From 66944d3e168091fec17ed064e90a92acc35916b3 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Thu, 19 Nov 2015 18:01:34 -0800 Subject: [PATCH] Convert C# outlining tests to 'FIT' style tests --- .../OperatorDeclarationOutliner.cs | 3 +- .../CSharpEditorServicesTest.csproj | 2 +- .../Outlining/AbstractOutlinerTests`1.cs | 94 ++- .../Outlining/AccessorDeclarationTests.cs | 567 ++++++------------ .../AnonymousMethodExpressionTests.cs | 126 ++-- .../CSharpTest/Outlining/CommentTests.cs | 2 + .../Outlining/CompilationUnitOutlinerTests.cs | 271 +++------ .../ConstructorDeclarationOutlinerTests.cs | 293 +++------ ...versionOperatorDeclarationOutlinerTests.cs | 79 +-- .../DelegateDeclarationOutlinerTests.cs | 30 +- .../DestructorDeclarationOutlinerTests.cs | 107 +--- .../Outlining/DisabledTextOutlinerTests.cs | 2 + .../DocumentationCommentOutlinerTests.cs | 462 +++++--------- .../Outlining/EnumDeclarationOutlinerTests.cs | 94 +-- .../EventDeclarationOutlinerTests.cs | 88 +-- .../EventFieldDeclarationOutlinerTests.cs | 37 +- .../FieldDeclarationOutlinerTests.cs | 37 +- .../IndexerDeclarationOutlinerTests.cs | 107 ++-- .../ConstructorDeclarationOutlinerTests.cs | 92 +-- ...versionOperatorDeclarationOutlinerTests.cs | 68 +-- .../DelegateDeclarationOutlinerTests.cs | 69 +-- .../DestructorDeclarationOutlinerTests.cs | 68 +-- .../EnumDeclarationOutlinerTests.cs | 78 +-- .../EnumMemberDeclarationOutlinerTests.cs | 68 +-- .../EventDeclarationOutlinerTests.cs | 90 +-- .../EventFieldDeclarationOutlinerTests.cs | 90 +-- .../FieldDeclarationOutlinerTests.cs | 87 +-- .../IndexerDeclarationOutlinerTests.cs | 90 +-- .../InvalidIdentifierTests.cs | 1 + .../MethodDeclarationOutlinerTests.cs | 90 +-- .../OperatorDeclarationOutlinerTests.cs | 90 +-- .../PropertyDeclarationOutlinerTests.cs | 90 +-- .../RegionDirectiveOutlinerTests.cs | 52 +- .../TypeDeclarationOutlinerTests.cs | 59 +- .../MethodDeclarationOutlinerTests.cs | 131 ++-- .../NamespaceDeclarationOutlinerTests.cs | 199 ++---- .../OperatorDeclarationOutlinerTests.cs | 82 +-- .../ParenthesizedLambdaOutlinerTests.cs | 126 ++-- .../PropertyDeclarationOutlinerTests.cs | 145 ++--- .../Outlining/RegionDirectiveOutlinerTests.cs | 83 +-- .../SimpleLambdaExpressionOutlinerTests.cs | 126 ++-- .../Outlining/TypeDeclarationOutlinerTests.cs | 268 +++------ .../CSharpTest/Outlining/Utils.cs | 24 + .../Test/EditorServicesTest.csproj | 1 + .../Outlining/AbstractOutlinerTests.cs | 23 +- .../BasicEditorServicesTest.vbproj | 1 - .../Outlining/AbstractOutlinerTests.vb | 17 - .../Outlining/AbstractOutlinerTests`1.vb | 1 + .../VisualBasicTest/Outlining/CommentTests.vb | 4 +- .../Outlining/DisabledCodeOutlinerTests.vb | 6 +- .../InvalidIdentifierTests.vb | 1 + .../Outlining/OverallOutliningTests.vb | 2 +- 52 files changed, 1619 insertions(+), 3204 deletions(-) create mode 100644 src/EditorFeatures/CSharpTest/Outlining/Utils.cs rename src/EditorFeatures/{CSharpTest => Test}/Outlining/AbstractOutlinerTests.cs (53%) delete mode 100644 src/EditorFeatures/VisualBasicTest/Outlining/AbstractOutlinerTests.vb diff --git a/src/EditorFeatures/CSharp/Outlining/Outliners/MetadataAsSource/OperatorDeclarationOutliner.cs b/src/EditorFeatures/CSharp/Outlining/Outliners/MetadataAsSource/OperatorDeclarationOutliner.cs index 3607ca1f3d2..7b425848216 100644 --- a/src/EditorFeatures/CSharp/Outlining/Outliners/MetadataAsSource/OperatorDeclarationOutliner.cs +++ b/src/EditorFeatures/CSharp/Outlining/Outliners/MetadataAsSource/OperatorDeclarationOutliner.cs @@ -1,6 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource @@ -11,7 +10,7 @@ protected override SyntaxToken GetEndToken(OperatorDeclarationSyntax node) { return node.Modifiers.Count > 0 ? node.Modifiers.First() - : node.OperatorKeyword; + : node.ReturnType.GetFirstToken(); } } } diff --git a/src/EditorFeatures/CSharpTest/CSharpEditorServicesTest.csproj b/src/EditorFeatures/CSharpTest/CSharpEditorServicesTest.csproj index b9d267a9d90..af42abe71f0 100644 --- a/src/EditorFeatures/CSharpTest/CSharpEditorServicesTest.csproj +++ b/src/EditorFeatures/CSharpTest/CSharpEditorServicesTest.csproj @@ -310,7 +310,6 @@ - @@ -351,6 +350,7 @@ + diff --git a/src/EditorFeatures/CSharpTest/Outlining/AbstractOutlinerTests`1.cs b/src/EditorFeatures/CSharpTest/Outlining/AbstractOutlinerTests`1.cs index 78ade191492..ed0a0b45e87 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/AbstractOutlinerTests`1.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/AbstractOutlinerTests`1.cs @@ -1,22 +1,28 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; +using Microsoft.CodeAnalysis.Editor.UnitTests.Outlining; using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; +using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public abstract class AbstractOutlinerTests : - AbstractOutlinerTests + public abstract class AbstractOutlinerTests : AbstractOutlinerTests where TSyntaxNode : SyntaxNode { - internal virtual IEnumerable GetRegions(TSyntaxNode node) + internal abstract AbstractSyntaxNodeOutliner CreateOutliner(); + + internal IEnumerable GetRegions(TSyntaxNode node) { - return Enumerable.Empty(); + var outliner = CreateOutliner(); + return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); } internal OutliningSpan GetRegion(TSyntaxNode node) @@ -27,32 +33,70 @@ internal OutliningSpan GetRegion(TSyntaxNode node) return regions[0]; } - protected void TestTrivia(string expectedRegionName, string code, SyntaxKind expectedKind, bool autoCollapse) + protected Tuple Region(string collapseSpanName, string hintSpanName, string bannerText, bool autoCollapse, bool isDefaultCollapsed = false) + { + return Tuple.Create(collapseSpanName, hintSpanName, bannerText, autoCollapse, isDefaultCollapsed); + } + + protected Tuple Region(string collapseSpanName, string bannerText, bool autoCollapse, bool isDefaultCollapsed = false) + { + return Tuple.Create(collapseSpanName, collapseSpanName, bannerText, autoCollapse, isDefaultCollapsed); + } + + protected void Regions(string markupCode, params Tuple[] expectedRegions) { - int caretPosition; - IList 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) + string code; + int? position; + IDictionary> spans; + MarkupTestFile.GetPositionAndSpans(markupCode, out code, out position, out spans); + + Assert.True(position.HasValue, "Can't find node! Test did not specify position."); + + var compilationUnit = SyntaxFactory.ParseCompilationUnit(code); + var token = compilationUnit.FindToken(position.Value, findInsideTrivia: true); + var node = token.Parent.FirstAncestorOrSelf(); + Assert.NotNull(node); + + var actualRegions = GetRegions(node).ToArray(); + Assert.True(expectedRegions.Length == actualRegions.Length, $"Expected {expectedRegions.Length} regions but there were {actualRegions.Length}"); + + for (int i = 0; i < actualRegions.Length; i++) { - Assert.Equal(0, actualRegions.Length); - return; + var actualRegion = actualRegions[i]; + var expectedRegion = expectedRegions[i]; + + var collapseSpanName = expectedRegion.Item1; + var hintSpanName = expectedRegion.Item2; + var bannerText = expectedRegion.Item3; + var autoCollapse = expectedRegion.Item4; + var isDefaultCollapsed = expectedRegion.Item5; + + Assert.True(spans.ContainsKey(collapseSpanName) && spans[collapseSpanName].Count == 1, $"Test did not specify '{collapseSpanName}' span."); + Assert.True(spans.ContainsKey(hintSpanName) && spans[hintSpanName].Count == 1, $"Test did not specify '{hintSpanName}' span."); + + var collapseSpan = spans[collapseSpanName][0]; + var hintSpan = spans[hintSpanName][0]; + + AssertRegion(new OutliningSpan(collapseSpan, hintSpan, bannerText, autoCollapse, isDefaultCollapsed), actualRegion); } + } + + protected void NoRegions(string markupCode) + { + string code; + int? position; + IDictionary> spans; + MarkupTestFile.GetPositionAndSpans(markupCode, out code, out position, out spans); + + Assert.True(position.HasValue, "Can't find node! Test did not specify position."); - Assert.Equal(1, actualRegions.Length); - var expectedRegion = new OutliningSpan( - spans[0], - expectedRegionName, - autoCollapse); + var compilationUnit = SyntaxFactory.ParseCompilationUnit(code); + var token = compilationUnit.FindToken(position.Value, findInsideTrivia: true); + var node = token.Parent.FirstAncestorOrSelf(); + Assert.NotNull(node); - AssertRegion(expectedRegion, actualRegions[0]); + var actualRegions = GetRegions(node).ToArray(); + Assert.True(actualRegions.Length == 0, $"Expected no regions but found {actualRegions.Length}."); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/AccessorDeclarationTests.cs b/src/EditorFeatures/CSharpTest/Outlining/AccessorDeclarationTests.cs index 4c1001d682a..f515ec8275c 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/AccessorDeclarationTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/AccessorDeclarationTests.cs @@ -1,457 +1,280 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { public class AccessorDeclarationTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(AccessorDeclarationSyntax accessorDeclaration) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new AccessorDeclarationOutliner(); - return outliner.GetOutliningSpans(accessorDeclaration, CancellationToken.None).WhereNotNull(); + return new AccessorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyGetter1() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " get", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[0]; - - var actualRegion = GetRegion(accessor); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(46, 60), - TextSpan.FromBounds(43, 60), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + $${|hint:get{|collapse: + { + }|}|} + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyGetterWithSingleLineComments1() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " // My", - " // Getter", - " get", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[0]; - - var actualRegions = GetRegions(accessor).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(43, 63), - "// My ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(72, 86), - TextSpan.FromBounds(69, 86), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + {|span1:// My + // Getter|} + $${|hint2:get{|collapse2: + { + }|}|} + } +} +"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// My ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyGetterWithMultiLineComments1() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " /* My", - " Getter */", - " get", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[0]; - - var actualRegions = GetRegions(accessor).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(43, 66), - "/* My ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(75, 89), - TextSpan.FromBounds(72, 89), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + {|span1:/* My + Getter */|} + $${|hint2:get{|collapse2: + { + }|}|} + } +} +"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "/* My ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyGetter2() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " get", - " {", - " }", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[0]; - - var actualRegion = GetRegion(accessor); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(46, 60), - TextSpan.FromBounds(43, 60), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + $${|hint:get{|collapse: + { + }|}|} + set + { + } + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyGetterWithSingleLineComments2() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " // My", - " // Getter", - " get", - " {", - " }", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[0]; - - var actualRegions = GetRegions(accessor).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(43, 63), - "// My ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(72, 86), - TextSpan.FromBounds(69, 86), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + {|span1:// My + // Getter|} + $${|hint2:get{|collapse2: + { + }|}|} + set + { + } + } +} +"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// My ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyGetterWithMultiLineComments2() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " /* My", - " Getter */", - " get", - " {", - " }", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[0]; - - var actualRegions = GetRegions(accessor).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(43, 66), - "/* My ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(75, 89), - TextSpan.FromBounds(72, 89), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + {|span1:/* My + Getter */|} + $${|hint2:get{|collapse2: + { + }|}|} + set + { + } + } +} +"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "/* My ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertySetter1() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[0]; - - var actualRegion = GetRegion(accessor); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(46, 60), - TextSpan.FromBounds(43, 60), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); - } - - [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] - public void TestPropertySetter2() + const string code = @" +class C +{ + public string Text + { + $${|hint:set{|collapse: { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " get", - " {", - " }", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - 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); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertySetterWithSingleLineComments1() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " // My", - " // Setter", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[0]; - - var actualRegions = GetRegions(accessor).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(43, 63), - "// My ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(72, 86), - TextSpan.FromBounds(69, 86), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + {|span1:// My + // Setter|} + $${|hint2:set{|collapse2: + { + }|}|} + } +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// My ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertySetterWithMultiLineComments1() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " get", - " {", - " }", - " /* My", - " Setter */", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[1]; - - var actualRegions = GetRegions(accessor).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(66, 89), - "/* My ...", - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + {|span1:/* My + Setter */|} + $${|hint2:set{|collapse2: + { + }|}|} + } +}"; - AssertRegion(expectedRegion1, actualRegions[0]); + Regions(code, + Region("span1", "/* My ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); + } - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(98, 112), - TextSpan.FromBounds(95, 112), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] + public void TestPropertySetter2() + { + const string code = @" +class C +{ + public string Text + { + get + { + } + $${|hint:set{|collapse: + { + }|}|} + } +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertySetterWithSingleLineComments2() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " get", - " {", - " }", - " // My", - " // Setter", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[1]; - - var actualRegions = GetRegions(accessor).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(66, 86), - "// My ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(95, 109), - TextSpan.FromBounds(92, 109), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + get + { + } + {|span1:// My + // Setter|} + $${|hint2:set{|collapse2: + { + }|}|} + } +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// My ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertySetterWithMultiLineComments2() { - var tree = ParseLines("class C", - "{", - " public string Text", - " {", - " get", - " {", - " }", - " /* My", - " Setter */", - " set", - " {", - " }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - var accessor = propDecl.AccessorList.Accessors[1]; - - var actualRegions = GetRegions(accessor).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(66, 89), - "/* My ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(98, 112), - TextSpan.FromBounds(95, 112), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + public string Text + { + get + { + } + {|span1:/* My + Setter */|} + $${|hint2:set{|collapse2: + { + }|}|} + } +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "/* My ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/AnonymousMethodExpressionTests.cs b/src/EditorFeatures/CSharpTest/Outlining/AnonymousMethodExpressionTests.cs index 85add134a79..9bdff306dd9 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/AnonymousMethodExpressionTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/AnonymousMethodExpressionTests.cs @@ -1,117 +1,87 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class AnonymousMethodExpressionTests : - AbstractOutlinerTests + public class AnonymousMethodExpressionTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(AnonymousMethodExpressionSyntax lambdaExpression) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new AnonymousMethodExpressionOutliner(); - return outliner.GetOutliningSpans(lambdaExpression, CancellationToken.None).WhereNotNull(); + return new AnonymousMethodExpressionOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestAnonymousMethod() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " delegate {", - " x();", - " };", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(45, 66), - TextSpan.FromBounds(36, 66), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void Main() + { + $${|hint:delegate {|collapse:{ + x(); + };|}|} + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestAnonymousMethodInForLoop() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " for (Action a = delegate { }; true; a()) { }", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegions = GetRegions(lambdaExpression).ToList(); + const string code = @" +class C +{ + void Main() + { + for (Action a = $$delegate { }; true; a()) { } + } +}"; - Assert.Equal(0, actualRegions.Count); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestAnonymousMethodInMethodCall1() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " someMethod(42, \"test\", false, delegate(int x, int y, int z) {", - " return x + y + z;", - " }, \"other arguments\");", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(96, 131), - TextSpan.FromBounds(66, 131), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void Main() + { + someMethod(42, ""test"", false, {|hint:$$delegate(int x, int y, int z) {|collapse:{ + return x + y + z; + }|}|}, ""other arguments""); + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestAnonymousMethodInMethodCall2() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " someMethod(42, \"test\", false, delegate(int x, int y, int z) {", - " return x + y + z;", - " });", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(96, 131), - TextSpan.FromBounds(66, 131), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void Main() + { + someMethod(42, ""test"", false, {|hint:$$delegate(int x, int y, int z) {|collapse:{ + return x + y + z; + }|}|}); + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/CommentTests.cs b/src/EditorFeatures/CSharpTest/Outlining/CommentTests.cs index ee02d8b6fd1..568a254aaec 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/CommentTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/CommentTests.cs @@ -3,9 +3,11 @@ using System.Linq; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; +using Microsoft.CodeAnalysis.Editor.UnitTests.Outlining; using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; +using static Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.Utils; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { diff --git a/src/EditorFeatures/CSharpTest/Outlining/CompilationUnitOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/CompilationUnitOutlinerTests.cs index 494469cb9df..9d22e33ed94 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/CompilationUnitOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/CompilationUnitOutlinerTests.cs @@ -1,263 +1,150 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { public class CompilationUnitOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(CompilationUnitSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new CompilationUnitOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new CompilationUnitOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestUsings() { - var tree = ParseLines("using System;", - "using System.Core;"); + const string code = @" +$${|hint:using {|collapse: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); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestUsingAliases() { - var tree = ParseLines("using System;", - "using System.Core;", - "using text = System.Text;", - "using linq = System.Linq;"); - - var compilationUnit = tree.GetRoot() as CompilationUnitSyntax; - - var actualRegion = GetRegion(compilationUnit); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(6, 87), - hintSpan: TextSpan.FromBounds(0, 87), - bannerText: CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" +$${|hint:using {|collapse:System; +using System.Core; +using text = System.Text; +using linq = System.Linq;|}|}"; + + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestExternAliases() { - var tree = ParseLines("extern alias Foo;", - "extern alias Bar;"); - - var compilationUnit = (CompilationUnitSyntax)tree.GetRoot(); + const string code = @" +$${|hint:extern {|collapse:alias Foo; +extern alias Bar;|}|}"; - 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); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestExternAliasesAndUsings() { - var tree = ParseLines("extern alias Foo;", - "extern alias Bar;", - "using System;", - "using System.Core;"); - - var compilationUnit = tree.GetRoot() as CompilationUnitSyntax; - - var actualRegion = GetRegion(compilationUnit); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(7, 71), - hintSpan: TextSpan.FromBounds(0, 71), - bannerText: CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" +$${|hint:extern {|collapse:alias Foo; +extern alias Bar; +using System; +using System.Core;|}|}"; + + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestExternAliasesAndUsingsWithLeadingTrailingAndNestedComments() { - var tree = ParseLines("// Foo", - "// Bar", - "extern alias Foo;", - "extern alias Bar;", - "// Foo", - "// Bar", - "using System;", - "using System.Core;", - "// Foo", - "// Bar"); - - var compilationUnit = (CompilationUnitSyntax)tree.GetRoot(); - - var actualRegions = GetRegions(compilationUnit).ToList(); - Assert.Equal(3, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(0, 14), - "// Foo ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(23, 103), - hintSpan: TextSpan.FromBounds(16, 103), - bannerText: CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion2, actualRegions[1]); - - var expectedRegion3 = new OutliningSpan( - TextSpan.FromBounds(105, 119), - "// Foo ...", - autoCollapse: true); - - AssertRegion(expectedRegion3, actualRegions[2]); + const string code = @" +$${|span1:// Foo +// Bar|} +{|hint2:extern {|collapse2:alias Foo; +extern alias Bar; +// Foo +// Bar +using System; +using System.Core;|}|} +{|span3:// Foo +// Bar|}"; + + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true), + Region("span3", "// Foo ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestUsingsWithComments() { - var tree = ParseLines("// Foo", - "// Bar", - "using System;", - "using System.Core;"); - - 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(22, 49), - hintSpan: TextSpan.FromBounds(16, 49), - bannerText: CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion2, actualRegions[1]); + const string code = @" +$${|span1:// Foo +// Bar|} +{|hint2:using {|collapse2:System; +using System.Core;|}|}"; + + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] 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]); + const string code = @" +$${|span1:// Foo +// Bar|} +{|hint2:extern {|collapse2:alias Foo; +extern alias Bar;|}|}"; + + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestWithComments() { - var tree = ParseLines("// Foo", - "// Bar"); + const string code = @" +$${|span1:// 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); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] 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]); + const string code = @" +$${|hint1:using {|collapse1:System;|}|} +{|span2:// Foo +// Bar|}"; + + Regions(code, + Region("collapse1", "hint1", CSharpOutliningHelpers.Ellipsis, autoCollapse: true), + Region("span2", "// Foo ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] [WorkItem(539359)] 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); + const string code = @" +$${|hint:using|} {|collapse:|}"; - AssertRegion(expectedRegion, actualRegions[0]); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/ConstructorDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/ConstructorDeclarationOutlinerTests.cs index 01d4f4efee4..459542ed5cb 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/ConstructorDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/ConstructorDeclarationOutlinerTests.cs @@ -1,244 +1,158 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class ConstructorDeclarationOutlinerTests : - AbstractOutlinerTests + public class ConstructorDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(ConstructorDeclarationSyntax constructorDeclaration) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new ConstructorDeclarationOutliner(); - return outliner.GetOutliningSpans(constructorDeclaration, CancellationToken.None).WhereNotNull(); + return new ConstructorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructor1() { - var tree = ParseLines("class C", - "{", - " public C()", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(24, 34), - TextSpan.FromBounds(14, 34), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public C(){|collapse: + { + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructor2() { - var tree = ParseLines("class C", - "{", - " public C()", - " {", - " } ", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(24, 51), - TextSpan.FromBounds(14, 51), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public C(){|collapse: + { + } |}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructor3() { - var tree = ParseLines("class C", - "{", - " public C()", - " {", - " } // .ctor", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(24, 34), - TextSpan.FromBounds(14, 34), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public C(){|collapse: + { + }|}|} // .ctor +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructor4() { - var tree = ParseLines("class C", - "{", - " public C()", - " {", - " } /* .ctor */", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(24, 34), - TextSpan.FromBounds(14, 34), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public C(){|collapse: + { + }|}|} /* .ctor */ +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructor5() { - var tree = ParseLines("class C", - "{", - " public C() // .ctor", - " {", - " } // .ctor", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(33, 43), - TextSpan.FromBounds(14, 43), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public C() // .ctor{|collapse: + { + }|}|} // .ctor +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructor6() { - var tree = ParseLines("class C", - "{", - " public C() /* .ctor */", - " {", - " } // .ctor", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(36, 46), - TextSpan.FromBounds(14, 46), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public C() /* .ctor */{|collapse: + { + }|}|} // .ctor +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructor7() { - var tree = ParseLines("class C", - "{", - " public C()", - " // .ctor", - " {", - " } // .ctor", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(36, 46), - TextSpan.FromBounds(14, 46), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public C() + // .ctor{|collapse: + { + }|}|} // .ctor +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructor8() { - var tree = ParseLines("class C", - "{", - " public C()", - " /* .ctor */", - " {", - " } // .ctor", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(39, 49), - TextSpan.FromBounds(14, 49), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public C() + /* .ctor */{|collapse: + { + }|}|} // .ctor +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestConstructorWithComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " public C()", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - 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); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$public C(){|collapse2: + { + }|}|} // .ctor +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] @@ -246,30 +160,13 @@ 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(); - var consDeclRegions = GetRegions(consDecl).ToList(); + const string code = @" +class C +{ + $$C( +}"; - Assert.Equal(0, consDeclRegions.Count); + NoRegions(code); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/ConversionOperatorDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/ConversionOperatorDeclarationOutlinerTests.cs index 350f1a8daf9..6a6f8a49466 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/ConversionOperatorDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/ConversionOperatorDeclarationOutlinerTests.cs @@ -1,83 +1,52 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class ConversionOperatorDeclarationOutlinerTests : - AbstractOutlinerTests + public class ConversionOperatorDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(ConversionOperatorDeclarationSyntax operatorDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new ConversionOperatorDeclarationOutliner(); - return outliner.GetOutliningSpans(operatorDecl, CancellationToken.None).WhereNotNull(); + return new ConversionOperatorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestOperator() { - var tree = ParseLines("class C", - "{", - " public static explicit operator C (byte i)", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(operatorDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(56, 66), - TextSpan.FromBounds(14, 66), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public static explicit operator C(byte i){|collapse: + { + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] 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(); - - 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); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$public static explicit operator C(byte i){|collapse2: + { + }|}|} +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/DelegateDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/DelegateDeclarationOutlinerTests.cs index ad9e6f005fb..520a839d1ca 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/DelegateDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/DelegateDeclarationOutlinerTests.cs @@ -1,42 +1,30 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class DelegateDeclarationOutlinerTests : - AbstractOutlinerTests + public class DelegateDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(DelegateDeclarationSyntax delegateDeclaration) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new DelegateDeclarationOutliner(); - return outliner.GetOutliningSpans(delegateDeclaration, CancellationToken.None); + return new DelegateDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestDelegateWithComments() { - var tree = ParseLines("// Foo", - "// Bar", - "public delegate void C();"); + const string code = @" +{|span:// Foo +// Bar|} +$$public delegate void C();"; - var delegateDecl = tree.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(delegateDecl); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 14), - "// Foo ...", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "// Foo ...", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/DestructorDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/DestructorDeclarationOutlinerTests.cs index a062804c736..250b5fd0690 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/DestructorDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/DestructorDeclarationOutlinerTests.cs @@ -1,81 +1,51 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class DestructorDeclarationOutlinerTests : - AbstractOutlinerTests + public class DestructorDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(DestructorDeclarationSyntax destructorDeclaration) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new DestructorDeclarationOutliner(); - return outliner.GetOutliningSpans(destructorDeclaration, CancellationToken.None).WhereNotNull(); + return new DestructorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestDestructor() { - var tree = ParseLines("class C", - "{", - " ~C()", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var destructor = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(destructor); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 28), - TextSpan.FromBounds(14, 28), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$~C(){|collapse: + { + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestDestructorWithComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " ~C()", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var destructor = typeDecl.DigToFirstNodeOfType(); - - var actualRegions = GetRegions(destructor).ToList(); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(14, 30), - "// Foo ...", - autoCollapse: true); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(38, 48), - TextSpan.FromBounds(34, 48), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$~C(){|collapse2: + { + }|}|} +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] @@ -83,30 +53,13 @@ public void TestDestructorMissingCloseParenAndBody() { // Expected behavior is that the class should be outlined, but the destructor 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, 20), - TextSpan.FromBounds(0, 20), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); - - AssertRegion(expectedTypeDeclRegion, typeDeclRegions[0]); - - var destructor = typeDecl.DigToFirstNodeOfType(); - var destructorRegions = GetRegions(destructor).ToList(); + const string code = @" +class C +{ + $$~C( +}"; - Assert.Equal(0, destructorRegions.Count); + NoRegions(code); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/DisabledTextOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/DisabledTextOutlinerTests.cs index 6ff17fcc394..259ae82add5 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/DisabledTextOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/DisabledTextOutlinerTests.cs @@ -7,9 +7,11 @@ using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; +using Microsoft.CodeAnalysis.Editor.UnitTests.Outlining; using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; +using static Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.Utils; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { diff --git a/src/EditorFeatures/CSharpTest/Outlining/DocumentationCommentOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/DocumentationCommentOutlinerTests.cs index 4b6473a715d..1002db0b882 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/DocumentationCommentOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/DocumentationCommentOutlinerTests.cs @@ -1,412 +1,242 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class DocumentationCommentOutlinerTests : - AbstractOutlinerTests + public class DocumentationCommentOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(DocumentationCommentTriviaSyntax documentationComment) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new DocumentationCommentOutliner(); - return outliner.GetOutliningSpans(documentationComment, CancellationToken.None).WhereNotNull(); + return new DocumentationCommentOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestDocumentationCommentWithoutSummaryTag1() { - var tree = ParseLines("/// XML doc comment", - "/// some description", - "/// of", - "/// the comment", - "class Class3", - "{", - "}"); - - 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, 66), - "/// XML doc comment ...", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" +{|span:/// $$XML doc comment +/// some description +/// of +/// the comment|} +class Class3 +{ +}"; + + Regions(code, + Region("span", "/// XML doc comment ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] 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); + const string code = @" +{|span:/** $$Block comment +* some description +* of +* the comment +*/|} +class Class3 +{ +}"; + + Regions(code, + Region("span", "/** Block comment ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestDocumentationCommentWithoutSummaryTag3() { - var tree = ParseLines("/// ", - "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, 31), - "/// ...", - autoCollapse: true); + const string code = @" +{|span:/// $$|} +class Class3 +{ +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "/// ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestDocumentationComment() { - var tree = ParseLines("/// ", - "/// Hello C#!", - "/// ", - "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, 44), - "/// Hello C#!", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" +{|span:/// +/// $$Hello C#! +/// |} +class Class3 +{ +}"; + + Regions(code, + Region("span", "/// Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestDocumentationCommentWithLongBannerText() { - var tree = ParseLines("/// ", - "/// " + new string('x', 240), - "/// ", - "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 = "/// " + new string('x', 106) + " ..."; - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 275), - expectedBannerText, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + var code = @" +{|span:/// $$ +/// " + new string('x', 240) + @" +/// |} +class Class3 +{ +}"; + + Regions(code, + Region("span", "/// " + new string('x', 106) + " ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestMultilineDocumentationComment() { - var tree = ParseLines("/** ", - "Hello C#!", - " */", - "class C", - "{", - "}"); - - 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, 39), - "/** Hello C#!", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" +{|span:/** +$$Hello C#! + */|} +class Class3 +{ +}"; + + Regions(code, + Region("span", "/** Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestIndentedDocumentationComment() { - var tree = ParseLines(" /// ", - " /// Hello C#!", - " /// ", - " class C", - " {", - " }"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var trivia = typeDecl.GetLeadingTrivia().ToList(); - Assert.Equal(3, trivia.Count); - - var documentationComment = trivia[1].GetStructure() as DocumentationCommentTriviaSyntax; - Assert.NotNull(documentationComment); - - var actualRegion = GetRegion(documentationComment); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(4, 56), - "/// Hello C#!", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" + {|span:/// + /// $$Hello C#! + /// |} + class Class3 + { + }"; + + Regions(code, + Region("span", "/// Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestIndentedMultilineDocumentationComment() { - var tree = ParseLines(" /** ", - " Hello C#!", - " */", - " class C", - " {", - " }"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var trivia = typeDecl.GetLeadingTrivia().ToList(); - Assert.Equal(4, trivia.Count); - - var documentationComment = trivia[1].GetStructure() as DocumentationCommentTriviaSyntax; - Assert.NotNull(documentationComment); - - var actualRegion = GetRegion(documentationComment); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(4, 51), - "/** Hello C#!", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" + {|span:/** + $$Hello C#! + */|} + class Class3 + { + }"; + + Regions(code, + Region("span", "/** Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestDocumentationCommentOnASingleLine() { - var tree = ParseLines("/// Hello C#!", - "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, 32), - "/// Hello C#!", - autoCollapse: true); + const string code = @" +{|span:/// $$Hello C#!|} +class Class3 +{ +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "/// Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestMultilineDocumentationCommentOnASingleLine() { - var tree = ParseLines("/** Hello C#! */", - "class C", - "{", - "}"); - - 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, 35), - "/** Hello C#!", - autoCollapse: true); + const string code = @" +{|span:/** $$Hello C#! */|} +class Class3 +{ +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "/** Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestIndentedDocumentationCommentOnASingleLine() { - var tree = ParseLines(" /// Hello C#!", - " class C", - " {", - " }"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var trivia = typeDecl.GetLeadingTrivia().ToList(); - Assert.Equal(3, trivia.Count); - - var documentationComment = trivia[1].GetStructure() as DocumentationCommentTriviaSyntax; - Assert.NotNull(documentationComment); - - var actualRegion = GetRegion(documentationComment); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(4, 36), - "/// Hello C#!", - autoCollapse: true); + const string code = @" + {|span:/// $$Hello C#!|} + class Class3 + { + }"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "/// Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestIndentedMultilineDocumentationCommentOnASingleLine() { - var tree = ParseLines(" /** Hello C#! */", - " class C", - " {", - " }"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var trivia = typeDecl.GetLeadingTrivia().ToList(); - Assert.Equal(4, trivia.Count); - - var documentationComment = trivia[1].GetStructure() as DocumentationCommentTriviaSyntax; - Assert.NotNull(documentationComment); - - var actualRegion = GetRegion(documentationComment); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(4, 39), - "/** Hello C#!", - autoCollapse: true); + const string code = @" + {|span:/** $$Hello C#! */|} + class Class3 + { + }"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "/** Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestMultilineSummaryInDocumentationComment1() { - var tree = ParseLines("/// ", - "/// Hello", - "/// C#!", - "/// ", - "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, 49), - "/// Hello C#!", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" +{|span:/// +/// $$Hello +/// C#! +/// |} +class Class3 +{ +}"; + + Regions(code, + Region("span", "/// Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestMultilineSummaryInDocumentationComment2() { - var tree = ParseLines("/// ", - "/// Hello", - "/// ", - "/// C#!", - "/// ", - "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), - "/// Hello C#!", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" +{|span:/// +/// $$Hello +/// +/// C#! +/// |} +class Class3 +{ +}"; + + Regions(code, + Region("span", "/// Hello C#!", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] [WorkItem(2129, "https://github.com/dotnet/roslyn/issues/2129")] public void CrefInSummary() { - var tree = ParseLines("class C", - "{", - " /// ", - " /// Summary with , , ", - " /// , , , and .", - " /// ", - " public void M(T t) { }", - "}"); - - var method = tree.GetRoot().FindFirstNodeOfType(); - var trivia = method.GetLeadingTrivia(); - - var docComment = (DocumentationCommentTriviaSyntax)trivia.Single(t => t.HasStructure).GetStructure(); - var actualRegion = GetRegion(docComment); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(16, 265), - "/// Summary with SeeClass , SeeAlsoClass , null , T , t , and not-supported .", - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + const string code = @" +class C +{ + {|span:/// $$ + /// Summary with , , + /// , , , and . + /// |} + public void M(T t) { } +}"; + + Regions(code, + Region("span", "/// Summary with SeeClass , SeeAlsoClass , null , T , t , and not-supported .", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/EnumDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/EnumDeclarationOutlinerTests.cs index 780d39003d5..f89c157b70f 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/EnumDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/EnumDeclarationOutlinerTests.cs @@ -1,12 +1,8 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; @@ -15,89 +11,51 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining public class EnumDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(EnumDeclarationSyntax enumDeclaration) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new EnumDeclarationOutliner(); - return outliner.GetOutliningSpans(enumDeclaration, CancellationToken.None); + return new EnumDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestEnum() { - var tree = ParseLines("enum E", - "{", - "}"); - - var enumDecl = tree.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(enumDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(6, 12), - TextSpan.FromBounds(0, 12), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +{|hint:$$enum E{|collapse: +{ +}|}|}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestEnumWithLeadingComments() { - var tree = ParseLines("// Foo", - "// Bar", - "enum E", - "{", - "}"); - - var enumDecl = tree.DigToFirstNodeOfType(); - - var actualRegions = GetRegions(enumDecl).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(22, 28), - TextSpan.FromBounds(16, 28), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +{|span1:// Foo +// Bar|} +{|hint2:$$enum E{|collapse2: +{ +}|}|}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestEnumWithNestedComments() { - var tree = ParseLines("enum E", - "{", - " // Foo", - " // Bar", - "}"); - - var enumDecl = tree.DigToFirstNodeOfType(); - - 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); + const string code = @" +{|hint1:$$enum E{|collapse1: +{ + {|span2:// Foo + // Bar|} +}|}|}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("collapse1", "hint1", CSharpOutliningHelpers.Ellipsis, autoCollapse: false), + Region("span2", "// Foo ...", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/EventDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/EventDeclarationOutlinerTests.cs index a49f4315c3e..22ab9b4c1fd 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/EventDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/EventDeclarationOutlinerTests.cs @@ -1,85 +1,55 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class EventDeclarationOutlinerTests : - AbstractOutlinerTests + public class EventDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(EventDeclarationSyntax eventDeclaration) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new EventDeclarationOutliner(); - return outliner.GetOutliningSpans(eventDeclaration, CancellationToken.None); + return new EventDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestEvent() { - var tree = ParseLines("class C", - "{", - " event EventHandler E", - " {", - " add { }", - " remove { }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(eventDecl); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(34, 73), - TextSpan.FromBounds(14, 73), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$event EventHandler E{|collapse: + { + add { } + remove { } + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestEventWithComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " event EventHandler E", - " {", - " add { }", - " remove { }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); - - 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]); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$event EventHandler E{|collapse2: + { + add { } + remove { } + }|}|} +}"; + + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/EventFieldDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/EventFieldDeclarationOutlinerTests.cs index 9fa613e1bd4..e3c3570bf90 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/EventFieldDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/EventFieldDeclarationOutlinerTests.cs @@ -1,46 +1,33 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class EventFieldDeclarationOutlinerTests : - AbstractOutlinerTests + public class EventFieldDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(EventFieldDeclarationSyntax eventFieldDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new EventFieldDeclarationOutliner(); - return outliner.GetOutliningSpans(eventFieldDecl, CancellationToken.None); + return new EventFieldDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestEventFieldWithComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " event EventHandler E;", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventFieldDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(eventFieldDecl); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(14, 30), - "// Foo ...", - autoCollapse: true); + const string code = @" +class C +{ + {|span:// Foo + // Bar|} + $$event EventHandler E; +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "// Foo ...", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/FieldDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/FieldDeclarationOutlinerTests.cs index 719e631afea..177c08491f2 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/FieldDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/FieldDeclarationOutlinerTests.cs @@ -1,46 +1,33 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class FieldDeclarationOutlinerTests : - AbstractOutlinerTests + public class FieldDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(FieldDeclarationSyntax fieldDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new FieldDeclarationOutliner(); - return outliner.GetOutliningSpans(fieldDecl, CancellationToken.None); + return new FieldDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestFieldWithComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " int F;", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var fieldDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(fieldDecl); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(14, 30), - "// Foo ...", - autoCollapse: true); + const string code = @" +class C +{ + {|span:// Foo + // Bar|} + $$int F; +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "// Foo ...", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/IndexerDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/IndexerDeclarationOutlinerTests.cs index 8af2c8e1d13..8aab1c5aa60 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/IndexerDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/IndexerDeclarationOutlinerTests.cs @@ -1,105 +1,68 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class IndexerDeclarationOutlinerTests : - AbstractOutlinerTests + public class IndexerDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(IndexerDeclarationSyntax indexerDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new IndexerDeclarationOutliner(); - return outliner.GetOutliningSpans(indexerDecl, CancellationToken.None); + return new IndexerDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestIndexer() { - var tree = ParseLines("class C", - "{", - " public string this[int index]", - " {", - " get { }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var indexerDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(indexerDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(43, 66), - TextSpan.FromBounds(14, 66), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public string this[int index]{|collapse: + { + get { } + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestIndexerWithComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " public string this[int index]", - " {", - " get { }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var indexerDecl = typeDecl.DigToFirstNodeOfType(); - - 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); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$public string this[int index]{|collapse2: + { + get { } + }|}|} +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestIndexerWithWithExpressionBodyAndComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " public string this[int index] => 0;", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var indexerDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(indexerDecl); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(14, 30), - "// Foo ...", - autoCollapse: true); + const string code = @" +class C +{ + {|span:// Foo + // Bar|} + $$public string this[int index] => 0; +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "// Foo ...", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/ConstructorDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/ConstructorDeclarationOutlinerTests.cs index 66870a17031..7ba7c0de83a 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/ConstructorDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/ConstructorDeclarationOutlinerTests.cs @@ -1,111 +1,77 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class ConstructorDeclarationOutlinerTests : - AbstractOutlinerTests + public class ConstructorDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(ConstructorDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.ConstructorDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.ConstructorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class C + const string code = @" +class C { - C(); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); + $$C(); +}"; - Assert.Empty(GetRegions(consDecl)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class C + const string code = @" +class C { - [Bar] - C(); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(16, 27), - TextSpan.FromBounds(16, 31), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Bar] + |}$$C();|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class C + const string code = @" +class C { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Bar] - C(); -}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); + |}$$C();|} +}"; - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(16, 75), - TextSpan.FromBounds(16, 79), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"class C + const string code = @" +class C { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Bar] - public C(); -}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var consDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(consDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(16, 75), - TextSpan.FromBounds(16, 86), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}$$public C();|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/ConversionOperatorDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/ConversionOperatorDeclarationOutlinerTests.cs index 07314d12e13..75bfac72a91 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/ConversionOperatorDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/ConversionOperatorDeclarationOutlinerTests.cs @@ -1,85 +1,61 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class ConversionOperatorDeclarationOutlinerTests : - AbstractOutlinerTests + public class ConversionOperatorDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(ConversionOperatorDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.ConversionOperatorDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.ConversionOperatorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class C { - public static explicit operator Foo (byte b); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorMethod = typeDecl.DigToFirstNodeOfType(); + public static explicit operator $$Foo(byte b); +}"; - Assert.Empty(GetRegions(operatorMethod)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class C { - [Blah] - public static explicit operator Foo (byte b); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorMethod = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(operatorMethod); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 30), - TextSpan.FromBounds(18, 75), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Blah] + |}public static explicit operator $$Foo(byte b);|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class C { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Blah] - public static explicit operator Foo (byte b); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorMethod = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(operatorMethod); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 78), - TextSpan.FromBounds(18, 123), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}public static explicit operator $$Foo(byte b);|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/DelegateDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/DelegateDeclarationOutlinerTests.cs index c3149800054..9040c9f792a 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/DelegateDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/DelegateDeclarationOutlinerTests.cs @@ -1,92 +1,65 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class DelegateDeclarationOutlinerTests : - AbstractOutlinerTests + public class DelegateDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(DelegateDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.DelegateDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.DelegateDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode(@"public delegate TResult Blah(T arg);"); - var delegateDecl = tree.DigToFirstNodeOfType(); + const string code = @" +public delegate TResult $$Blah(T arg);"; - Assert.Empty(GetRegions(delegateDecl)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"[Foo] -public delegate TResult Blah(T arg);"); - var delegateDecl = tree.DigToFirstNodeOfType(); + const string code = @" +{|hint:{|collapse:[Foo] +|}public delegate TResult $$Blah(T arg);|}"; - var actualRegion = GetRegion(delegateDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 7), - TextSpan.FromBounds(0, 62), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"// Summary: + const string code = @" +{|hint:{|collapse:// Summary: // This is a summary. [Foo] -delegate TResult Blah(T arg);"); - var delegateDecl = tree.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(delegateDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 47), - TextSpan.FromBounds(0, 95), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); +|}delegate TResult $$Blah(T arg);|}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"// Summary: + const string code = @" +{|hint:{|collapse:// Summary: // This is a summary. [Foo] -public delegate TResult Blah(T arg);"); - var delegateDecl = tree.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(delegateDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 47), - TextSpan.FromBounds(0, 102), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); +|}public delegate TResult $$Blah(T arg);|}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/DestructorDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/DestructorDeclarationOutlinerTests.cs index ba4b9c039e6..12d0c8b1cb3 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/DestructorDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/DestructorDeclarationOutlinerTests.cs @@ -1,85 +1,61 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class DestructorDeclarationOutlinerTests : - AbstractOutlinerTests + public class DestructorDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(DestructorDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.DestructorDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.DestructorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - ~Foo(); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var destructor = typeDecl.DigToFirstNodeOfType(); + $$~Foo(); +}"; - Assert.Empty(GetRegions(destructor)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - [Bar] - ~Foo(); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var destructor = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(destructor); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 29), - TextSpan.FromBounds(18, 36), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Bar] + |}$$~Foo();|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Bar] - ~Foo(); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var destructor = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(destructor); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 84), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}$$~Foo();|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EnumDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EnumDeclarationOutlinerTests.cs index 0247c7344b8..d6d64d4f58e 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EnumDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EnumDeclarationOutlinerTests.cs @@ -1,109 +1,81 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class EnumDeclarationOutlinerTests : - AbstractOutlinerTests + public class EnumDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(EnumDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.EnumDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.EnumDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"enum C + const string code = @" +enum $$E { A, B -}"); - var enumDecl = tree.DigToFirstNodeOfType(); +}"; - Assert.Empty(GetRegions(enumDecl)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"[Bar] -enum C + const string code = @" +{|hint:{|collapse:[Bar] +|}enum $$E|} { A, B -}"); - var enumDecl = tree.DigToFirstNodeOfType(); +}"; - var actualRegion = GetRegion(enumDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 7), - TextSpan.FromBounds(0, 13), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"// Summary: + const string code = @" +{|hint:{|collapse:// Summary: // This is a summary. [Bar] -enum C +|}enum $$E|} { A, B -}"); - var enumDecl = tree.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(enumDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 47), - TextSpan.FromBounds(0, 53), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"// Summary: + const string code = @" +{|hint:{|collapse:// Summary: // This is a summary. [Bar] -public enum C +|}public enum $$E|} { A, B -}"); - var enumDecl = tree.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(enumDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 47), - TextSpan.FromBounds(0, 60), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EnumMemberDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EnumMemberDeclarationOutlinerTests.cs index 8be2835b52b..c879a80c611 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EnumMemberDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EnumMemberDeclarationOutlinerTests.cs @@ -1,88 +1,64 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class EnumMemberDeclarationOutlinerTests : - AbstractOutlinerTests + public class EnumMemberDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(EnumMemberDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.EnumMemberDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.EnumMemberDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"enum E + const string code = @" +enum E { - Foo, + $$Foo, Bar -}"); - var enumDecl = tree.DigToFirstNodeOfType(); - var enumMember = enumDecl.DigToFirstNodeOfType(); +}"; - Assert.Empty(GetRegions(enumMember)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"enum E + const string code = @" +enum E { - [Blah] - Foo, + {|hint:{|collapse:[Blah] + |}$$Foo|}, Bar -}"); - var enumDecl = tree.DigToFirstNodeOfType(); - var enumMember = enumDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(enumMember); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(15, 27), - TextSpan.FromBounds(15, 30), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"enum E + const string code = @" +enum E { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Blah] - Foo, + |}$$Foo|}, Bar -}"); - var enumDecl = tree.DigToFirstNodeOfType(); - var enumMember = enumDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(enumMember); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(15, 75), - TextSpan.FromBounds(15, 78), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EventDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EventDeclarationOutlinerTests.cs index e9edc86a7e5..737c1ae12a0 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EventDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EventDeclarationOutlinerTests.cs @@ -1,109 +1,77 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class EventDeclarationOutlinerTests : - AbstractOutlinerTests + public class EventDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(EventDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.EventDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.EventDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - public event EventArgs foo { add; remove; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); + public event EventArgs $$foo { add; remove; } +}"; - Assert.Empty(GetRegions(eventDecl)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - [Foo] - public event EventArgs foo { add; remove; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(eventDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 29), - TextSpan.FromBounds(18, 72), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Foo] + |}public event EventArgs $$foo { add; remove; }|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - event EventArgs foo { add; remove; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); + |}event EventArgs $$foo { add; remove; }|} +}"; - var actualRegion = GetRegion(eventDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 113), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - public event EventArgs foo { add; remove; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(eventDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 120), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}public event EventArgs $$foo { add; remove; }|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EventFieldDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EventFieldDeclarationOutlinerTests.cs index 7d2fedb3953..34a2c5cdec0 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EventFieldDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/EventFieldDeclarationOutlinerTests.cs @@ -1,109 +1,77 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class EventFieldDeclarationOutlinerTests : - AbstractOutlinerTests + public class EventFieldDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(EventFieldDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.EventFieldDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.EventFieldDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - public event EventArgs foo; -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); + public event EventArgs $$foo +}"; - Assert.Empty(GetRegions(eventDecl)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - [Foo] - public event EventArgs foo; -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(eventDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 29), - TextSpan.FromBounds(18, 56), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Foo] + |}event EventArgs $$foo|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - event EventArgs foo; -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); + |}event EventArgs $$foo|} +}"; - var actualRegion = GetRegion(eventDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 97), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - public event EventArgs foo; -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var eventDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(eventDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 104), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}public event EventArgs $$foo|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/FieldDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/FieldDeclarationOutlinerTests.cs index 0d8a7b97846..3e5a60270b0 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/FieldDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/FieldDeclarationOutlinerTests.cs @@ -1,13 +1,9 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; @@ -16,94 +12,67 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSou public class FieldDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(FieldDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.FieldDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.FieldDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - public int foo; -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var fieldDecl = typeDecl.DigToFirstNodeOfType(); + public int $$foo +}"; - Assert.Empty(GetRegions(fieldDecl)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - [Foo] - public int foo; -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var fieldDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(fieldDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 29), - TextSpan.FromBounds(18, 44), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Foo] + |}public int $$foo|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - int foo; -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var fieldDecl = typeDecl.DigToFirstNodeOfType(); + |}int $$foo|} +}"; - var actualRegion = GetRegion(fieldDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 85), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - public int foo; -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var fieldDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(fieldDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 92), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}public int $$foo|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/IndexerDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/IndexerDeclarationOutlinerTests.cs index 7fac0a195a2..31761fbe418 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/IndexerDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/IndexerDeclarationOutlinerTests.cs @@ -1,109 +1,77 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class IndexerDeclarationOutlinerTests : - AbstractOutlinerTests + public class IndexerDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(IndexerDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.IndexerDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.IndexerDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - public string this[int x] { get; set; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var indexer = typeDecl.DigToFirstNodeOfType(); + public string $$this[int x] { get; set; } +}"; - Assert.Empty(GetRegions(indexer)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - [Foo] - public string this[int x] { get; set; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var indexer = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(indexer); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 29), - TextSpan.FromBounds(18, 68), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Foo] + |}public string $$this[int x] { get; set; }|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - string this[int x] { get; set; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var indexer = typeDecl.DigToFirstNodeOfType(); + |}string $$this[int x] { get; set; }|} +}"; - var actualRegion = GetRegion(indexer); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 109), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndmodifiers() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - public string this[int x] { get; set; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var indexer = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(indexer); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 116), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}public string $$this[int x] { get; set; }|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/InvalidIdentifierTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/InvalidIdentifierTests.cs index 7f4f234eb7f..6e0daaae9c3 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/InvalidIdentifierTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/InvalidIdentifierTests.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; +using Microsoft.CodeAnalysis.Editor.UnitTests.Outlining; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; using Roslyn.Test.Utilities; using Xunit; diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/MethodDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/MethodDeclarationOutlinerTests.cs index 1cbe71d417c..cb5b5ae06de 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/MethodDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/MethodDeclarationOutlinerTests.cs @@ -1,109 +1,77 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class MethodDeclarationOutlinerTests : - AbstractOutlinerTests + public class MethodDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(MethodDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.MethodDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.MethodDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - public string Bar(int x); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var method = typeDecl.DigToFirstNodeOfType(); + public string $$Bar(int x); +}"; - Assert.Empty(GetRegions(method)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - [Foo] - public string Bar(int x); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var method = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(method); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 29), - TextSpan.FromBounds(18, 54), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Foo] + |}public string $$Bar(int x);|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - string Bar(int x); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var method = typeDecl.DigToFirstNodeOfType(); + |}string $$Bar(int x);|} +}"; - var actualRegion = GetRegion(method); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 95), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - public string Bar(int x); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var method = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(method); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 102), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}public string $$Bar(int x);|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/OperatorDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/OperatorDeclarationOutlinerTests.cs index bf93a82cd75..94b3c68fe3f 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/OperatorDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/OperatorDeclarationOutlinerTests.cs @@ -1,109 +1,77 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class OperatorDeclarationOutlinerTests : - AbstractOutlinerTests + public class OperatorDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(OperatorDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.OperatorDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.OperatorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - public static bool operator ==(Foo a, Foo b); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorMethod = typeDecl.DigToFirstNodeOfType(); + public static bool operator $$==(Foo a, Foo b); +}"; - Assert.Empty(GetRegions(operatorMethod)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - [Blah] - public static bool operator ==(Foo a, Foo b); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorMethod = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(operatorMethod); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 30), - TextSpan.FromBounds(18, 75), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Blah] + |}public static bool operator $$==(Foo a, Foo b);|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Blah] - bool operator ==(Foo a, Foo b); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorMethod = typeDecl.DigToFirstNodeOfType(); + |}bool operator $$==(Foo a, Foo b);|} +}"; - var actualRegion = GetRegion(operatorMethod); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 83), - TextSpan.FromBounds(18, 109), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Blah] - public static bool operator ==(Foo a, Foo b); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorMethod = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(operatorMethod); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 78), - TextSpan.FromBounds(18, 123), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}public static bool operator $$==(Foo a, Foo b);|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/PropertyDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/PropertyDeclarationOutlinerTests.cs index b899ffed78e..401ae0f6d6a 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/PropertyDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/PropertyDeclarationOutlinerTests.cs @@ -1,109 +1,77 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class PropertyDeclarationOutlinerTests : - AbstractOutlinerTests + public class PropertyDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(PropertyDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.PropertyDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.PropertyDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - public string Prop { get; set; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var prop = typeDecl.DigToFirstNodeOfType(); + public string $$Prop { get; set; } +}"; - Assert.Empty(GetRegions(prop)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - [Foo] - public string Prop { get; set; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var prop = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(prop); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 29), - TextSpan.FromBounds(18, 61), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + {|hint:{|collapse:[Foo] + |}public string $$Prop { get; set; }|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - string Prop { get; set; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var prop = typeDecl.DigToFirstNodeOfType(); + |}string $$Prop { get; set; }|} +}"; - var actualRegion = GetRegion(prop); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 102), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAttributesAndModifiers() { - var tree = ParseCode( -@"class Foo + const string code = @" +class Foo { - // Summary: + {|hint:{|collapse:// Summary: // This is a summary. [Foo] - public string Prop { get; set; } -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - var prop = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(prop); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(18, 77), - TextSpan.FromBounds(18, 109), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + |}public string $$Prop { get; set; }|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/RegionDirectiveOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/RegionDirectiveOutlinerTests.cs index 1cb9f33e865..eb144b02679 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/RegionDirectiveOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/RegionDirectiveOutlinerTests.cs @@ -1,68 +1,42 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class RegionDirectiveOutlinerTests : - AbstractOutlinerTests + public class RegionDirectiveOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(RegionDirectiveTriviaSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.RegionDirectiveOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.RegionDirectiveOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void FileHeader() { - var tree = ParseCode( -@"#region Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + const string code = @" +{|span:#re$$gion Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll -#endregion"); +#endregion|}"; - var trivia = tree.GetRoot().FindTrivia(position: 0); - var region = trivia.GetStructure() as RegionDirectiveTriviaSyntax; - - Assert.NotNull(region); - - var actualOutliningSpan = GetRegion(region); - var expectedOutliningSpan = new OutliningSpan( - TextSpan.FromBounds(0, 204), - bannerText: "Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", - autoCollapse: true); - - AssertRegion(expectedOutliningSpan, actualOutliningSpan); + Regions(code, + Region("span", "Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void EmptyFileHeader() { - var tree = ParseCode( -@"#region + const string code = @" +{|span:#re$$gion // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll -#endregion"); - - var trivia = tree.GetRoot().FindTrivia(position: 0); - var region = trivia.GetStructure() as RegionDirectiveTriviaSyntax; - - Assert.NotNull(region); - - var actualOutliningSpan = GetRegion(region); - var expectedOutliningSpan = new OutliningSpan( - TextSpan.FromBounds(0, 119), - bannerText: "#region", - autoCollapse: true); +#endregion|}"; - AssertRegion(expectedOutliningSpan, actualOutliningSpan); + Regions(code, + Region("span", "#region", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/TypeDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/TypeDeclarationOutlinerTests.cs index 0d01154c8eb..4b9b6adb5a8 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/TypeDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MetadataAsSource/TypeDeclarationOutlinerTests.cs @@ -1,83 +1,62 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using MaSOutliners = Microsoft.CodeAnalysis.Editor.CSharp.Outlining.MetadataAsSource; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining.MetadataAsSource { - public class TypeDeclarationOutlinerTests : - AbstractOutlinerTests + public class TypeDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(TypeDeclarationSyntax node) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MaSOutliners.TypeDeclarationOutliner(); - return outliner.GetOutliningSpans(node, CancellationToken.None).WhereNotNull(); + return new MaSOutliners.TypeDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void NoCommentsOrAttributes() { - var tree = ParseCode( -@"class C + const string code = @" +class $$C { void M(); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); +}"; - Assert.Empty(GetRegions(typeDecl)); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithAttributes() { - var tree = ParseCode( -@"[Bar] + const string code = @" +{|hint:{|collapse:[Bar] [Baz] -public class C +|}public class $$C|} { void M(); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); +}"; - var actualRegion = GetRegion(typeDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 14), - TextSpan.FromBounds(0, 28), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)] public void WithCommentsAndAttributes() { - var tree = ParseCode( -@"// Summary: + const string code = @" +{|hint:{|collapse:// Summary: // This is a doc comment. [Bar, Baz] -public class C +|}public class $$C|} { void M(); -}"); - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegion = GetRegion(typeDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(0, 56), - TextSpan.FromBounds(0, 70), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/MethodDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/MethodDeclarationOutlinerTests.cs index 545e6d41ff9..337c0856882 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/MethodDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/MethodDeclarationOutlinerTests.cs @@ -1,128 +1,81 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class MethodDeclarationOutlinerTests : - AbstractOutlinerTests + public class MethodDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(MethodDeclarationSyntax methodDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new MethodDeclarationOutliner(); - return outliner.GetOutliningSpans(methodDecl, CancellationToken.None).WhereNotNull(); + return new MethodDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestMethod() { - var tree = ParseLines("class C", - "{", - " public string Foo()", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var methodDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(methodDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(33, 43), - TextSpan.FromBounds(14, 43), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public string Foo(){|collapse: + { + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestMethodWithTrailingSpaces() { - var tree = ParseLines("class C", - "{", - " public string Foo() ", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var methodDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(methodDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(37, 47), - TextSpan.FromBounds(14, 47), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public string Foo() {|collapse: + { + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestMethodWithLeadingComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " public string Foo()", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var methodDecl = typeDecl.DigToFirstNodeOfType(); - - 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); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$public string Foo(){|collapse2: + { + }|}|} +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestMethodWithWithExpressionBodyAndComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " public string Foo() => \"Foo\";", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var methodDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(methodDecl); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(14, 30), - "// Foo ...", - autoCollapse: true); + const string code = @" +class C +{ + {|span:// Foo + // Bar|} + $$public string Foo() => ""Foo""; +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "// Foo ...", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/NamespaceDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/NamespaceDeclarationOutlinerTests.cs index a640585f9c0..c5edd0853ad 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/NamespaceDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/NamespaceDeclarationOutlinerTests.cs @@ -1,175 +1,108 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class NamespaceDeclarationOutlinerTests : - AbstractOutlinerTests + public class NamespaceDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(NamespaceDeclarationSyntax namespaceDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new NamespaceDeclarationOutliner(); - return outliner.GetOutliningSpans(namespaceDecl, CancellationToken.None).WhereNotNull(); + return new NamespaceDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestNamespace() { - var tree = ParseLines("namespace N", - "{", - "}"); - - var namespaceDecl = tree.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(namespaceDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(11, 17), - TextSpan.FromBounds(0, 17), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + {|hint:$$namespace N{|collapse: + { + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestNamespaceWithLeadingComments() { - var tree = ParseLines("// Foo", - "// Bar", - "namespace C", - "{", - "}"); - - var namespaceDecl = tree.DigToFirstNodeOfType(); - - 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); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$namespace N{|collapse2: + { + }|}|} +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestNamespaceWithNestedUsings() { - var tree = ParseLines("namespace C", - "{", - " using System;", - " using System.Linq;", - "}"); - - var namespaceDecl = tree.DigToFirstNodeOfType(); - - 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]); + const string code = @" +class C +{ + {|hint1:$$namespace N{|collapse1: + { + {|hint2:using {|collapse2:System; + using System.Linq;|}|} + }|}|} +}"; + + Regions(code, + Region("collapse1", "hint1", CSharpOutliningHelpers.Ellipsis, autoCollapse: false), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestNamespaceWithNestedUsingsWithLeadingComments() { - var tree = ParseLines("namespace C", - "{", - " // Foo", - " // Bar", - " using System;", - " using System.Linq;", - "}"); - - var namespaceDecl = tree.DigToFirstNodeOfType(); - - var actualRegions = GetRegions(namespaceDecl).ToList(); - Assert.Equal(3, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(11, 76), - TextSpan.FromBounds(0, 76), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(18, 34), - "// Foo ...", - autoCollapse: true); - - AssertRegion(expectedRegion2, actualRegions[1]); - - var expectedRegion3 = new OutliningSpan( - TextSpan.FromBounds(44, 73), - hintSpan: TextSpan.FromBounds(38, 73), - bannerText: CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion3, actualRegions[2]); + const string code = @" +class C +{ + {|hint1:$$namespace N{|collapse1: + { + {|span2:// Foo + // Bar|} + {|hint3:using {|collapse3:System; + using System.Linq;|}|} + }|}|} +}"; + + Regions(code, + Region("collapse1", "hint1", CSharpOutliningHelpers.Ellipsis, autoCollapse: false), + Region("span2", "// Foo ...", autoCollapse: true), + Region("collapse3", "hint3", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestNamespaceWithNestedComments() { - var tree = ParseLines("namespace C", - "{", - " // Foo", - " // Bar", - "}"); - - var namespaceDecl = tree.DigToFirstNodeOfType(); - - var actualRegions = GetRegions(namespaceDecl).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(11, 37), - TextSpan.FromBounds(0, 37), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(18, 34), - "// Foo ...", - autoCollapse: true); - - AssertRegion(expectedRegion2, actualRegions[1]); + const string code = @" +class C +{ + {|hint1:$$namespace N{|collapse1: + { + {|span2:// Foo + // Bar|} + }|}|} +}"; + + Regions(code, + Region("collapse1", "hint1", CSharpOutliningHelpers.Ellipsis, autoCollapse: false), + Region("span2", "// Foo ...", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/OperatorDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/OperatorDeclarationOutlinerTests.cs index b598e669b5a..32c84c0b1ff 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/OperatorDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/OperatorDeclarationOutlinerTests.cs @@ -1,83 +1,51 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class OperatorDeclarationOutlinerTests : - AbstractOutlinerTests + public class OperatorDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(OperatorDeclarationSyntax operatorDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new OperatorDeclarationOutliner(); - return outliner.GetOutliningSpans(operatorDecl, CancellationToken.None).WhereNotNull(); + return new OperatorDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestOperator() { - var tree = ParseLines("class C", - "{", - " public static int operator ++(int i)", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(operatorDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(50, 60), - TextSpan.FromBounds(14, 60), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public static int operator +(int i){|collapse: + { + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } - [WpfFact, - Trait(Traits.Feature, Traits.Features.Outlining)] + [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestOperatorWithLeadingComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " public static int operator ++(int i)", - " {", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var operatorDecl = typeDecl.DigToFirstNodeOfType(); - - 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(70, 80), - TextSpan.FromBounds(34, 80), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$public static int operator +(int i){|collapse2: + { + }|}|} +}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/ParenthesizedLambdaOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/ParenthesizedLambdaOutlinerTests.cs index 74453d13fc0..12200c46aa9 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/ParenthesizedLambdaOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/ParenthesizedLambdaOutlinerTests.cs @@ -1,117 +1,87 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class ParenthesizedLambdaOutlinerTests : - AbstractOutlinerTests + public class ParenthesizedLambdaOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(ParenthesizedLambdaExpressionSyntax lambdaExpression) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new ParenthesizedLambdaExpressionOutliner(); - return outliner.GetOutliningSpans(lambdaExpression, CancellationToken.None).WhereNotNull(); + return new ParenthesizedLambdaExpressionOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestLambda() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " () => {", - " x();", - " };", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(42, 63), - TextSpan.FromBounds(36, 63), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void M() + { + {|hint:$$() => {|collapse:{ + x(); + };|}|} + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestLambdaInForLoop() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " for (Action a = () => { }; true; a()) { }", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegions = GetRegions(lambdaExpression).ToList(); + const string code = @" +class C +{ + void M() + { + for (Action a = $$() => { }; true; a()) { } + } +}"; - Assert.Equal(0, actualRegions.Count); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestLambdaInMethodCall1() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " someMethod(42, \"test\", false, (x, y, z) => {", - " return x + y + z;", - " }, \"other arguments\");", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(79, 114), - TextSpan.FromBounds(66, 114), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void M() + { + someMethod(42, ""test"", false, {|hint:$$(x, y, z) => {|collapse:{ + return x + y + z; + }|}|}, ""other arguments""); + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestLambdaInMethodCall2() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " someMethod(42, \"test\", false, (x, y, z) => {", - " return x + y + z;", - " });", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(79, 114), - TextSpan.FromBounds(66, 114), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void M() + { + someMethod(42, ""test"", false, {|hint:$$(x, y, z) => {|collapse:{ + return x + y + z; + }|}|}); + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/PropertyDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/PropertyDeclarationOutlinerTests.cs index 91c57b0b486..55996c0053d 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/PropertyDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/PropertyDeclarationOutlinerTests.cs @@ -1,134 +1,87 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class PropertyDeclarationOutlinerTests : - AbstractOutlinerTests + public class PropertyDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(PropertyDeclarationSyntax propDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new PropertyDeclarationOutliner(); - return outliner.GetOutliningSpans(propDecl, CancellationToken.None).WhereNotNull(); + return new PropertyDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestProperty() { - var tree = ParseLines("class C", - "{", - " public int Foo", - " {", - " get { }", - " set { }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(propDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(28, 64), - TextSpan.FromBounds(14, 64), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public int Foo{|collapse: + { + get { } + set { } + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyWithLeadingComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " public int Foo", - " {", - " get { }", - " set { }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegions = GetRegions(propDecl).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(48, 84), - TextSpan.FromBounds(34, 84), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); - - AssertRegion(expectedRegion2, actualRegions[1]); + const string code = @" +class C +{ + {|span1:// Foo + // Bar|} + {|hint2:$$public int Foo{|collapse2: + { + get { } + set { } + }|}|} +}"; + + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyWithWithExpressionBodyAndComments() { - var tree = ParseLines("class C", - "{", - " // Foo", - " // Bar", - " public int Foo => 0;", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(propDecl); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(14, 30), - "// Foo ...", - autoCollapse: true); + const string code = @" +class C +{ + {|span:// Foo + // Bar|} + $$public int Foo => 0; +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("span", "// Foo ...", autoCollapse: true)); } [Fact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestPropertyWithSpaceAfterIdentifier() { - var tree = ParseLines("class C", - "{", - " public int Foo ", - " {", - " get { }", - " set { }", - " }", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - var propDecl = typeDecl.DigToFirstNodeOfType(); - - var actualRegion = GetRegion(propDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(32, 68), - TextSpan.FromBounds(14, 68), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: true); + const string code = @" +class C +{ + {|hint:$$public int Foo {|collapse: + { + get { } + set { } + }|}|} +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/RegionDirectiveOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/RegionDirectiveOutlinerTests.cs index 504e1619b83..5fc63f438b0 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/RegionDirectiveOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/RegionDirectiveOutlinerTests.cs @@ -1,9 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; @@ -12,98 +8,103 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class RegionDirectiveOutlinerTests : - AbstractOutlinerTests + public class RegionDirectiveOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(RegionDirectiveTriviaSyntax regionDirective) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new RegionDirectiveOutliner(); - return outliner.GetOutliningSpans(regionDirective, CancellationToken.None); - } - - private void TestRegion(string expectedRegionName, string code) - { - TestTrivia(expectedRegionName, code, SyntaxKind.RegionDirectiveTrivia, autoCollapse: true); + return new RegionDirectiveOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void BrokenRegion() { - TestRegion(null, "$$#region Foo"); + const string code = @" +$$#region Foo"; + + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void SimpleRegion() { - TestRegion("Foo", @"$$[|#region Foo -#endregion|]"); + const string code = @" +{|span:$$#region Foo +#endregion|}"; + + Regions(code, + Region("span", "Foo", autoCollapse: true, isDefaultCollapsed: true)); } - [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] [WorkItem(539361)] + [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void RegressionFor5284() { - TestRegion("TaoRegion", @"namespace BasicGenerateFromUsage + const string code = @" +namespace BasicGenerateFromUsage { - class BasicGenerateFromUsage { - [|#reg$$ion TaoRegion - + {|span:#reg$$ion TaoRegion + static void Main(string[] args) { /*Marker1*/ CustomStack s = new CustomStack(); //Generate new class - + //Generate constructor Classic cc = new Classic(5, 6, 7);/*Marker2*/ - + Classic cc = new Classic(); //generate property cc.NewProperty = 5; /*Marker3*/ - + } - #endregion TaoRegion|] + #endregion TaoRegion|} } - + class Classic { } -} +}"; -"); + Regions(code, + Region("span", "TaoRegion", autoCollapse: true, isDefaultCollapsed: true)); } - [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] [WorkItem(953668)] + [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void RegionsShouldBeCollapsedByDefault() { - TestRegion("Region", @" + const string code = @" class C { - [|#region R$$egion + {|span:#region Re$$gion static void Main(string[] args) { } - #endregion|] -} -"); + #endregion|} +}"; + + Regions(code, + Region("span", "Region", autoCollapse: true, isDefaultCollapsed: true)); } - [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] [WorkItem(4105, "https://github.com/dotnet/roslyn/issues/4105")] + [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void SpacesBetweenPoundAndRegionShouldNotAffectBanner() { - TestRegion("Region", @" + const string code = @" class C { -[|# region R$$egion +{|span:# region R$$egion static void Main(string[] args) { } -# endregion|] -} -"); +# endregion|} +}"; + + Regions(code, + Region("span", "Region", autoCollapse: true, isDefaultCollapsed: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/SimpleLambdaExpressionOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/SimpleLambdaExpressionOutlinerTests.cs index beb43e7d11d..45e9756e089 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/SimpleLambdaExpressionOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/SimpleLambdaExpressionOutlinerTests.cs @@ -1,117 +1,87 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class SimpleLambdaExpressionOutlinerTests : - AbstractOutlinerTests + public class SimpleLambdaExpressionOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(SimpleLambdaExpressionSyntax lambdaExpression) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new SimpleLambdaExpressionOutliner(); - return outliner.GetOutliningSpans(lambdaExpression, CancellationToken.None).WhereNotNull(); + return new SimpleLambdaExpressionOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestLambda() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " f => {", - " x();", - " };", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(41, 62), - TextSpan.FromBounds(36, 62), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void M() + { + {|hint:$$f => {|collapse:{ + x(); + };|}|} + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestLambdaInForLoop() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " for (Action a = x => { }; true; a()) { }", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegions = GetRegions(lambdaExpression).ToList(); + const string code = @" +class C +{ + void M() + { + for (Action a = x$$ => { }; true; a()) { } + } +}"; - Assert.Equal(0, actualRegions.Count); + NoRegions(code); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestLambdaInMethodCall1() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " someMethod(42, \"test\", false, x => {", - " return x;", - " }, \"other arguments\");", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(71, 98), - TextSpan.FromBounds(66, 98), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void M() + { + someMethod(42, ""test"", false, {|hint:$$x => {|collapse:{ + return x; + }|}|}, ""other arguments}""); + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestLambdaInMethodCall2() { - var tree = ParseLines("class C", - "{", - " void Main()", - " {", - " someMethod(42, \"test\", false, x => {", - " return x;", - " });", - " }", - "}"); - - var lambdaExpression = tree.GetRoot().FindFirstNodeOfType(); - var actualRegion = GetRegion(lambdaExpression); - - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(71, 98), - TextSpan.FromBounds(66, 98), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +class C +{ + void M() + { + someMethod(42, ""test"", false, {|hint:$$x => {|collapse:{ + return x; + }|}|}); + } +}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/TypeDeclarationOutlinerTests.cs b/src/EditorFeatures/CSharpTest/Outlining/TypeDeclarationOutlinerTests.cs index 3da3aa0dd1d..d94b8eae375 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/TypeDeclarationOutlinerTests.cs +++ b/src/EditorFeatures/CSharpTest/Outlining/TypeDeclarationOutlinerTests.cs @@ -1,262 +1,144 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editor.CSharp.Outlining; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining { - public class TypeDeclarationOutlinerTests : - AbstractOutlinerTests + public class TypeDeclarationOutlinerTests : AbstractOutlinerTests { - internal override IEnumerable GetRegions(TypeDeclarationSyntax typeDecl) + internal override AbstractSyntaxNodeOutliner CreateOutliner() { - var outliner = new TypeDeclarationOutliner(); - return outliner.GetOutliningSpans(typeDecl, CancellationToken.None).WhereNotNull(); + return new TypeDeclarationOutliner(); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestClass() { - var tree = ParseLines("class C", - "{", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegion = GetRegion(typeDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(7, 13), - TextSpan.FromBounds(0, 13), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +{|hint:$$class C{|collapse: +{ +}|}|}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestClassWithLeadingComments() { - var tree = ParseLines("// Foo", - "// Bar", - "class C", - "{", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegions = GetRegions(typeDecl).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, 29), - TextSpan.FromBounds(16, 29), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +{|span1:// Foo +// Bar|} +{|hint2:$$class C{|collapse2: +{ +}|}|}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] 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); + const string code = @" +{|hint1:$$class C{|collapse1: +{ + {|span2:// Foo + // Bar|} +}|}|}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("collapse1", "hint1", CSharpOutliningHelpers.Ellipsis, autoCollapse: false), + Region("span2", "// Foo ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestInterface() { - var tree = ParseLines("interface I", - "{", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegion = GetRegion(typeDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(11, 17), - TextSpan.FromBounds(0, 17), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +{|hint:$$interface I{|collapse: +{ +}|}|}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestInterfaceWithLeadingComments() { - var tree = ParseLines("// Foo", - "// Bar", - "interface I", - "{", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegions = GetRegions(typeDecl).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); + const string code = @" +{|span1:// Foo +// Bar|} +{|hint2:$$interface I{|collapse2: +{ +}|}|}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestInterfaceWithNestedComments() { - var tree = ParseLines("interface I", - "{", - " // Foo", - " // Bar", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegions = GetRegions(typeDecl).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(11, 37), - TextSpan.FromBounds(0, 37), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(18, 34), - "// Foo ...", - autoCollapse: true); + const string code = @" +{|hint1:$$interface I{|collapse1: +{ + {|span2:// Foo + // Bar|} +}|}|}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("collapse1", "hint1", CSharpOutliningHelpers.Ellipsis, autoCollapse: false), + Region("span2", "// Foo ...", autoCollapse: true)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestStruct() { - var tree = ParseLines("struct S", - "{", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegion = GetRegion(typeDecl); - var expectedRegion = new OutliningSpan( - TextSpan.FromBounds(8, 14), - TextSpan.FromBounds(0, 14), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +{|hint:$$struct S{|collapse: +{ +}|}|}"; - AssertRegion(expectedRegion, actualRegion); + Regions(code, + Region("collapse", "hint", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestStructWithLeadingComments() { - var tree = ParseLines("// Foo", - "// Bar", - "struct S", - "{", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegions = GetRegions(typeDecl).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(24, 30), - TextSpan.FromBounds(16, 30), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); + const string code = @" +{|span1:// Foo +// Bar|} +{|hint2:$$struct S{|collapse2: +{ +}|}|}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("span1", "// Foo ...", autoCollapse: true), + Region("collapse2", "hint2", CSharpOutliningHelpers.Ellipsis, autoCollapse: false)); } [WpfFact, Trait(Traits.Feature, Traits.Features.Outlining)] public void TestStructWithNestedComments() { - var tree = ParseLines("struct S", - "{", - " // Foo", - " // Bar", - "}"); - - var typeDecl = tree.DigToFirstTypeDeclaration(); - - var actualRegions = GetRegions(typeDecl).ToList(); - Assert.Equal(2, actualRegions.Count); - - var expectedRegion1 = new OutliningSpan( - TextSpan.FromBounds(8, 34), - TextSpan.FromBounds(0, 34), - CSharpOutliningHelpers.Ellipsis, - autoCollapse: false); - - AssertRegion(expectedRegion1, actualRegions[0]); - - var expectedRegion2 = new OutliningSpan( - TextSpan.FromBounds(15, 31), - "// Foo ...", - autoCollapse: true); + const string code = @" +{|hint1:$$struct S{|collapse1: +{ + {|span2:// Foo + // Bar|} +}|}|}"; - AssertRegion(expectedRegion2, actualRegions[1]); + Regions(code, + Region("collapse1", "hint1", CSharpOutliningHelpers.Ellipsis, autoCollapse: false), + Region("span2", "// Foo ...", autoCollapse: true)); } } } diff --git a/src/EditorFeatures/CSharpTest/Outlining/Utils.cs b/src/EditorFeatures/CSharpTest/Outlining/Utils.cs new file mode 100644 index 00000000000..e154011c1a1 --- /dev/null +++ b/src/EditorFeatures/CSharpTest/Outlining/Utils.cs @@ -0,0 +1,24 @@ +using System; +using Microsoft.CodeAnalysis.CSharp; + +namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining +{ + internal static class Utils + { + public static SyntaxTree ParseCode(string code) + { + return SyntaxFactory.ParseSyntaxTree(code); + } + + public static string StringFromLines(params string[] lines) + { + return string.Join(Environment.NewLine, lines); + } + + public static SyntaxTree ParseLines(params string[] lines) + { + var code = StringFromLines(lines); + return ParseCode(code); + } + } +} diff --git a/src/EditorFeatures/Test/EditorServicesTest.csproj b/src/EditorFeatures/Test/EditorServicesTest.csproj index ba41fd2208e..3d5a928a237 100644 --- a/src/EditorFeatures/Test/EditorServicesTest.csproj +++ b/src/EditorFeatures/Test/EditorServicesTest.csproj @@ -251,6 +251,7 @@ + diff --git a/src/EditorFeatures/CSharpTest/Outlining/AbstractOutlinerTests.cs b/src/EditorFeatures/Test/Outlining/AbstractOutlinerTests.cs similarity index 53% rename from src/EditorFeatures/CSharpTest/Outlining/AbstractOutlinerTests.cs rename to src/EditorFeatures/Test/Outlining/AbstractOutlinerTests.cs index 98fd4a5976b..fcf9e1be0f2 100644 --- a/src/EditorFeatures/CSharpTest/Outlining/AbstractOutlinerTests.cs +++ b/src/EditorFeatures/Test/Outlining/AbstractOutlinerTests.cs @@ -1,15 +1,13 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Editor.Implementation.Outlining; using Xunit; -namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Outlining +namespace Microsoft.CodeAnalysis.Editor.UnitTests.Outlining { public abstract class AbstractOutlinerTests { - internal void AssertRegion(OutliningSpan expected, OutliningSpan actual) + internal static void AssertRegion(OutliningSpan expected, OutliningSpan actual) { Assert.Equal(expected.TextSpan.Start, actual.TextSpan.Start); Assert.Equal(expected.TextSpan.End, actual.TextSpan.End); @@ -17,22 +15,7 @@ internal void AssertRegion(OutliningSpan expected, OutliningSpan actual) Assert.Equal(expected.HintSpan.End, actual.HintSpan.End); Assert.Equal(expected.BannerText, actual.BannerText); Assert.Equal(expected.AutoCollapse, actual.AutoCollapse); - } - - protected SyntaxTree ParseCode(string code) - { - return SyntaxFactory.ParseSyntaxTree(code); - } - - protected string StringFromLines(params string[] lines) - { - return string.Join(Environment.NewLine, lines); - } - - protected SyntaxTree ParseLines(params string[] lines) - { - var code = StringFromLines(lines); - return ParseCode(code); + Assert.Equal(expected.IsDefaultCollapsed, actual.IsDefaultCollapsed); } } } diff --git a/src/EditorFeatures/VisualBasicTest/BasicEditorServicesTest.vbproj b/src/EditorFeatures/VisualBasicTest/BasicEditorServicesTest.vbproj index 28f4cf57406..e562d718797 100644 --- a/src/EditorFeatures/VisualBasicTest/BasicEditorServicesTest.vbproj +++ b/src/EditorFeatures/VisualBasicTest/BasicEditorServicesTest.vbproj @@ -313,7 +313,6 @@ - diff --git a/src/EditorFeatures/VisualBasicTest/Outlining/AbstractOutlinerTests.vb b/src/EditorFeatures/VisualBasicTest/Outlining/AbstractOutlinerTests.vb deleted file mode 100644 index f4e64e369e2..00000000000 --- a/src/EditorFeatures/VisualBasicTest/Outlining/AbstractOutlinerTests.vb +++ /dev/null @@ -1,17 +0,0 @@ -' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -Imports Microsoft.CodeAnalysis.Editor.Implementation.Outlining - -Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining - Public MustInherit Class AbstractOutlinerTests - Friend Sub AssertRegion(expected As OutliningSpan, actual As OutliningSpan) - 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) - Assert.Equal(expected.IsDefaultCollapsed, actual.IsDefaultCollapsed) - End Sub - End Class -End Namespace diff --git a/src/EditorFeatures/VisualBasicTest/Outlining/AbstractOutlinerTests`1.vb b/src/EditorFeatures/VisualBasicTest/Outlining/AbstractOutlinerTests`1.vb index f4c05f5735f..99201e5c4a9 100644 --- a/src/EditorFeatures/VisualBasicTest/Outlining/AbstractOutlinerTests`1.vb +++ b/src/EditorFeatures/VisualBasicTest/Outlining/AbstractOutlinerTests`1.vb @@ -2,6 +2,7 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Microsoft.CodeAnalysis.Editor.Implementation.Outlining +Imports Microsoft.CodeAnalysis.Editor.UnitTests.Outlining Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining Public MustInherit Class AbstractOutlinerTests(Of T As SyntaxNode) diff --git a/src/EditorFeatures/VisualBasicTest/Outlining/CommentTests.vb b/src/EditorFeatures/VisualBasicTest/Outlining/CommentTests.vb index df051b05d30..133e86c9530 100644 --- a/src/EditorFeatures/VisualBasicTest/Outlining/CommentTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Outlining/CommentTests.vb @@ -1,11 +1,9 @@ ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.Editor.Implementation.Outlining +Imports Microsoft.CodeAnalysis.Editor.UnitTests.Outlining Imports Microsoft.CodeAnalysis.Editor.VisualBasic.Outlining -Imports Microsoft.CodeAnalysis.Editor.VisualBasic.Utilities Imports Microsoft.CodeAnalysis.Text -Imports Roslyn.Test.Utilities Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining Public Class CommentTests diff --git a/src/EditorFeatures/VisualBasicTest/Outlining/DisabledCodeOutlinerTests.vb b/src/EditorFeatures/VisualBasicTest/Outlining/DisabledCodeOutlinerTests.vb index 3d6e8a0c643..c8c9e4a3161 100644 --- a/src/EditorFeatures/VisualBasicTest/Outlining/DisabledCodeOutlinerTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Outlining/DisabledCodeOutlinerTests.vb @@ -1,15 +1,11 @@ ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports System.Threading -Imports Microsoft.CodeAnalysis Imports Microsoft.CodeAnalysis.Editor.Implementation.Outlining +Imports Microsoft.CodeAnalysis.Editor.UnitTests.Outlining Imports Microsoft.CodeAnalysis.Editor.VisualBasic.Outlining -Imports Microsoft.CodeAnalysis.Shared.Collections Imports Microsoft.CodeAnalysis.Text -Imports Microsoft.CodeAnalysis.VisualBasic -Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Microsoft.CodeAnalysis.VisualBasic.Syntax -Imports Roslyn.Test.Utilities Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining Public Class DisabledCodeOutlinerTests diff --git a/src/EditorFeatures/VisualBasicTest/Outlining/MetadataAsSource/InvalidIdentifierTests.vb b/src/EditorFeatures/VisualBasicTest/Outlining/MetadataAsSource/InvalidIdentifierTests.vb index ab2de930fda..5ad4b96bc55 100644 --- a/src/EditorFeatures/VisualBasicTest/Outlining/MetadataAsSource/InvalidIdentifierTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Outlining/MetadataAsSource/InvalidIdentifierTests.vb @@ -2,6 +2,7 @@ Imports System.Threading Imports Microsoft.CodeAnalysis.Editor.Implementation.Outlining +Imports Microsoft.CodeAnalysis.Editor.UnitTests.Outlining Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining.MetadataAsSource diff --git a/src/EditorFeatures/VisualBasicTest/Outlining/OverallOutliningTests.vb b/src/EditorFeatures/VisualBasicTest/Outlining/OverallOutliningTests.vb index e8656745943..a0f2ae36be6 100644 --- a/src/EditorFeatures/VisualBasicTest/Outlining/OverallOutliningTests.vb +++ b/src/EditorFeatures/VisualBasicTest/Outlining/OverallOutliningTests.vb @@ -2,8 +2,8 @@ Imports System.Threading Imports Microsoft.CodeAnalysis.Editor.Implementation.Outlining +Imports Microsoft.CodeAnalysis.Editor.UnitTests.Outlining Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces -Imports Microsoft.CodeAnalysis.LanguageServices Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining Public Class OverallOutliningTests -- GitLab