示例#1
0
        private static async Task TestSymbolFoundAsync(string inputLine, string code)
        {
            using var workspace = TestWorkspace.CreateCSharp(code);
            var result = await StackTraceAnalyzer.AnalyzeAsync(inputLine, CancellationToken.None);

            Assert.Single(result.ParsedFrames);

            var stackFrame = result.ParsedFrames[0] as ParsedStackFrame;

            AssertEx.NotNull(stackFrame);

            // Test that ToString() and reparsing keeps the same outcome
            var reparsedResult = await StackTraceAnalyzer.AnalyzeAsync(stackFrame.ToString(), CancellationToken.None);

            Assert.Single(reparsedResult.ParsedFrames);

            var reparsedFrame = reparsedResult.ParsedFrames[0] as ParsedStackFrame;

            AssertEx.NotNull(reparsedFrame);
            StackFrameUtils.AssertEqual(stackFrame.Root, reparsedFrame.Root);

            // Get the definition for the parsed frame
            var service    = workspace.Services.GetRequiredService <IStackTraceExplorerService>();
            var definition = await service.TryFindDefinitionAsync(workspace.CurrentSolution, stackFrame, StackFrameSymbolPart.Method, CancellationToken.None);

            AssertEx.NotNull(definition);

            // Get the symbol that was indicated in the source code by cursor position
            var cursorDoc    = workspace.Documents.Single();
            var selectedSpan = cursorDoc.SelectedSpans.Single();
            var doc          = workspace.CurrentSolution.GetRequiredDocument(cursorDoc.Id);
            var root         = await doc.GetRequiredSyntaxRootAsync(CancellationToken.None);

            var node          = root.FindNode(selectedSpan);
            var semanticModel = await doc.GetRequiredSemanticModelAsync(CancellationToken.None);

            var expectedSymbol = semanticModel.GetDeclaredSymbol(node);

            AssertEx.NotNull(expectedSymbol);

            // Compare the definition found to the definition for the test symbol
            var expectedDefinition = expectedSymbol.ToNonClassifiedDefinitionItem(workspace.CurrentSolution, includeHiddenLocations: true);

            Assert.Equal(expectedDefinition.IsExternal, definition.IsExternal);
            AssertEx.SetEqual(expectedDefinition.NameDisplayParts, definition.NameDisplayParts);
            AssertEx.SetEqual(expectedDefinition.OriginationParts, definition.OriginationParts);
            AssertEx.SetEqual(expectedDefinition.Properties, definition.Properties);
            AssertEx.SetEqual(expectedDefinition.SourceSpans, definition.SourceSpans);
            AssertEx.SetEqual(expectedDefinition.Tags, definition.Tags);
        }
示例#2
0
        private static void Verify(
            string input,
            StackFrameMethodDeclarationNode?methodDeclaration = null,
            bool expectFailure = false,
            StackFrameFileInformationNode?fileInformation = null,
            StackFrameToken?eolTokenOpt = null)
        {
            FuzzyTest(input);

            var tree = StackFrameParser.TryParse(input);

            if (expectFailure)
            {
                Assert.Null(tree);
                return;
            }

            AssertEx.NotNull(tree);
            VerifyCharacterSpans(input, tree);

            if (methodDeclaration is null)
            {
                Assert.Null(tree.Root.MethodDeclaration);
            }
            else
            {
                StackFrameUtils.AssertEqual(methodDeclaration, tree.Root.MethodDeclaration);
            }

            if (fileInformation is null)
            {
                Assert.Null(tree.Root.FileInformationExpression);
            }
            else
            {
                StackFrameUtils.AssertEqual(fileInformation, tree.Root.FileInformationExpression);
            }

            var eolToken = eolTokenOpt.HasValue
                ? eolTokenOpt.Value
                : CreateToken(StackFrameKind.EndOfFrame, "");

            StackFrameUtils.AssertEqual(eolToken, tree.Root.EndOfLineToken);
        }