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);
 }
        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, IsDefaultCollapsed=False}", outliningRegion.ToString());
        }
        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);
        }
        public void TestDisabledIf()
        {
            var tree = ParseLines("#if false",
                                        "Blah",
                                        "Blah",
                                        "Blah",
                                        "#endif");

            var trivia = (tree.GetRoot() as CompilationUnitSyntax).EndOfFileToken.LeadingTrivia;
            var disabledTextTrivia = trivia.ElementAt(1);
            Assert.Equal(SyntaxKind.DisabledTextTrivia, disabledTextTrivia.Kind());

            var actualRegion = GetRegion(tree, disabledTextTrivia);
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(11, 27),
                CSharpOutliningHelpers.Ellipsis,
                autoCollapse: true);

            AssertRegion(expectedRegion, actualRegion);
        }
Example #5
0
        public void TestSimpleComment1()
        {
            var tree = ParseLines("// Hello",
                                        "// C#!",
                                        "class C",
                                        "{",
                                        "}");

            var typeDecl = tree.DigToFirstTypeDeclaration();
            var trivia = typeDecl.GetLeadingTrivia();
            Assert.Equal(4, trivia.Count);

            var regions = CSharpOutliningHelpers.CreateCommentRegions(trivia).ToList();
            Assert.Equal(1, regions.Count);

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

            AssertRegion(expectedRegion, actualRegion);
        }
Example #6
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);
        }
Example #7
0
        public void TestIncompleteMultilineCommentSingleSpace()
        {
            var tree = ParseLines("/* ");

            var multiLineCommentTrivia = tree.GetRoot().FindToken(0).LeadingTrivia;
            var regions = CSharpOutliningHelpers.CreateCommentRegions(multiLineCommentTrivia).ToList();
            Assert.Equal(1, regions.Count);

            var actualRegion = regions[0];
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(0, 3),
                "/*  ...",
                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 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);
        }
        public void NestedDisabledCodePreProcessorDirectivesShouldCollapseEntireDisabledRegion2()
        {
            var tree = ParseCode(@"class P {
#if Foo
    void M()
    {
#if Bar
       M();
       M();
#endif
        }
#endif
    }
");
            var actualRegion = GetRegion(tree, tree.GetRoot().DescendantTrivia().Where(t => t.IsKind(SyntaxKind.DisabledTextTrivia)).Skip(1).First());
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(50, 74), CSharpOutliningHelpers.Ellipsis, autoCollapse: true);
            AssertRegion(expectedRegion, actualRegion);
        }
        public void DisabledCodeWithEmbeddedPreprocessorDirectivesShouldCollapseEntireDisabledRegion()
        {
            var tree = ParseCode(@"class P {
#if false
    void M()
    {
#region ""R""
       M();
#endregion
        }
#endif
    }
");
            var actualRegion = GetRegion(tree, tree.GetRoot().DescendantTrivia().First(t => t.IsKind(SyntaxKind.DisabledTextTrivia)));
            var expectedRegion = new OutliningSpan(
                TextSpan.FromBounds(22, 90), CSharpOutliningHelpers.Ellipsis, autoCollapse: true);
            AssertRegion(expectedRegion, actualRegion);
        }