Exemplo n.º 1
0
        public void TestMethodWithLeadingComments()
        {
            var tree = ParseLines("class C",
                                  "{",
                                  "  // Foo",
                                  "  // Bar",
                                  "  public string Foo()",
                                  "  {",
                                  "  }",
                                  "}");

            var typeDecl   = tree.DigToFirstTypeDeclaration();
            var methodDecl = typeDecl.DigToFirstNodeOfType <MethodDeclarationSyntax>();

            var actualRegions = GetRegions(methodDecl).ToList();

            Assert.Equal(2, actualRegions.Count);

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(14, 30),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(53, 63),
                TextSpan.FromBounds(34, 63),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 2
0
        public void TestDocumentationCommentWithoutSummaryTag2()
        {
            var tree = ParseLines("/** Block comment",
                                  "* some description",
                                  "* of",
                                  "* the comment",
                                  "*/",
                                  "class Class3",
                                  "{",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var trivia   = typeDecl.GetLeadingTrivia().ToList();

            Assert.Equal(2, trivia.Count);

            var documentationComment = trivia[0].GetStructure() as DocumentationCommentTriviaSyntax;

            Assert.NotNull(documentationComment);

            var actualRegion   = GetRegion(documentationComment);
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 62),
                "/** Block comment ...",
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Exemplo n.º 3
0
        public void TestOperatorWithLeadingComments()
        {
            var tree = ParseLines("class C",
                                  "{",
                                  "  // Foo",
                                  "  // Bar",
                                  "  public static explicit operator C (byte i)",
                                  "  {",
                                  "  }",
                                  "}");

            var typeDecl     = tree.DigToFirstTypeDeclaration();
            var operatorDecl = typeDecl.DigToFirstNodeOfType <ConversionOperatorDeclarationSyntax>();

            var actualRegions = GetRegions(operatorDecl).ToList();

            Assert.Equal(2, actualRegions.Count);

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(14, 30),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(76, 86),
                TextSpan.FromBounds(34, 86),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 4
0
        public void TestDocumentationCommentWithLongBannerText()
        {
            var tree = ParseLines("/// <summary>",
                                  "/// " + new string('x', 240),
                                  "/// </summary>",
                                  "class C",
                                  "{",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var trivia   = typeDecl.GetLeadingTrivia().ToList();

            Assert.Equal(1, trivia.Count);

            var documentationComment = trivia[0].GetStructure() as DocumentationCommentTriviaSyntax;

            Assert.NotNull(documentationComment);

            var actualRegion       = GetRegion(documentationComment);
            var expectedBannerText = "/// <summary> " + new string('x', 106) + " ...";
            var expectedRegion     = new OutliningSpan(
                TextSpan.FromBounds(0, 275),
                expectedBannerText,
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Exemplo n.º 5
0
        public void TestMultilineSummaryInDocumentationComment2()
        {
            var tree = ParseLines("/// <summary>",
                                  "/// Hello",
                                  "/// ",
                                  "/// C#!",
                                  "/// </summary>",
                                  "class C",
                                  "{",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var trivia   = typeDecl.GetLeadingTrivia().ToList();

            Assert.Equal(1, trivia.Count);

            var documentationComment = trivia[0].GetStructure() as DocumentationCommentTriviaSyntax;

            Assert.NotNull(documentationComment);

            var actualRegion   = GetRegion(documentationComment);
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 55),
                "/// <summary> Hello C#!",
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
        public void PreprocessorDirectivesInTrailingTrivia()
        {
            var tree = ParseCode(@"
class C
{
    void M()
    {
        extern mscorlib 
        {{
          a = x;
        }} 
    }

#if false
Disabled
Code
#endif
}");

            var actualRegion   = GetRegion(tree, tree.GetRoot().DescendantTrivia().First(t => t.IsKind(SyntaxKind.DisabledTextTrivia)));
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(124, 138), CSharpOutliningHelpers.Ellipsis, autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
        public void TestEnumWithNestedComments()
        {
            var tree = ParseLines("enum E",
                                  "{",
                                  "  // Foo",
                                  "  // Bar",
                                  "}");

            var enumDecl = tree.DigToFirstNodeOfType <EnumDeclarationSyntax>();

            var actualRegions = GetRegions(enumDecl).ToList();

            Assert.Equal(2, actualRegions.Count);

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(6, 32),
                TextSpan.FromBounds(0, 32),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: false);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(13, 29),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 8
0
        public void TestSingleLineCommentGroupFollowedByDocumentationComment()
        {
            var tree = ParseLines("// Hello",
                                  string.Empty,
                                  "// C#!",
                                  "/// <summary></summary>",
                                  "class C",
                                  "{",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var trivia   = typeDecl.GetLeadingTrivia();

            Assert.Equal(6, trivia.Count);

            var regions = CSharpOutliningHelpers.CreateCommentRegions(trivia).ToList();

            Assert.Equal(1, regions.Count);

            var actualRegion   = regions[0];
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 18),
                "// Hello ...",
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
        public void NestedDisabledCodePreProcessorDirectivesShouldCollapseEntireDisabledRegion4()
        {
            var tree           = ParseCode(@"class P {
#if Foo
    void M()
    {
#if Bar
       M();
#line 10
        //some more text...
        //text
#if Car
        //random text
        //text
#endif
        // more text
        // text
#endif
    }
#endif
    }
");
            var actualRegion   = GetRegion(tree, tree.GetRoot().DescendantTrivia().First(t => t.IsKind(SyntaxKind.DisabledTextTrivia)));
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(20, 226), CSharpOutliningHelpers.Ellipsis, autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Exemplo n.º 10
0
        public void TestSimpleComment2()
        {
            var tree = ParseLines("// Hello",
                                  "//",
                                  "// C#!",
                                  "class C",
                                  "{",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var trivia   = typeDecl.GetLeadingTrivia();

            Assert.Equal(6, trivia.Count);

            var regions = CSharpOutliningHelpers.CreateCommentRegions(trivia).ToList();

            Assert.Equal(1, regions.Count);

            var actualRegion   = regions[0];
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 20),
                "// Hello ...",
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
        public void TestClassWithNestedComments()
        {
            var tree = ParseLines("class C",
                                  "{",
                                  "  // Foo",
                                  "  // Bar",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();

            var actualRegions = GetRegions(typeDecl).ToList();

            Assert.Equal(2, actualRegions.Count);

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(7, 33),
                TextSpan.FromBounds(0, 33),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: false);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(14, 30),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 12
0
        protected void TestTrivia(string expectedRegionName, string code, SyntaxKind expectedKind, bool autoCollapse)
        {
            int caretPosition;
            IList <TextSpan> spans;

            MarkupTestFile.GetPositionAndSpans(code, out code, out caretPosition, out spans);

            var tree      = ParseCode(code);
            var trivia    = tree.GetRoot().FindTrivia(caretPosition);
            var directive = trivia.GetStructure() as TSyntaxNode;

            Assert.NotNull(directive);
            Assert.Equal(expectedKind, directive.Kind());

            var actualRegions = GetRegions(directive).ToArray();

            if (spans.Count == 0)
            {
                Assert.Equal(0, actualRegions.Length);
                return;
            }

            Assert.Equal(1, actualRegions.Length);
            var expectedRegion = new OutliningSpan(
                spans[0],
                expectedRegionName,
                autoCollapse);

            AssertRegion(expectedRegion, actualRegions[0]);
        }
Exemplo n.º 13
0
        public void TestIndexerWithComments()
        {
            var tree = ParseLines("class C",
                                  "{",
                                  "  // Foo",
                                  "  // Bar",
                                  "  public string this[int index]",
                                  "  {",
                                  "    get { }",
                                  "  }",
                                  "}");

            var typeDecl    = tree.DigToFirstTypeDeclaration();
            var indexerDecl = typeDecl.DigToFirstNodeOfType <IndexerDeclarationSyntax>();

            var actualRegions = GetRegions(indexerDecl).ToList();

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(14, 30),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(63, 86),
                TextSpan.FromBounds(34, 86),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 14
0
        public void TestExternAliasesWithComments()
        {
            var tree = ParseLines("// Foo",
                                  "// Bar",
                                  "extern alias Foo;",
                                  "extern alias Bar;");

            var compilationUnit = (CompilationUnitSyntax)tree.GetRoot();

            var actualRegions = GetRegions(compilationUnit).ToList();

            Assert.Equal(2, actualRegions.Count);

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(0, 14),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(23, 52),
                hintSpan: TextSpan.FromBounds(16, 52),
                bannerText: CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
        public void TestPropertySetter2()
        {
            var tree = ParseLines("class C",
                                  "{",
                                  "  public string Text",
                                  "  {",
                                  "    get",
                                  "    {",
                                  "    }",
                                  "    set",
                                  "    {",
                                  "    }",
                                  "  }",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var propDecl = typeDecl.DigToFirstNodeOfType <PropertyDeclarationSyntax>();
            var accessor = propDecl.AccessorList.Accessors[1];

            var actualRegion   = GetRegion(accessor);
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(69, 83),
                TextSpan.FromBounds(66, 83),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
        public void TestNamespaceWithNestedUsings()
        {
            var tree = ParseLines("namespace C",
                                  "{",
                                  "  using System;",
                                  "  using System.Linq;",
                                  "}");

            var namespaceDecl = tree.DigToFirstNodeOfType <NamespaceDeclarationSyntax>();

            var actualRegions = GetRegions(namespaceDecl).ToList();

            Assert.Equal(2, actualRegions.Count);

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(11, 56),
                TextSpan.FromBounds(0, 56),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: false);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(24, 53),
                hintSpan: TextSpan.FromBounds(18, 53),
                bannerText: CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
        public void TestEventWithComments()
        {
            var tree = ParseLines("class C",
                                  "{",
                                  "  // Foo",
                                  "  // Bar",
                                  "  event EventHandler E",
                                  "  {",
                                  "    add { }",
                                  "    remove { }",
                                  "  }",
                                  "}");

            var typeDecl  = tree.DigToFirstTypeDeclaration();
            var eventDecl = typeDecl.DigToFirstNodeOfType <EventDeclarationSyntax>();

            var actualRegions = GetRegions(eventDecl).ToList();

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(14, 30),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(54, 93),
                TextSpan.FromBounds(34, 93),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 18
0
        public void TestConstructorMissingCloseParenAndBody()
        {
            // Expected behavior is that the class should be outlined, but the constructor should not.

            var tree = ParseLines("class C",
                                  "{",
                                  "  C(",
                                  "}");

            var typeDecl         = tree.DigToFirstTypeDeclaration();
            var typeDeclOutliner = new TypeDeclarationOutliner();

            var typeDeclRegions = typeDeclOutliner.GetOutliningSpans(typeDecl, CancellationToken.None).ToList();

            Assert.Equal(1, typeDeclRegions.Count);

            var expectedTypeDeclRegion =
                new OutliningSpan(
                    TextSpan.FromBounds(7, 19),
                    TextSpan.FromBounds(0, 19),
                    CSharpOutliningHelpers.Ellipsis,
                    autoCollapse: false);

            AssertRegion(expectedTypeDeclRegion, typeDeclRegions[0]);

            var consDecl        = typeDecl.DigToFirstNodeOfType <ConstructorDeclarationSyntax>();
            var consDeclRegions = GetRegions(consDecl).ToList();

            Assert.Equal(0, consDeclRegions.Count);
        }
        public void TestNamespaceWithLeadingComments()
        {
            var tree = ParseLines("// Foo",
                                  "// Bar",
                                  "namespace C",
                                  "{",
                                  "}");

            var namespaceDecl = tree.DigToFirstNodeOfType <NamespaceDeclarationSyntax>();

            var actualRegions = GetRegions(namespaceDecl).ToList();

            Assert.Equal(2, actualRegions.Count);

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(0, 14),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(27, 33),
                TextSpan.FromBounds(16, 33),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: false);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 20
0
        public void TestWithCommentsAtEnd()
        {
            var tree = ParseLines("using System;",
                                  "// Foo",
                                  "// Bar");

            var compilationUnit = (CompilationUnitSyntax)tree.GetRoot();

            var actualRegions = GetRegions(compilationUnit).ToList();

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(6, 13),
                hintSpan: TextSpan.FromBounds(0, 13),
                bannerText: CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(15, 29),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 21
0
        public void TestConstructorWithComments()
        {
            var tree = ParseLines("class C",
                                  "{",
                                  "  // Foo",
                                  "  // Bar",
                                  "  public C()",
                                  "  {",
                                  "  }",
                                  "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var consDecl = typeDecl.DigToFirstNodeOfType <ConstructorDeclarationSyntax>();

            var actualRegions = GetRegions(consDecl).ToList();

            var expectedRegion1 = new OutliningSpan(
                TextSpan.FromBounds(14, 30),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion1, actualRegions[0]);

            var expectedRegion2 = new OutliningSpan(
                TextSpan.FromBounds(44, 54),
                TextSpan.FromBounds(34, 54),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion2, actualRegions[1]);
        }
Exemplo n.º 22
0
 internal void AssertRegion(OutliningSpan expected, OutliningSpan actual)
 {
     Assert.Equal(expected.TextSpan.Start, actual.TextSpan.Start);
     Assert.Equal(expected.TextSpan.End, actual.TextSpan.End);
     Assert.Equal(expected.HintSpan.Start, actual.HintSpan.Start);
     Assert.Equal(expected.HintSpan.End, actual.HintSpan.End);
     Assert.Equal(expected.BannerText, actual.BannerText);
     Assert.Equal(expected.AutoCollapse, actual.AutoCollapse);
 }
Exemplo n.º 23
0
        public void TestToStringWithoutHintSpan()
        {
            var span         = TextSpan.FromBounds(0, 1);
            var bannerText   = "Foo";
            var autoCollapse = true;

            var outliningRegion = new OutliningSpan(span, bannerText, autoCollapse);

            Assert.Equal("{Span=[0..1), BannerText=\"Foo\", AutoCollapse=True}", outliningRegion.ToString());
        }
Exemplo n.º 24
0
        public void TestProperties()
        {
            var span         = TextSpan.FromBounds(0, 1);
            var hintSpan     = TextSpan.FromBounds(2, 3);
            var bannerText   = "Foo";
            var autoCollapse = true;

            var outliningRegion = new OutliningSpan(span, hintSpan, bannerText, autoCollapse);

            Assert.Equal(span, outliningRegion.TextSpan);
            Assert.Equal(hintSpan, outliningRegion.HintSpan);
            Assert.Equal(bannerText, outliningRegion.BannerText);
            Assert.Equal(autoCollapse, outliningRegion.AutoCollapse);
        }
Exemplo n.º 25
0
        public void TestUsingKeywordWithSpace()
        {
            var tree            = ParseLines("using ");
            var compilationUnit = (CompilationUnitSyntax)tree.GetRoot();
            var actualRegions   = GetRegions(compilationUnit).ToList();

            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(6, 6),
                TextSpan.FromBounds(0, 5),
                bannerText: CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegions[0]);
        }
Exemplo n.º 26
0
        public void WithAttributes()
        {
            var tree = ParseCode(
                @"[Foo]
public delegate TResult Blah<in T, out TResult>(T arg);");
            var delegateDecl = tree.DigToFirstNodeOfType <DelegateDeclarationSyntax>();

            var actualRegion   = GetRegion(delegateDecl);
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 7),
                TextSpan.FromBounds(0, 62),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Exemplo n.º 27
0
        public void TestExternAliases()
        {
            var tree = ParseLines("extern alias Foo;",
                                  "extern alias Bar;");

            var compilationUnit = (CompilationUnitSyntax)tree.GetRoot();

            var actualRegion   = GetRegion(compilationUnit);
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(7, 36),
                hintSpan: TextSpan.FromBounds(0, 36),
                bannerText: CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Exemplo n.º 28
0
        public void TestUsings()
        {
            var tree = ParseLines("using System;",
                                  "using System.Core;");

            var compilationUnit = tree.GetRoot() as CompilationUnitSyntax;

            var actualRegion   = GetRegion(compilationUnit);
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(6, 33),
                hintSpan: TextSpan.FromBounds(0, 33),
                bannerText: CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Exemplo n.º 29
0
        public void TestWithComments()
        {
            var tree = ParseLines("// Foo",
                                  "// Bar");

            var compilationUnit = (CompilationUnitSyntax)tree.GetRoot();

            var actualRegion = GetRegion(compilationUnit);

            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 14),
                "// Foo ...",
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
        public void TestNamespace()
        {
            var tree = ParseLines("namespace N",
                                  "{",
                                  "}");

            var namespaceDecl = tree.DigToFirstNodeOfType <NamespaceDeclarationSyntax>();

            var actualRegion   = GetRegion(namespaceDecl);
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(11, 17),
                TextSpan.FromBounds(0, 17),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: false);

            AssertRegion(expectedRegion, actualRegion);
        }