Exemplo n.º 1
0
        public async void ExecuteAsync_UpdatesSessionCursorPosition(string dataString, int expectedPosition)
        {
            var driver = MirrorSharpTestDriver.New();
            await driver.SendAsync(MoveCursor, dataString);

            Assert.Equal(expectedPosition, driver.Session.CursorPosition);
        }
Exemplo n.º 2
0
        private static async Task <MirrorSharpTestDriver> NewTestDriverAsync()
        {
            var driver = MirrorSharpTestDriver.New(TestEnvironment.MirrorSharpOptions);
            await driver.SendSetOptionsAsync(LanguageNames.CSharp, TargetNames.Explain);

            return(driver);
        }
Exemplo n.º 3
0
        public async void ExecuteAsync_UpdatesSessionLanguage(string languageName)
        {
            var driver = MirrorSharpTestDriver.New(new MirrorSharpOptions().EnableVisualBasic());
            await driver.SendAsync(SetOptions, "language=" + languageName);

            Assert.Equal(languageName, driver.Session.Language.Name);
        }
Exemplo n.º 4
0
        public async Task ExecuteAsync_InsertsSingleChar()
        {
            var driver = MirrorSharpTestDriver.New().SetTextWithCursor("class A| {}");
            await driver.SendAsync(TypeChar, '1');

            Assert.Equal("class A1 {}", driver.Session.GetText());
        }
Exemplo n.º 5
0
        public async Task ExecuteAsync_ProducesExpectedCompletionWithSuggestionItem_InLambdaContext()
        {
            var driver = MirrorSharpTestDriver.New().SetTextWithCursor(@"class C { void M() { System.Action a = | } }");
            var result = await driver.SendWithRequiredResultAsync <CompletionsResult>(TypeChar, 's');

            Assert.Equal("<lambda expression>", result.Suggestion?.DisplayText);
        }
Exemplo n.º 6
0
        public async void TypeChar_ProducesExpectedCompletion()
        {
            var driver = MirrorSharpTestDriver.New(Options, FSharpLanguage.Name);

            driver.SetTextWithCursor(@"
                type Test() =
                    member this.Method() = ()

                let test = 
                    let t = new Test()
                    t|
            ".Trim().Replace("                ", ""));

            var result = await driver.SendTypeCharAsync('.');

            Assert.NotNull(result);
            Assert.Equal(
                new[] {
                new { DisplayText = "Equals", Tag = "method" },
                new { DisplayText = "GetHashCode", Tag = "method" },
                new { DisplayText = "GetType", Tag = "method" },
                new { DisplayText = "Method", Tag = "method" },
                new { DisplayText = "ToString", Tag = "method" },
            },
                result.Completions.Select(c => new { c.DisplayText, Tag = c.Tags.SingleOrDefault() })
                );
        }
Exemplo n.º 7
0
        public async Task ExecuteAsync_HandlesUnicodeChar(char @char)
        {
            var driver = MirrorSharpTestDriver.New();
            await driver.SendAsync(TypeChar, @char);

            Assert.Equal(@char.ToString(), driver.Session.GetText());
        }
Exemplo n.º 8
0
        public async Task SlowUpdate_ReturnsNotSupportedError_ForJitAsmWithStaticConstructors(string code)
        {
            var driver = MirrorSharpTestDriver.New(MirrorSharpOptions).SetText(code);
            await driver.SendSetOptionsAsync(LanguageNames.CSharp, TargetNames.JitAsm);

            await Assert.ThrowsAsync <NotSupportedException>(() => driver.SendSlowUpdateAsync <string>());
        }
        public async void ExecuteAsync_AddsCompleteText_IfTextIsSplitIntoSeveralBuffers()
        {
            var driver = MirrorSharpTestDriver.New();
            await driver.SendAsync(ReplaceText, new[] { "0:0:0::x", "123456789", "123456789" });

            Assert.Equal("x123456789123456789", driver.Session.GetText());
        }
Exemplo n.º 10
0
        private static async Task <MirrorSharpTestDriver> NewTestDriverAsync(TestData data, string optimize = Optimize.Release)
        {
            var driver = MirrorSharpTestDriver.New(MirrorSharpOptions);
            await driver.SendSetOptionsAsync(data.SourceLanguageName, data.TargetLanguageName, optimize);

            driver.SetText(data.Original);
            return(driver);
        }
Exemplo n.º 11
0
        private static async Task <MirrorSharpTestDriver> NewTestDriverAsync(TestCode code, string optimize = Optimize.Release)
        {
            var driver = MirrorSharpTestDriver.New(TestEnvironment.MirrorSharpOptions);
            await driver.SendSetOptionsAsync(code.SourceLanguageName, code.TargetName, optimize);

            driver.SetText(code.Original);
            return(driver);
        }
 public static Task SendSetOptionsAsync(this MirrorSharpTestDriver driver, string sourceLanguageName, string targetName, string optimize = Optimize.Release)
 {
     return(driver.SendSetOptionsAsync(new Dictionary <string, string> {
         { "language", sourceLanguageName },
         { "x-optimize", optimize },
         { "x-target", targetName }
     }));
 }
Exemplo n.º 13
0
        public async Task ExecuteAsync_MovesCursorBySingleChar()
        {
            var driver         = MirrorSharpTestDriver.New().SetTextWithCursor("class A| {}");
            var cursorPosition = driver.Session.CursorPosition;
            await driver.SendAsync(TypeChar, '1');

            Assert.Equal(cursorPosition + 1, driver.Session.CursorPosition);
        }
Exemplo n.º 14
0
        public async void ExecuteAsync_AddsSpecifiedCharacter(string initialText, string dataString, string expectedText, int expectedCursorPosition)
        {
            var driver = MirrorSharpTestDriver.New().SetText(initialText);
            await driver.SendAsync(ReplaceText, dataString);

            Assert.Equal(expectedText, driver.Session.GetText());
            Assert.Equal(expectedCursorPosition, driver.Session.CursorPosition);
        }
        public async Task ExecuteAsync_DoesNotSendMessage_WhenNoQuickInfo()
        {
            var driver = MirrorSharpTestDriver.New().SetText("class C {}");

            var result = await driver.SendRequestInfoTipAsync(10);

            Assert.Null(result);
        }
Exemplo n.º 16
0
        public async Task SlowUpdate_DoesNotReturnWarnings_ForCodeWithoutXmlDocumentation(string sourceLanguageName, string code)
        {
            var driver = MirrorSharpTestDriver.New(TestEnvironment.MirrorSharpOptions).SetText(code);
            await driver.SendSetOptionsAsync(sourceLanguageName, TargetNames.IL);

            var result = await driver.SendSlowUpdateAsync <string>();

            Assert.Empty(result.Diagnostics);
        }
        public async Task ExecuteAsync_ProducesExpectedInfoTip(string textWithCursor, string expectedResultText, string[] expectedKinds)
        {
            var text   = TextWithCursor.Parse(textWithCursor, '➭');
            var driver = MirrorSharpTestDriver.New().SetText(text.Text);

            var result = await driver.SendRequestInfoTipAsync(text.CursorPosition);

            Assert.Equal(expectedKinds, result.Kinds);
            Assert.Equal(expectedResultText, result?.ToString());
        }
Exemplo n.º 18
0
        private static async Task <SlowUpdateDiagnosticAction> ExecuteSlowUpdateAndGetDiagnosticActionAsync(
            MirrorSharpTestDriver driver, string diagnosticMessageFilter, string actionTitleFilter
            )
        {
            var result = await driver.SendSlowUpdateAsync();

            var diagnostic = result.Diagnostics.Single(d => d.Message?.Contains(diagnosticMessageFilter) ?? false);

            return(diagnostic.Actions.Single(a => a.Title?.Contains(actionTitleFilter) ?? false));
        }
        public async Task Script_ProducesNoErrors_WhenSetInInitialOptions()
        {
            var options = new MirrorSharpOptions()
                          .SetupCSharp(o => o.SetScriptMode(hostObjectType: TestHostType));
            var driver = MirrorSharpTestDriver.New(options)
                         .SetText($"var x = {TestHostMethodName}();");

            var result = await driver.SendSlowUpdateAsync();

            Assert.Equal("", result.JoinErrors());
        }
Exemplo n.º 20
0
        private static async Task <MirrorSharpTestDriver> NewTestDriverAsync(
            string code,
            string languageName = LanguageNames.CSharp,
            string optimize     = Optimize.Debug
            )
        {
            var driver = MirrorSharpTestDriver.New(TestEnvironment.MirrorSharpOptions).SetText(code);
            await driver.SendSetOptionsAsync(languageName, TargetNames.Run, optimize);

            return(driver);
        }
Exemplo n.º 21
0
        public async Task ExecuteAsync_CancelsCompletion_WhenXIsProvidedInsteadOfIndex()
        {
            var driver = MirrorSharpTestDriver.New().SetTextWithCursor("class C { void M(object o) { o| } }");

            await TypeAndGetCompletionsAsync('.', driver);

            var result = await driver.SendAsync <ChangesResult?>(CompletionState, 'X');

            Assert.Null(result);
            Assert.Null(driver.Session.CurrentCompletion.List);
        }
Exemplo n.º 22
0
        public async void ExecuteAsync_AddsCompleteText_IfTextIsSplitInTwoBuffersInTheMiddleOfUtf8Char()
        {
            var driver = MirrorSharpTestDriver.New();
            var bytes  = Encoding.UTF8.GetBytes("0:0:0::☀");
            await driver.SendAsync(ReplaceText, new[] {
                bytes.Take(bytes.Length - 2).ToArray(),
                new[] { bytes[bytes.Length - 2], bytes[bytes.Length - 1] }
            });

            Assert.Equal("☀", driver.Session.GetText());
        }
Exemplo n.º 23
0
        public async Task ExecuteAsync_ProducesExpectedSignatureHelp(string methods, string[] expected)
        {
            var driver = MirrorSharpTestDriver.New().SetTextWithCursor(@"
                class C {
                    " + methods + @"
                    void T() { M| }
                }
            ");
            var result = await driver.SendAsync <SignaturesResult>(TypeChar, '(');

            Assert.Equal(expected, result.Signatures.Select(s => s.ToString(markSelected: false)));
        }
Exemplo n.º 24
0
        public async Task SlowUpdate_ReturnsExpectedWarnings_ForXmlDocumentation(string sourceLanguageName, string code, string expectedWarningId)
        {
            var driver = MirrorSharpTestDriver.New(TestEnvironment.MirrorSharpOptions).SetText(code);
            await driver.SendSetOptionsAsync(sourceLanguageName, TargetNames.IL);

            var result = await driver.SendSlowUpdateAsync <string>();

            Assert.Equal(
                new[] { new { Severity = "warning", Id = expectedWarningId } },
                result.Diagnostics.Select(d => new { d.Severity, d.Id }).ToArray()
                );
        }
Exemplo n.º 25
0
        public async Task SlowUpdate_ProducesDiagnosticWithCustomTagUnnecessary_ForUnusedNamespace()
        {
            var driver = MirrorSharpTestDriver.New().SetTextWithCursor(@"using System;|");
            var result = await driver.SendAsync <SlowUpdateResult <object> >(SlowUpdate);

            Assert.Contains(
                new { severity = DiagnosticSeverity.Hidden.ToString("G").ToLowerInvariant(), isUnnecessary = true },
                result.Diagnostics.Select(
                    d => new { severity = d.Severity, isUnnecessary = d.Tags.Contains(WellKnownDiagnosticTags.Unnecessary, StringComparer.OrdinalIgnoreCase) }
                    ).ToArray()
                );
        }
Exemplo n.º 26
0
        public async Task SlowUpdate_DisposesExtensionResult_IfDisposable()
        {
            var disposable = Mock.Of <IDisposable>();
            var driver     = MirrorSharpTestDriver.New(new MirrorSharpOptions {
                SlowUpdate = Mock.Of <ISlowUpdateExtension>(
                    x => x.ProcessAsync(It.IsAny <IWorkSession>(), It.IsAny <IList <Diagnostic> >(), It.IsAny <CancellationToken>()) == Task.FromResult <object>(disposable)
                    )
            });
            await driver.SendAsync(SlowUpdate);

            Mock.Get(disposable).Verify(x => x.Dispose());
        }
        public async Task ExecuteAsync_ProducesExpectedInfoTip(string textWithCursor, string expectedResultText, string[] expectedKinds)
        {
            var text   = TextWithCursor.Parse(textWithCursor, '➭');
            var driver = MirrorSharpTestDriver.New().SetText(text.Text);

            var result = await driver.SendRequestInfoTipAsync(text.CursorPosition);

            Assert.NotNull(result);
            // https://github.com/xunit/assert.xunit/pull/36#issuecomment-578990557
            Assert.Equal(expectedKinds, result !.Kinds);
            Assert.Equal(expectedResultText, result?.ToString());
        }
Exemplo n.º 28
0
        public async Task ExecuteAsync_DoesNotModifyCurrentSession()
        {
            var driver = MirrorSharpTestDriver.New().SetText(@"class C { Action a; }");
            var action = await ExecuteSlowUpdateAndGetDiagnosticActionAsync(driver, "Action", "using");

            var textBefore = driver.Session.Roslyn.SourceText;
            await driver.SendAsync(ApplyDiagnosticAction, action.Id);

            Assert.Same(textBefore, driver.Session.Roslyn.SourceText);
            Assert.Equal(textBefore.ToString(), (await driver.Session.Roslyn.Document.GetTextAsync()).ToString());
            Assert.Same(driver.Session.Roslyn.Workspace.CurrentSolution, driver.Session.Roslyn.Project.Solution);
        }
Exemplo n.º 29
0
        public async Task ExecuteAsync_ProducesExpectedChanges_ForMissingNamespace()
        {
            var driver = MirrorSharpTestDriver.New().SetText(@"class C { Action a; }");
            var action = await ExecuteSlowUpdateAndGetDiagnosticActionAsync(driver, "Action", "using");

            var changes = await driver.SendWithRequiredResultAsync <ChangesResult>(ApplyDiagnosticAction, action.Id);

            Assert.Equal(
                new[] { new { Start = 0, Length = 0, Text = "using System;\r\n\r\n" } },
                changes.Changes.Select(c => new { c.Start, c.Length, c.Text })
                );
        }
Exemplo n.º 30
0
        public async Task ExecuteAsync_ForcesCompletion_WhenFIsProvidedInsteadOfIndex()
        {
            var driver = MirrorSharpTestDriver.New().SetTextWithCursor("class C { void M(object o) { o.| } }");

            var result = await driver.SendAsync <CompletionsResult>(CompletionState, 'F');

            Assert.NotNull(result);
            Assert.Equal(
                ObjectMembers.AllNames.OrderBy(n => n),
                result.Completions.Select(i => i.DisplayText).OrderBy(n => n)
                );
        }