Repository: dotnet/roslyn
File: src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNodeTests.cs (C#)

Code before:
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[3].Kind());
            Assert.Equal(SyntaxKind.SubtractExpression, nodes[4].Kind());
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[5].Kind());
            Assert.Equal(SyntaxKind.AddExpression, nodes[6].Kind());
        }

        [Fact]
        public void TestAncestorsAndSelf()
        {
            var text = "a + (b - (c * (d / e)))";
            var expression = SyntaxFactory.ParseExpression(text);
            var e = expression.DescendantNodes().OfType<IdentifierNameSyntax>().First(n => n.Identifier.Text == "e");

            var nodes = e.AncestorsAndSelf().ToList();
            Assert.Equal(8, nodes.Count);
            Assert.Equal(SyntaxKind.IdentifierName, nodes[0].Kind());
            Assert.Equal(SyntaxKind.DivideExpression, nodes[1].Kind());
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[2].Kind());
            Assert.Equal(SyntaxKind.MultiplyExpression, nodes[3].Kind());
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[4].Kind());
            Assert.Equal(SyntaxKind.SubtractExpression, nodes[5].Kind());
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[6].Kind());
            Assert.Equal(SyntaxKind.AddExpression, nodes[7].Kind());
        }

        [Fact]
        public void TestAncestorsOfDocumentationCommentTrivia()
        {
            var text = @"
public class TestMe
{
    /// <summary>
    /// Test comment
    /// </summary>
    private int i;
}";
            var tree = SyntaxFactory.ParseSyntaxTree(text);
            var root = tree.GetCompilationUnitRoot();

            var docComment = root.DescendantNodes(descendIntoTrivia: true)
                .OfType<DocumentationCommentTriviaSyntax>()
                .First();

            // Verify that Ancestors() now returns all ancestors when ascendOutOfTrivia is true
            var ancestors = docComment.Ancestors(ascendOutOfTrivia: true).ToList();
            Assert.Equal(3, ancestors.Count);
            Assert.Equal(SyntaxKind.FieldDeclaration, ancestors[0].Kind());
            Assert.Equal(SyntaxKind.ClassDeclaration, ancestors[1].Kind());
            Assert.Equal(SyntaxKind.CompilationUnit, ancestors[2].Kind());

            // Verify that AncestorsAndSelf() still works correctly

Review comment (suggestion):
@copilot add a WorkItem attribute.  And use a raw string literal for the test.  This applies to all tests you added.

Code after:
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[3].Kind());
            Assert.Equal(SyntaxKind.SubtractExpression, nodes[4].Kind());
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[5].Kind());
            Assert.Equal(SyntaxKind.AddExpression, nodes[6].Kind());
        }

        [Fact]
        public void TestAncestorsAndSelf()
        {
            var text = "a + (b - (c * (d / e)))";
            var expression = SyntaxFactory.ParseExpression(text);
            var e = expression.DescendantNodes().OfType<IdentifierNameSyntax>().First(n => n.Identifier.Text == "e");

            var nodes = e.AncestorsAndSelf().ToList();
            Assert.Equal(8, nodes.Count);
            Assert.Equal(SyntaxKind.IdentifierName, nodes[0].Kind());
            Assert.Equal(SyntaxKind.DivideExpression, nodes[1].Kind());
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[2].Kind());
            Assert.Equal(SyntaxKind.MultiplyExpression, nodes[3].Kind());
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[4].Kind());
            Assert.Equal(SyntaxKind.SubtractExpression, nodes[5].Kind());
            Assert.Equal(SyntaxKind.ParenthesizedExpression, nodes[6].Kind());
            Assert.Equal(SyntaxKind.AddExpression, nodes[7].Kind());
        }

        [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/46964")]
        public void TestAncestorsOfDocumentationCommentTrivia()
        {
            var text = """
                public class TestMe
                {
                    /// <summary>
                    /// Test comment
                    /// </summary>
                    private int i;
                }
                """;
            var tree = SyntaxFactory.ParseSyntaxTree(text);
            var root = tree.GetCompilationUnitRoot();

            var docComment = root.DescendantNodes(descendIntoTrivia: true)
                .OfType<DocumentationCommentTriviaSyntax>()
                .First();

            // Verify that Ancestors() now returns all ancestors when ascendOutOfTrivia is true
            var ancestors = docComment.Ancestors(ascendOutOfTrivia: true).ToList();
            Assert.Equal(3, ancestors.Count);
            Assert.Equal(SyntaxKind.FieldDeclaration, ancestors[0].Kind());
            Assert.Equal(SyntaxKind.ClassDeclaration, ancestors[1].Kind());
            Assert.Equal(SyntaxKind.CompilationUnit, ancestors[2].Kind());