From 39ae842a1ce78f95558d6913bf2430399f74a5bf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 15 Aug 2023 19:25:13 -0700 Subject: [PATCH 1/4] Add test --- .../Formatting/FormattingEngineTests.cs | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs index 950f417161b31..113cbf26d3c0c 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs @@ -2588,11 +2588,41 @@ class C [WpfFact] public void FormatCollectionExpressionAfterEquals() { - var code = @"$$ -var v = [ 1 , 2 , 3 ] ;"; + var code = """ + $$ + var v = [ 1 , 2 , 3 ] ; + """; - var expected = @"$$ -var v = [1, 2, 3];"; + var expected = """ + $$ + var v = [1, 2, 3]; + """; + + AssertFormatWithView(expected, code); + } + + [WpfFact] + public void FormatCollectionExpressionAfterEquals2() + { + var code = """ + class C + { + void M() + { + List list = [ ] ;$$ + } + } + """; + + var expected = """ + class C + { + void M() + { + List list = [];$$ + } + } + """; AssertFormatWithView(expected, code); } From 2d9cf9badf91ce216383623ed76237d54e1650b5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 15 Aug 2023 19:31:22 -0700 Subject: [PATCH 2/4] Make attributes consistent --- .../Formatting/FormattingEngineTests.cs | 137 +++++++----------- 1 file changed, 54 insertions(+), 83 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs index 113cbf26d3c0c..574704ea3aaec 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs @@ -201,8 +201,7 @@ static void Main(string[] args) AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true, isPaste: false); } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/977133")] - [WpfFact] + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/977133")] public void DoNotFormatRangeOrFormatTokenOnOpenBraceOnSameLine() { var code = @"class C @@ -222,8 +221,7 @@ public void M() AssertFormatAfterTypeChar(code, expected); } - [WorkItem("https://github.com/dotnet/roslyn/pull/14491")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/pull/14491")] public void DoNotFormatRangeButFormatTokenOnOpenBraceOnNextLine() { var code = @"class C @@ -245,8 +243,7 @@ public void M() AssertFormatAfterTypeChar(code, expected); } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1007071")] - [WpfFact] + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1007071")] public void FormatPragmaWarningInbetweenDelegateDeclarationStatement() { var code = @"using System; @@ -278,8 +275,7 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] - [WpfFact] + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] public void FormatHashRegion() { var code = @"using System; @@ -303,8 +299,7 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] - [WpfFact] + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] public void FormatHashEndRegion() { var code = @"using System; @@ -330,8 +325,7 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/987373")] - [WpfFact] + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/987373")] public async Task FormatSpansIndividuallyWithoutCollapsing() { var code = @"class C @@ -423,8 +417,7 @@ public void M() Assert.Equal(expected, node.ToFullString()); } - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1044118")] - [WpfFact] + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1044118")] public void SemicolonInCommentOnLastLineDoesNotFormat() { var code = @"using System; @@ -449,9 +442,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideSingleLineRegularComment_1() { var code = @"class Program @@ -474,9 +467,9 @@ static void Main(int a, int b) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideSingleLineRegularComment_2() { var code = @"class Program @@ -499,9 +492,9 @@ static void Main(int a, int b) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideMultiLineRegularComment_1() { var code = @"class Program @@ -522,9 +515,9 @@ static void Main(int a/* { */, int b) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideMultiLineRegularComment_2() { var code = @"class Program @@ -547,9 +540,9 @@ static void Main(int a/* { AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideMultiLineRegularComment_3() { var code = @"class Program @@ -572,9 +565,9 @@ static void Main(int a/* { AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideSingleLineDocComment_1() { var code = @"class Program @@ -597,9 +590,9 @@ static void Main(int a, int b) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideSingleLineDocComment_2() { var code = @"class Program @@ -622,9 +615,9 @@ static void Main(int a, int b) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideMultiLineDocComment_1() { var code = @"class Program @@ -647,9 +640,9 @@ static void Main(int a, int b) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideMultiLineDocComment_2() { var code = @"class Program @@ -674,9 +667,9 @@ static void Main(int a, int b) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideMultiLineDocComment_3() { var code = @"class Program @@ -701,9 +694,9 @@ static void Main(int a, int b) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideInactiveCode() { var code = @"class Program @@ -732,9 +725,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideStringLiteral() { var code = @"class Program @@ -755,9 +748,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideCharLiteral() { var code = @"class Program @@ -778,9 +771,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/449")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - [WpfFact] public void NoFormattingInsideCommentsOfPreprocessorDirectives() { var code = @"class Program @@ -805,9 +798,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void ColonInSwitchCase() { var code = @"class Program @@ -836,9 +829,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void ColonInDefaultSwitchCase() { var code = @"class Program @@ -869,8 +862,7 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } - [WorkItem("https://github.com/dotnet/roslyn/issues/9097")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/9097")] public void ColonInPatternSwitchCase01() { var code = @"class Program @@ -897,9 +889,9 @@ static void Main() AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void ColonInLabeledStatement() { var code = @"class Program @@ -920,9 +912,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void DoNotFormatColonInTargetAttribute() { var code = @"using System; @@ -939,9 +931,9 @@ class C : Attribute AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void DoNotFormatColonInBaseList() { var code = @"class C :$$ Attribute @@ -954,9 +946,9 @@ public void DoNotFormatColonInBaseList() AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void DoNotFormatColonInThisConstructor() { var code = @"class Goo @@ -983,9 +975,9 @@ public void DoNotFormatColonInThisConstructor() AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void DoNotFormatColonInConditionalOperator() { var code = @"class Program @@ -1006,9 +998,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void DoNotFormatColonInArgument() { var code = @"class Program @@ -1029,9 +1021,9 @@ static void Main(string[] args) AssertFormatAfterTypeChar(code, expected); } + [WpfFact] [WorkItem("https://github.com/dotnet/roslyn/issues/464")] [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - [WpfFact] public void DoNotFormatColonInTypeParameter() { var code = @"class Program @@ -1054,8 +1046,7 @@ class C1 AssertFormatAfterTypeChar(code, expected); } - [WorkItem("https://github.com/dotnet/roslyn/issues/2224")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/2224")] public void DoNotSmartFormatBracesOnSmartIndentNone() { var code = @"class Program @@ -1140,8 +1131,8 @@ class C AssertFormatAfterTypeChar(code, expected, globalOptions); } - [WorkItem("https://github.com/dotnet/roslyn/issues/5873")] [WpfFact, Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + [WorkItem("https://github.com/dotnet/roslyn/issues/5873")] public void KeepTabsInCommentsWhenFormattingIsOff() { // There are tabs in this test case. Tools that touch the Roslyn repo should @@ -1172,8 +1163,8 @@ static void Main() AssertFormatAfterTypeChar(code, expected, globalOptions); } - [WorkItem("https://github.com/dotnet/roslyn/issues/5873")] [WpfFact, Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + [WorkItem("https://github.com/dotnet/roslyn/issues/5873")] public void DoNotKeepTabsInCommentsWhenFormattingIsOn() { // There are tabs in this test case. Tools that touch the Roslyn repo should @@ -1522,8 +1513,7 @@ void M() AssertFormatAfterTypeChar(code, expected); } - [WorkItem("https://github.com/dotnet/roslyn/issues/7900")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/7900")] public void FormatLockStatementWithEmbeddedStatementOnSemicolonDifferentLine() { var code = @"class C @@ -1547,8 +1537,7 @@ public void M() AssertFormatAfterTypeChar(code, expected); } - [WorkItem("https://github.com/dotnet/roslyn/issues/7900")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/7900")] public void FormatLockStatementWithEmbeddedStatementOnSemicolonSameLine() { var code = @"class C @@ -1570,8 +1559,7 @@ public void M() AssertFormatAfterTypeChar(code, expected); } - [WorkItem("https://github.com/dotnet/roslyn/issues/11642")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/11642")] public void FormatArbitraryNodeParenthesizedLambdaExpression() { // code equivalent to an expression synthesized like so: @@ -1695,8 +1683,7 @@ public async Task FormatAttributeAtEndOfFile(bool trailingNewLine) await AssertFormatAsync(expected, expected, spans: null); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff1() { var code = @@ -1722,8 +1709,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff2() { var code = @@ -1749,8 +1735,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff3() { // We only smart indent the { if it's on it's own line. @@ -1775,8 +1760,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff4() { // We only smart indent the { if it's on it's own line. @@ -1801,8 +1785,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff5() { // Typing the { should not affect the formating of the preceding tokens. @@ -1829,8 +1812,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff6() { // Typing the { should not affect the formating of the preceding tokens. @@ -1855,8 +1837,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff7() { var code = @@ -1876,8 +1857,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff1() { var code = @@ -1905,8 +1885,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff2() { // Note that the { is not updated since we are not formatting. @@ -1933,8 +1912,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff3() { var code = @@ -1956,8 +1934,7 @@ void M() AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff4() { // Should not affect formatting of open brace @@ -2003,8 +1980,7 @@ void MyMethod() await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); } - [WorkItem("https://github.com/dotnet/roslyn/issues/30518")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30518")] public void FormatGeneratedNodeInInitializer() { var code = @"new bool[] { @@ -2149,8 +2125,7 @@ void M() await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); } - [WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_KeepMultipleLinesBetweenGroups() { var code = @"$$ @@ -2174,8 +2149,7 @@ public void SeparateGroups_KeepMultipleLinesBetweenGroups() AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } - [WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_KeepMultipleLinesBetweenGroups_FileScopedNamespace() { var code = @"$$ @@ -2203,8 +2177,7 @@ namespace N; AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } - [WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_DoNotGroupIfNotSorted() { var code = @"$$ @@ -2224,8 +2197,7 @@ public void SeparateGroups_DoNotGroupIfNotSorted() AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } - [WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_GroupIfSorted() { var code = @"$$ @@ -2246,8 +2218,7 @@ public void SeparateGroups_GroupIfSorted() AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } - [WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - [WpfFact] + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_GroupIfSorted_RecognizeSystemNotFirst() { var code = @"$$ From a90e9563d6128611546b46130a0146a26516bf68 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 16 Aug 2023 09:24:49 -0700 Subject: [PATCH 3/4] Use raw strings --- .../Formatting/FormattingEngineTests.cs | 3500 +++++++++-------- 1 file changed, 1909 insertions(+), 1591 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs index 574704ea3aaec..5dd0ebc0530a8 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs @@ -2,16 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Formatting; -using Microsoft.CodeAnalysis.CSharp.Shared.Extensions; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; @@ -19,11 +15,9 @@ using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; using Microsoft.CodeAnalysis.Formatting; using Microsoft.CodeAnalysis.Indentation; -using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Test.Utilities; -using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Editor.Commanding.Commands; -using Newtonsoft.Json.Linq; using Roslyn.Test.Utilities; using Xunit; using Xunit.Abstractions; @@ -36,37 +30,37 @@ public class FormattingEngineTests : CSharpFormattingEngineTestBase public FormattingEngineTests(ITestOutputHelper output) : base(output) { } private static OptionsCollection SmartIndentButDoNotFormatWhileTyping() - { - return new OptionsCollection(LanguageNames.CSharp) + => new(LanguageNames.CSharp) { { IndentationOptionsStorage.SmartIndent, FormattingOptions2.IndentStyle.Smart }, { AutoFormattingOptionsStorage.FormatOnTyping, false }, { AutoFormattingOptionsStorage.FormatOnCloseBrace, false }, }; - } [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539682")] public void FormatDocumentCommandHandler() { - var code = @"class Program -{ - static void Main(string[] args) - { - int x;$$ -int y; - } -} -"; + var code = """ + class Program + { + static void Main(string[] args) + { + int x;$$ + int y; + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - int x;$$ - int y; - } -} -"; + var expected = """ + class Program + { + static void Main(string[] args) + { + int x;$$ + int y; + } + } + """; AssertFormatWithView(expected, code); } @@ -74,25 +68,27 @@ static void Main(string[] args) [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539682")] public void FormatDocumentPasteCommandHandler() { - var code = @"class Program -{ - static void Main(string[] args) - { - int x;$$ -int y; - } -} -"; + var code = """ + class Program + { + static void Main(string[] args) + { + int x;$$ + int y; + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - int x;$$ - int y; - } -} -"; + var expected = """ + class Program + { + static void Main(string[] args) + { + int x;$$ + int y; + } + } + """; AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true); } @@ -100,25 +96,27 @@ static void Main(string[] args) [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/547261")] public void FormatDocumentReadOnlyWorkspacePasteCommandHandler() { - var code = @"class Program -{ - static void Main(string[] args) - { - int x;$$ -int y; - } -} -"; + var code = """ + class Program + { + static void Main(string[] args) + { + int x;$$ + int y; + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - int x;$$ -int y; - } -} -"; + var expected = """ + class Program + { + static void Main(string[] args) + { + int x;$$ + int y; + } + } + """; AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: false); } @@ -126,25 +124,27 @@ static void Main(string[] args) [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] public void DoNotFormatUsingStatementOnReturn() { - var code = @"class Program -{ - static void Main(string[] args) - { - using (null) - using (null)$$ - } -} -"; + var code = """ + class Program + { + static void Main(string[] args) + { + using (null) + using (null)$$ + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - using (null) - using (null)$$ - } -} -"; + var expected = """ + class Program + { + static void Main(string[] args) + { + using (null) + using (null)$$ + } + } + """; AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true, isPaste: false); } @@ -152,25 +152,27 @@ static void Main(string[] args) [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] public void FormatUsingStatementWhenTypingCloseParen() { - var code = @"class Program -{ - static void Main(string[] args) - { - using (null) - using (null)$$ - } -} -"; + var code = """ + class Program + { + static void Main(string[] args) + { + using (null) + using (null)$$ + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - using (null) - using (null) - } -} -"; + var expected = """ + class Program + { + static void Main(string[] args) + { + using (null) + using (null) + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -178,25 +180,27 @@ static void Main(string[] args) [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] public void FormatNotUsingStatementOnReturn() { - var code = @"class Program -{ - static void Main(string[] args) - { - using (null) - for (;;)$$ - } -} -"; + var code = """ + class Program + { + static void Main(string[] args) + { + using (null) + for (;;)$$ + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - using (null) - for (;;)$$ - } -} -"; + var expected = """ + class Program + { + static void Main(string[] args) + { + using (null) + for (;;)$$ + } + } + """; AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true, isPaste: false); } @@ -204,214 +208,238 @@ static void Main(string[] args) [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/977133")] public void DoNotFormatRangeOrFormatTokenOnOpenBraceOnSameLine() { - var code = @"class C -{ - public void M() - { - if (true) {$$ - } -}"; - var expected = @"class C -{ - public void M() - { - if (true) { - } -}"; + var code = """ + class C + { + public void M() + { + if (true) {$$ + } + } + """; + var expected = """ + class C + { + public void M() + { + if (true) { + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/pull/14491")] public void DoNotFormatRangeButFormatTokenOnOpenBraceOnNextLine() { - var code = @"class C -{ - public void M() - { - if (true) - {$$ - } -}"; - var expected = @"class C -{ - public void M() - { - if (true) - { - } -}"; + var code = """ + class C + { + public void M() + { + if (true) + {$$ + } + } + """; + var expected = """ + class C + { + public void M() + { + if (true) + { + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1007071")] public void FormatPragmaWarningInbetweenDelegateDeclarationStatement() { - var code = @"using System; + var code = """ + using System; -class Program -{ - static void Main(string[] args) - { - Func a = delegate () -#pragma warning disable CA0001 - { - return true; - };$$ - } -}"; - var expected = @"using System; + class Program + { + static void Main(string[] args) + { + Func a = delegate () + #pragma warning disable CA0001 + { + return true; + };$$ + } + } + """; + var expected = """ + using System; -class Program -{ - static void Main(string[] args) - { - Func a = delegate () -#pragma warning disable CA0001 - { - return true; - }; - } -}"; + class Program + { + static void Main(string[] args) + { + Func a = delegate () + #pragma warning disable CA0001 + { + return true; + }; + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] public void FormatHashRegion() { - var code = @"using System; + var code = """ + using System; -class Program -{ - static void Main(string[] args) - { -#region$$ - } -}"; - var expected = @"using System; + class Program + { + static void Main(string[] args) + { + #region$$ + } + } + """; + var expected = """ + using System; -class Program -{ - static void Main(string[] args) - { - #region - } -}"; + class Program + { + static void Main(string[] args) + { + #region + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] public void FormatHashEndRegion() { - var code = @"using System; + var code = """ + using System; -class Program -{ - static void Main(string[] args) - { - #region -#endregion$$ - } -}"; - var expected = @"using System; + class Program + { + static void Main(string[] args) + { + #region + #endregion$$ + } + } + """; + var expected = """ + using System; -class Program -{ - static void Main(string[] args) - { - #region - #endregion - } -}"; + class Program + { + static void Main(string[] args) + { + #region + #endregion + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/987373")] public async Task FormatSpansIndividuallyWithoutCollapsing() { - var code = @"class C -{ - public void M() - { - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - [|if(true){}|] - if(true){} - [|if(true){}|] - } -}"; - var expected = @"class C -{ - public void M() - { - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if (true) { } - if(true){} - if (true) { } - } -}"; + var code = """ + class C + { + public void M() + { + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + [|if(true){}|] + if(true){} + [|if(true){}|] + } + } + """; + var expected = """ + class C + { + public void M() + { + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if (true) { } + if(true){} + if (true) { } + } + } + """; using var workspace = TestWorkspace.CreateCSharp(code); var subjectDocument = workspace.Documents.Single(); var spans = subjectDocument.SelectedSpans; var document = workspace.CurrentSolution.Projects.Single().Documents.Single(); - var syntaxRoot = await document.GetSyntaxRootAsync(); + var syntaxRoot = await document.GetRequiredSyntaxRootAsync(CancellationToken.None); var options = CSharpSyntaxFormattingOptions.Default; var node = Formatter.Format(syntaxRoot, spans, workspace.Services.SolutionServices, options, rules: null, CancellationToken.None); Assert.Equal(expected, node.ToFullString()); @@ -420,25 +448,29 @@ public void M() [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1044118")] public void SemicolonInCommentOnLastLineDoesNotFormat() { - var code = @"using System; + var code = """ + using System; -class Program -{ - static void Main(string[] args) - { - } -} -// ;$$"; + class Program + { + static void Main(string[] args) + { + } + } + // ;$$ + """; - var expected = @"using System; + var expected = """ + using System; -class Program -{ - static void Main(string[] args) - { - } -} -// ;"; + class Program + { + static void Main(string[] args) + { + } + } + // ; + """; AssertFormatAfterTypeChar(code, expected); } @@ -447,23 +479,27 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideSingleLineRegularComment_1() { - var code = @"class Program -{ - // {$$ - static void Main(int a, int b) - { + var code = """ + class Program + { + // {$$ + static void Main(int a, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - // { - static void Main(int a, int b) - { + var expected = """ + class Program + { + // { + static void Main(int a, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -472,23 +508,27 @@ static void Main(int a, int b) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideSingleLineRegularComment_2() { - var code = @"class Program -{ - // {$$ - static void Main(int a, int b) - { + var code = """ + class Program + { + // {$$ + static void Main(int a, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - // { - static void Main(int a, int b) - { + var expected = """ + class Program + { + // { + static void Main(int a, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -497,21 +537,25 @@ static void Main(int a, int b) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideMultiLineRegularComment_1() { - var code = @"class Program -{ - static void Main(int a/* {$$ */, int b) - { + var code = """ + class Program + { + static void Main(int a/* {$$ */, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - static void Main(int a/* { */, int b) - { + var expected = """ + class Program + { + static void Main(int a/* { */, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -520,23 +564,27 @@ static void Main(int a/* { */, int b) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideMultiLineRegularComment_2() { - var code = @"class Program -{ - static void Main(int a/* {$$ - */, int b) - { + var code = """ + class Program + { + static void Main(int a/* {$$ + */, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - static void Main(int a/* { - */, int b) - { + var expected = """ + class Program + { + static void Main(int a/* { + */, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -545,23 +593,27 @@ static void Main(int a/* { [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideMultiLineRegularComment_3() { - var code = @"class Program -{ - static void Main(int a/* {$$ - */, int b) - { + var code = """ + class Program + { + static void Main(int a/* {$$ + */, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - static void Main(int a/* { - */, int b) - { + var expected = """ + class Program + { + static void Main(int a/* { + */, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -570,23 +622,27 @@ static void Main(int a/* { [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideSingleLineDocComment_1() { - var code = @"class Program -{ - /// {$$ - static void Main(int a, int b) - { + var code = """ + class Program + { + /// {$$ + static void Main(int a, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - /// { - static void Main(int a, int b) - { + var expected = """ + class Program + { + /// { + static void Main(int a, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -595,23 +651,27 @@ static void Main(int a, int b) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideSingleLineDocComment_2() { - var code = @"class Program -{ - /// {$$ - static void Main(int a, int b) - { + var code = """ + class Program + { + /// {$$ + static void Main(int a, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - /// { - static void Main(int a, int b) - { + var expected = """ + class Program + { + /// { + static void Main(int a, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -620,23 +680,27 @@ static void Main(int a, int b) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideMultiLineDocComment_1() { - var code = @"class Program -{ - /** {$$ **/ - static void Main(int a, int b) - { + var code = """ + class Program + { + /** {$$ **/ + static void Main(int a, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - /** { **/ - static void Main(int a, int b) - { + var expected = """ + class Program + { + /** { **/ + static void Main(int a, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -645,25 +709,29 @@ static void Main(int a, int b) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideMultiLineDocComment_2() { - var code = @"class Program -{ - /** {$$ - **/ - static void Main(int a, int b) - { + var code = """ + class Program + { + /** {$$ + **/ + static void Main(int a, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - /** { - **/ - static void Main(int a, int b) - { + var expected = """ + class Program + { + /** { + **/ + static void Main(int a, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -672,25 +740,29 @@ static void Main(int a, int b) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideMultiLineDocComment_3() { - var code = @"class Program -{ - /** {$$ - **/ - static void Main(int a, int b) - { + var code = """ + class Program + { + /** {$$ + **/ + static void Main(int a, int b) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - /** { - **/ - static void Main(int a, int b) - { + var expected = """ + class Program + { + /** { + **/ + static void Main(int a, int b) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -699,29 +771,33 @@ static void Main(int a, int b) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideInactiveCode() { - var code = @"class Program -{ - #if false - {$$ - #endif + var code = """ + class Program + { + #if false + {$$ + #endif - static void Main(string[] args) - { + static void Main(string[] args) + { - } -}"; + } + } + """; - var expected = @"class Program -{ - #if false - { - #endif + var expected = """ + class Program + { + #if false + { + #endif - static void Main(string[] args) - { + static void Main(string[] args) + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -730,21 +806,25 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideStringLiteral() { - var code = @"class Program -{ - static void Main(string[] args) - { - var asdas = ""{$$"" ; - } -}"; + var code = """ + class Program + { + static void Main(string[] args) + { + var asdas = "{$$" ; + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - var asdas = ""{"" ; - } -}"; + var expected = """ + class Program + { + static void Main(string[] args) + { + var asdas = "{" ; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -753,21 +833,25 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideCharLiteral() { - var code = @"class Program -{ - static void Main(string[] args) - { - var asdas = '{$$' ; - } -}"; + var code = """ + class Program + { + static void Main(string[] args) + { + var asdas = '{$$' ; + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - var asdas = '{' ; - } -}"; + var expected = """ + class Program + { + static void Main(string[] args) + { + var asdas = '{' ; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -776,25 +860,29 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] public void NoFormattingInsideCommentsOfPreprocessorDirectives() { - var code = @"class Program -{ - #region - #endregion // a/*{$$*/ - static void Main(string[] args) - { - - } -}"; + var code = """ + class Program + { + #region + #endregion // a/*{$$*/ + static void Main(string[] args) + { - var expected = @"class Program -{ - #region - #endregion // a/*{*/ - static void Main(string[] args) - { - - } -}"; + } + } + """; + + var expected = """ + class Program + { + #region + #endregion // a/*{*/ + static void Main(string[] args) + { + + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -803,29 +891,33 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void ColonInSwitchCase() { - var code = @"class Program -{ - static void Main(string[] args) - { - int f = 0; - switch(f) - { - case 1 :$$ break; - } - } -}"; + var code = """ + class Program + { + static void Main(string[] args) + { + int f = 0; + switch(f) + { + case 1 :$$ break; + } + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - int f = 0; - switch(f) - { - case 1: break; - } - } -}"; + var expected = """ + class Program + { + static void Main(string[] args) + { + int f = 0; + switch(f) + { + case 1: break; + } + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -834,58 +926,66 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void ColonInDefaultSwitchCase() { - var code = @"class Program -{ - static void Main(string[] args) - { - int f = 0; - switch(f) - { - case 1: break; - default :$$ break; - } - } -}"; + var code = """ + class Program + { + static void Main(string[] args) + { + int f = 0; + switch(f) + { + case 1: break; + default :$$ break; + } + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - int f = 0; - switch(f) - { - case 1: break; - default: break; - } - } -}"; + var expected = """ + class Program + { + static void Main(string[] args) + { + int f = 0; + switch(f) + { + case 1: break; + default: break; + } + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/9097")] public void ColonInPatternSwitchCase01() { - var code = @"class Program -{ - static void Main() - { - switch(f) - { - case int i :$$ break; - } - } -}"; + var code = """ + class Program + { + static void Main() + { + switch(f) + { + case int i :$$ break; + } + } + } + """; - var expected = @"class Program -{ - static void Main() - { - switch(f) - { - case int i: break; - } - } -}"; + var expected = """ + class Program + { + static void Main() + { + switch(f) + { + case int i: break; + } + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -894,21 +994,25 @@ static void Main() [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void ColonInLabeledStatement() { - var code = @"class Program -{ - static void Main(string[] args) - { - label1 :$$ int s = 0; - } -}"; + var code = """ + class Program + { + static void Main(string[] args) + { + label1 :$$ int s = 0; + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - label1: int s = 0; - } -}"; + var expected = """ + class Program + { + static void Main(string[] args) + { + label1: int s = 0; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -917,17 +1021,21 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void DoNotFormatColonInTargetAttribute() { - var code = @"using System; -[method :$$ C] -class C : Attribute -{ -}"; + var code = """ + using System; + [method :$$ C] + class C : Attribute + { + } + """; - var expected = @"using System; -[method : C] -class C : Attribute -{ -}"; + var expected = """ + using System; + [method : C] + class C : Attribute + { + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -936,13 +1044,17 @@ class C : Attribute [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void DoNotFormatColonInBaseList() { - var code = @"class C :$$ Attribute -{ -}"; + var code = """ + class C :$$ Attribute + { + } + """; - var expected = @"class C : Attribute -{ -}"; + var expected = """ + class C : Attribute + { + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -951,27 +1063,31 @@ public void DoNotFormatColonInBaseList() [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void DoNotFormatColonInThisConstructor() { - var code = @"class Goo -{ - Goo(int s) :$$ this() - { - } + var code = """ + class Goo + { + Goo(int s) :$$ this() + { + } - Goo() - { - } -}"; + Goo() + { + } + } + """; - var expected = @"class Goo -{ - Goo(int s) : this() - { - } + var expected = """ + class Goo + { + Goo(int s) : this() + { + } - Goo() - { - } -}"; + Goo() + { + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -980,21 +1096,25 @@ public void DoNotFormatColonInThisConstructor() [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void DoNotFormatColonInConditionalOperator() { - var code = @"class Program -{ - static void Main(string[] args) - { - var vari = goo() ? true :$$ false; - } -}"; + var code = """ + class Program + { + static void Main(string[] args) + { + var vari = goo() ? true :$$ false; + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - var vari = goo() ? true : false; - } -}"; + var expected = """ + class Program + { + static void Main(string[] args) + { + var vari = goo() ? true : false; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -1003,21 +1123,25 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void DoNotFormatColonInArgument() { - var code = @"class Program -{ - static void Main(string[] args) - { - Main(args :$$ args); - } -}"; + var code = """ + class Program + { + static void Main(string[] args) + { + Main(args :$$ args); + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - Main(args : args); - } -}"; + var expected = """ + class Program + { + static void Main(string[] args) + { + Main(args : args); + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -1026,40 +1150,48 @@ static void Main(string[] args) [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] public void DoNotFormatColonInTypeParameter() { - var code = @"class Program -{ - class C1 - where T :$$ U - { + var code = """ + class Program + { + class C1 + where T :$$ U + { - } -}"; + } + } + """; - var expected = @"class Program -{ - class C1 - where T : U - { + var expected = """ + class Program + { + class C1 + where T : U + { - } -}"; + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/2224")] public void DoNotSmartFormatBracesOnSmartIndentNone() { - var code = @"class Program -{ - class C1 -{$$ -}"; + var code = """ + class Program + { + class C1 + {$$ + } + """; - var expected = @"class Program -{ - class C1 -{ -}"; + var expected = """ + class Program + { + class C1 + { + } + """; var globalOptions = new OptionsCollection(LanguageNames.CSharp) { { IndentationOptionsStorage.SmartIndent, FormattingOptions2.IndentStyle.None } @@ -1071,25 +1203,27 @@ class C1 [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] public void StillAutoIndentCloseBraceWhenFormatOnCloseBraceIsOff() { - var code = @"namespace N -{ - class C - { - // improperly indented code - int x = 10; - }$$ -} -"; + var code = """ + namespace N + { + class C + { + // improperly indented code + int x = 10; + }$$ + } + """; - var expected = @"namespace N -{ - class C - { - // improperly indented code - int x = 10; - } -} -"; + var expected = """ + namespace N + { + class C + { + // improperly indented code + int x = 10; + } + } + """; var globalOptions = new OptionsCollection(LanguageNames.CSharp) { @@ -1103,25 +1237,27 @@ class C [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] public void AutoIndentCloseBraceWhenFormatOnTypingIsOff() { - var code = @"namespace N -{ - class C - { - // improperly indented code - int x = 10; - }$$ -} -"; + var code = """ + namespace N + { + class C + { + // improperly indented code + int x = 10; + }$$ + } + """; - var expected = @"namespace N -{ - class C - { - // improperly indented code - int x = 10; - } -} -"; + var expected = """ + namespace N + { + class C + { + // improperly indented code + int x = 10; + } + } + """; var globalOptions = new OptionsCollection(LanguageNames.CSharp) { @@ -1138,22 +1274,26 @@ public void KeepTabsInCommentsWhenFormattingIsOff() // There are tabs in this test case. Tools that touch the Roslyn repo should // not remove these as we are explicitly testing tab behavior. var code = -@"class Program -{ - static void Main() - { - return; /* Comment preceded by tabs */ // This one too - }$$ -}"; + """ + class Program + { + static void Main() + { + return; /* Comment preceded by tabs */ // This one too + }$$ + } + """; var expected = -@"class Program -{ - static void Main() - { - return; /* Comment preceded by tabs */ // This one too - } -}"; + """ + class Program + { + static void Main() + { + return; /* Comment preceded by tabs */ // This one too + } + } + """; var globalOptions = new OptionsCollection(LanguageNames.CSharp) { @@ -1169,22 +1309,26 @@ public void DoNotKeepTabsInCommentsWhenFormattingIsOn() { // There are tabs in this test case. Tools that touch the Roslyn repo should // not remove these as we are explicitly testing tab behavior. - var code = @"class Program -{ - static void Main() - { - return; /* Comment preceded by tabs */ // This one too - }$$ -}"; + var code = """ + class Program + { + static void Main() + { + return; /* Comment preceded by tabs */ // This one too + }$$ + } + """; var expected = -@"class Program -{ - static void Main() - { - return; /* Comment preceded by tabs */ // This one too - } -}"; + """ + class Program + { + static void Main() + { + return; /* Comment preceded by tabs */ // This one too + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -1194,24 +1338,26 @@ static void Main() public void DoNotFormatStatementIfSemicolonOptionIsOff() { var code = - @"namespace N -{ - class C - { - int x = 10 ;$$ - } -} -"; + """ + namespace N + { + class C + { + int x = 10 ;$$ + } + } + """; var expected = -@"namespace N -{ - class C - { - int x = 10 ; - } -} -"; + """ + namespace N + { + class C + { + int x = 10 ; + } + } + """; var globalOptions = new OptionsCollection(LanguageNames.CSharp) { @@ -1226,24 +1372,26 @@ class C public void DoNotFormatStatementIfTypingOptionIsOff() { var code = - @"namespace N -{ - class C - { - int x = 10 ;$$ - } -} -"; + """ + namespace N + { + class C + { + int x = 10 ;$$ + } + } + """; var expected = -@"namespace N -{ - class C - { - int x = 10 ; - } -} -"; + """ + namespace N + { + class C + { + int x = 10 ; + } + } + """; var globalOptions = new OptionsCollection(LanguageNames.CSharp) { @@ -1258,20 +1406,20 @@ class C public void OpenCurlyNotFormattedIfNotAtStartOfLine() { var code = -@" -class C -{ - public int P {$$ -} -"; + """ + class C + { + public int P {$$ + } + """; var expected = -@" -class C -{ - public int P { -} -"; + """ + class C + { + public int P { + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -1281,22 +1429,22 @@ public int P { public void OpenCurlyFormattedIfAtStartOfLine() { var code = -@" -class C -{ - public int P - {$$ -} -"; + """ + class C + { + public int P + {$$ + } + """; var expected = -@" -class C -{ - public int P - { -} -"; + """ + class C + { + public int P + { + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -1304,156 +1452,184 @@ public int P [WpfFact] public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly1() { - var code = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property - { - get { return true;$$ - } -}"; - var expected = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property - { - get { return true; - } -}"; + var code = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property + { + get { return true;$$ + } + } + """; + var expected = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property + { + get { return true; + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact] public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly2() { - var code = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property { get { return true;$$ - } -}"; - var expected = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property { get { return true; - } -}"; + var code = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property { get { return true;$$ + } + } + """; + var expected = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property { get { return true; + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact] public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly3() { - var code = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property { get;$$ - } -}"; - var expected = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property { get; - } -}"; + var code = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property { get;$$ + } + } + """; + var expected = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property { get; + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact] public void DoNotFormatCompleteBlockOnSingleLineIfTypingCloseCurly1() { - var code = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property - { - get { return true; }$$ -}"; - var expected = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property - { - get { return true; } -}"; + var code = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property + { + get { return true; }$$ + } + """; + var expected = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property + { + get { return true; } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact] public void DoNotFormatCompleteBlockOnSingleLineIfTypingCloseCurly2() { - var code = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property { get { return true; }$$ -}"; - var expected = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property { get { return true; } -}"; + var code = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property { get { return true; }$$ + } + """; + var expected = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property { get { return true; } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact] public void FormatIncompleteBlockOnMultipleLinesIfTypingCloseCurly1() { - var code = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property - { - get { return true; - }$$ -}"; - var expected = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property - { - get - { - return true; - } -}"; + var code = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property + { + get { return true; + }$$ + } + """; + var expected = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property + { + get + { + return true; + } + } + """; AssertFormatAfterTypeChar(code, expected); } - - [WpfFact] - public void FormatIncompleteBlockOnMultipleLinesIfTypingCloseCurly2() - { - var code = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property - { - get { return true; - } -}$$"; - var expected = @"namespace ConsoleApplication1 -{ - class Program - { - static bool Property + + [WpfFact] + public void FormatIncompleteBlockOnMultipleLinesIfTypingCloseCurly2() { - get - { - return true; - } - }"; + var code = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property + { + get { return true; + } + }$$ + """; + var expected = """ + namespace ConsoleApplication1 + { + class Program + { + static bool Property + { + get + { + return true; + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -1461,25 +1637,29 @@ static bool Property public void DoNotFormatCompleteBlockOnSingleLineIfTypingSemicolon() { var code = -@"public class Class1 -{ - void M() - { - try { } - catch { return;$$ - x.ToString(); - } -}"; + """ + public class Class1 + { + void M() + { + try { } + catch { return;$$ + x.ToString(); + } + } + """; var expected = -@"public class Class1 -{ - void M() - { - try { } - catch { return; - x.ToString(); - } -}"; + """ + public class Class1 + { + void M() + { + try { } + catch { return; + x.ToString(); + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -1487,75 +1667,87 @@ void M() public void FormatCompleteBlockOnSingleLineIfTypingCloseCurlyOnLaterLine() { var code = -@"public class Class1 -{ - void M() - { - try { } - catch { return; - x.ToString(); - }$$ - } -}"; + """ + public class Class1 + { + void M() + { + try { } + catch { return; + x.ToString(); + }$$ + } + } + """; var expected = -@"public class Class1 -{ - void M() - { - try { } - catch - { - return; - x.ToString(); - } - } -}"; + """ + public class Class1 + { + void M() + { + try { } + catch + { + return; + x.ToString(); + } + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/7900")] public void FormatLockStatementWithEmbeddedStatementOnSemicolonDifferentLine() { - var code = @"class C -{ - private object _l = new object(); - public void M() - { - lock (_l) - Console.WriteLine(""d"");$$ - } -}"; - var expected = @"class C -{ - private object _l = new object(); - public void M() - { - lock (_l) - Console.WriteLine(""d""); - } -}"; + var code = """ + class C + { + private object _l = new object(); + public void M() + { + lock (_l) + Console.WriteLine("d");$$ + } + } + """; + var expected = """ + class C + { + private object _l = new object(); + public void M() + { + lock (_l) + Console.WriteLine("d"); + } + } + """; AssertFormatAfterTypeChar(code, expected); } [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/7900")] public void FormatLockStatementWithEmbeddedStatementOnSemicolonSameLine() { - var code = @"class C -{ - private object _l = new object(); - public void M() - { - lock (_l) Console.WriteLine(""d"");$$ - } -}"; - var expected = @"class C -{ - private object _l = new object(); - public void M() - { - lock (_l) Console.WriteLine(""d""); - } -}"; + var code = """ + class C + { + private object _l = new object(); + public void M() + { + lock (_l) Console.WriteLine("d");$$ + } + } + """; + var expected = """ + class C + { + private object _l = new object(); + public void M() + { + lock (_l) Console.WriteLine("d"); + } + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -1573,48 +1765,50 @@ public void FormatArbitraryNodeParenthesizedLambdaExpression() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/57465")] public async Task FormatLambdaWithDirective() { - var code = @"namespace N -{ - public class C - { - protected void Render() - { - if (outer) - { - M(() => + var code = """ + namespace N + { + public class C + { + protected void Render() { -#nullable enable - if (inner) - { - } + if (outer) + { + M(() => + { + #nullable enable + if (inner) + { + } + } + ); } - ); + } + } } - } - } -} -"; - var expected = @"namespace N -{ - public class C - { - protected void Render() - { - if (outer) - { - M(() => + """; + var expected = """ + namespace N + { + public class C { -#nullable enable - if (inner) + protected void Render() { + if (outer) + { + M(() => + { + #nullable enable + if (inner) + { + } + } + ); + } } } - ); - } - } - } -} -"; + } + """; await AssertFormatAsync(expected, code, spans: null); } @@ -1622,46 +1816,48 @@ protected void Render() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/57465")] public async Task FormatLambdaWithComment() { - var code = @"namespace N -{ - public class C - { - protected void Render() - { -if (true) - { - M(() => - { - if (true) + var code = """ + namespace N { -/* marker */ - } - }); + public class C + { + protected void Render() + { + if (true) + { + M(() => + { + if (true) + { + /* marker */ + } + }); + } + } + } } - } - } -} -"; - var expected = @"namespace N -{ - public class C - { - protected void Render() - { - if (true) - { - M(() => + """; + var expected = """ + namespace N { - if (true) + public class C { - /* marker */ + protected void Render() + { + if (true) + { + M(() => + { + if (true) + { + /* marker */ + } + }); + } + } } - }); - } - } - } -} -"; + } + """; await AssertFormatAsync(expected, code, spans: null); } @@ -1687,24 +1883,28 @@ public async Task FormatAttributeAtEndOfFile(bool trailingNewLine) public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff1() { var code = -@"class Program -{ - void M() - { - if (true) - {$$ - } -}"; + """ + class Program + { + void M() + { + if (true) + {$$ + } + } + """; var expected = -@"class Program -{ - void M() - { - if (true) - { - } -}"; + """ + class Program + { + void M() + { + if (true) + { + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1713,24 +1913,28 @@ void M() public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff2() { var code = -@"class Program -{ - void M() - { - if (true) - {}$$ - } -}"; + """ + class Program + { + void M() + { + if (true) + {}$$ + } + } + """; var expected = -@"class Program -{ - void M() - { - if (true) - { } - } -}"; + """ + class Program + { + void M() + { + if (true) + { } + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1740,22 +1944,26 @@ public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff3() { // We only smart indent the { if it's on it's own line. var code = -@"class Program -{ - void M() - { - if (true){$$ - } -}"; + """ + class Program + { + void M() + { + if (true){$$ + } + } + """; var expected = -@"class Program -{ - void M() - { - if (true){ - } -}"; + """ + class Program + { + void M() + { + if (true){ + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1765,22 +1973,26 @@ public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff4() { // We only smart indent the { if it's on it's own line. var code = -@"class Program -{ - void M() - { - if (true){}$$ - } -}"; + """ + class Program + { + void M() + { + if (true){}$$ + } + } + """; var expected = -@"class Program -{ - void M() - { - if (true){ } - } -}"; + """ + class Program + { + void M() + { + if (true){ } + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1790,24 +2002,28 @@ public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff5() { // Typing the { should not affect the formating of the preceding tokens. var code = -@"class Program -{ - void M() - { - if ( true ) - {$$ - } -}"; + """ + class Program + { + void M() + { + if ( true ) + {$$ + } + } + """; var expected = -@"class Program -{ - void M() - { - if ( true ) - { - } -}"; + """ + class Program + { + void M() + { + if ( true ) + { + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1816,23 +2032,27 @@ void M() public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff6() { // Typing the { should not affect the formating of the preceding tokens. - var code = -@"class Program -{ - void M() - { - if ( true ){$$ - } -}"; + var code = + """ + class Program + { + void M() + { + if ( true ){$$ + } + } + """; var expected = -@"class Program -{ - void M() - { - if ( true ){ - } -}"; + """ + class Program + { + void M() + { + if ( true ){ + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1841,18 +2061,22 @@ void M() public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff7() { var code = -@"class Program -{ - void M() - {$$ -}"; + """ + class Program + { + void M() + {$$ + } + """; var expected = -@"class Program -{ - void M() - { -}"; + """ + class Program + { + void M() + { + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1861,26 +2085,30 @@ void M() public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff1() { var code = -@"class Program -{ - void M() - { - if (true) - { - }$$ - } -}"; + """ + class Program + { + void M() + { + if (true) + { + }$$ + } + } + """; var expected = -@"class Program -{ - void M() - { - if (true) - { - } - } -}"; + """ + class Program + { + void M() + { + if (true) + { + } + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1890,24 +2118,28 @@ public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff2() { // Note that the { is not updated since we are not formatting. var code = -@"class Program -{ - void M() - { - if (true) { - }$$ - } -}"; + """ + class Program + { + void M() + { + if (true) { + }$$ + } + } + """; var expected = -@"class Program -{ - void M() - { - if (true) { - } - } -}"; + """ + class Program + { + void M() + { + if (true) { + } + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1916,20 +2148,24 @@ void M() public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff3() { var code = -@"class Program -{ - void M() - { - }$$ -}"; + """ + class Program + { + void M() + { + }$$ + } + """; var expected = -@"class Program -{ - void M() - { - } -}"; + """ + class Program + { + void M() + { + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1939,18 +2175,22 @@ public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff4() { // Should not affect formatting of open brace var code = -@"class Program -{ - void M() { - }$$ -}"; + """ + class Program + { + void M() { + }$$ + } + """; var expected = -@"class Program -{ - void M() { - } -}"; + """ + class Program + { + void M() { + } + } + """; AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); } @@ -1958,24 +2198,28 @@ void M() { [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/31907")] public async Task NullableReferenceTypes() { - var code = @"[| -class MyClass -{ - void MyMethod() - { - var returnType = (_useMethodSignatureReturnType ? _methodSignatureOpt !: method).ReturnType; - } -} -|]"; - var expected = @" -class MyClass -{ - void MyMethod() - { - var returnType = (_useMethodSignatureReturnType ? _methodSignatureOpt! : method).ReturnType; - } -} -"; + var code = """ + [| + class MyClass + { + void MyMethod() + { + var returnType = (_useMethodSignatureReturnType ? _methodSignatureOpt !: method).ReturnType; + } + } + |] + """; + var expected = """ + + class MyClass + { + void MyMethod() + { + var returnType = (_useMethodSignatureReturnType ? _methodSignatureOpt! : method).ReturnType; + } + } + + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); } @@ -1983,15 +2227,19 @@ void MyMethod() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30518")] public void FormatGeneratedNodeInInitializer() { - var code = @"new bool[] { - true, - true -}"; + var code = """ + new bool[] { + true, + true + } + """; - var expected = @"new bool[] { - true, -true == false, true -}"; + var expected = """ + new bool[] { + true, + true == false, true + } + """; var tree = SyntaxFactory.ParseSyntaxTree(code, options: TestOptions.Script); var root = tree.GetRoot(); @@ -2004,32 +2252,36 @@ public void FormatGeneratedNodeInInitializer() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27268")] public async Task PositionalPattern() { - var code = @"[| -class MyClass -{ - void MyMethod() - { - var point = new Point (3, 4); - if (point is Point (3, 4) _ - && point is Point{x: 3, y: 4} _) - { - } - } -} -|]"; - var expected = @" -class MyClass -{ - void MyMethod() - { - var point = new Point(3, 4); - if (point is Point(3, 4) _ - && point is Point { x: 3, y: 4 } _) - { - } - } -} -"; + var code = """ + [| + class MyClass + { + void MyMethod() + { + var point = new Point (3, 4); + if (point is Point (3, 4) _ + && point is Point{x: 3, y: 4} _) + { + } + } + } + |] + """; + var expected = """ + + class MyClass + { + void MyMethod() + { + var point = new Point(3, 4); + if (point is Point(3, 4) _ + && point is Point { x: 3, y: 4 } _) + { + } + } + } + + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); } @@ -2037,24 +2289,28 @@ void MyMethod() [WpfFact] public async Task WithExpression() { - var code = @"[| -record C(int Property) -{ - void M() - { - _ = this with { Property = 1 } ; - } -} -|]"; - var expected = @" -record C(int Property) -{ - void M() - { - _ = this with { Property = 1 }; - } -} -"; + var code = """ + [| + record C(int Property) + { + void M() + { + _ = this with { Property = 1 } ; + } + } + |] + """; + var expected = """ + + record C(int Property) + { + void M() + { + _ = this with { Property = 1 }; + } + } + + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); } @@ -2062,32 +2318,36 @@ void M() [WpfFact] public async Task WithExpression_MultiLine() { - var code = @"[| -record C(int Property, int Property2) -{ - void M() - { - _ = this with -{ -Property = 1, -Property2 = 2 -} ; - } -} -|]"; - var expected = @" -record C(int Property, int Property2) -{ - void M() - { - _ = this with - { - Property = 1, - Property2 = 2 - }; - } -} -"; + var code = """ + [| + record C(int Property, int Property2) + { + void M() + { + _ = this with + { + Property = 1, + Property2 = 2 + } ; + } + } + |] + """; + var expected = """ + + record C(int Property, int Property2) + { + void M() + { + _ = this with + { + Property = 1, + Property2 = 2 + }; + } + } + + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); } @@ -2095,32 +2355,36 @@ void M() [WpfFact] public async Task WithExpression_MultiLine_UserPositionedBraces() { - var code = @"[| -record C(int Property, int Property2) -{ - void M() - { - _ = this with - { - Property = 1, - Property2 = 2 - } ; - } -} -|]"; - var expected = @" -record C(int Property, int Property2) -{ - void M() - { - _ = this with - { - Property = 1, - Property2 = 2 - }; - } -} -"; + var code = """ + [| + record C(int Property, int Property2) + { + void M() + { + _ = this with + { + Property = 1, + Property2 = 2 + } ; + } + } + |] + """; + var expected = """ + + record C(int Property, int Property2) + { + void M() + { + _ = this with + { + Property = 1, + Property2 = 2 + }; + } + } + + """; await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); } @@ -2128,23 +2392,25 @@ void M() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_KeepMultipleLinesBetweenGroups() { - var code = @"$$ -using System.A; -using System.B; + var code = """ + $$ + using System.A; + using System.B; -using MS.A; -using MS.B; -"; + using MS.A; + using MS.B; + """; - var expected = @"$$ -using System.A; -using System.B; + var expected = """ + $$ + using System.A; + using System.B; -using MS.A; -using MS.B; -"; + using MS.A; + using MS.B; + """; AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } @@ -2152,27 +2418,29 @@ public void SeparateGroups_KeepMultipleLinesBetweenGroups() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_KeepMultipleLinesBetweenGroups_FileScopedNamespace() { - var code = @"$$ -namespace N; + var code = """ + $$ + namespace N; -using System.A; -using System.B; + using System.A; + using System.B; -using MS.A; -using MS.B; -"; + using MS.A; + using MS.B; + """; - var expected = @"$$ -namespace N; + var expected = """ + $$ + namespace N; -using System.A; -using System.B; + using System.A; + using System.B; -using MS.A; -using MS.B; -"; + using MS.A; + using MS.B; + """; AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } @@ -2180,19 +2448,21 @@ namespace N; [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_DoNotGroupIfNotSorted() { - var code = @"$$ -using System.B; -using System.A; -using MS.B; -using MS.A; -"; + var code = """ + $$ + using System.B; + using System.A; + using MS.B; + using MS.A; + """; - var expected = @"$$ -using System.B; -using System.A; -using MS.B; -using MS.A; -"; + var expected = """ + $$ + using System.B; + using System.A; + using MS.B; + using MS.A; + """; AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } @@ -2200,20 +2470,22 @@ public void SeparateGroups_DoNotGroupIfNotSorted() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_GroupIfSorted() { - var code = @"$$ -using System.A; -using System.B; -using MS.A; -using MS.B; -"; + var code = """ + $$ + using System.A; + using System.B; + using MS.A; + using MS.B; + """; - var expected = @"$$ -using System.A; -using System.B; + var expected = """ + $$ + using System.A; + using System.B; -using MS.A; -using MS.B; -"; + using MS.A; + using MS.B; + """; AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } @@ -2221,20 +2493,22 @@ public void SeparateGroups_GroupIfSorted() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] public void SeparateGroups_GroupIfSorted_RecognizeSystemNotFirst() { - var code = @"$$ -using MS.A; -using MS.B; -using System.A; -using System.B; -"; + var code = """ + $$ + using MS.A; + using MS.B; + using System.A; + using System.B; + """; - var expected = @"$$ -using MS.A; -using MS.B; + var expected = """ + $$ + using MS.A; + using MS.B; -using System.A; -using System.B; -"; + using System.A; + using System.B; + """; AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); } @@ -2242,29 +2516,31 @@ public void SeparateGroups_GroupIfSorted_RecognizeSystemNotFirst() [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/58157")] public void FormatImplicitObjectCollection() { - var code = @"class Program -{ - static void Main(string[] args) - { - $$List list = new() - { - 1, 2, 3, 4, - }; - } -} -"; + var code = """ + class Program + { + static void Main(string[] args) + { + $$List list = new() + { + 1, 2, 3, 4, + }; + } + } + """; - var expected = @"class Program -{ - static void Main(string[] args) - { - $$List list = new() - { - 1, 2, 3, 4, - }; - } -} -"; + var expected = """ + class Program + { + static void Main(string[] args) + { + $$List list = new() + { + 1, 2, 3, 4, + }; + } + } + """; AssertFormatWithView(expected, code); } @@ -2272,15 +2548,15 @@ static void Main(string[] args) [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49492")] public void PreserveAnnotationsOnMultiLineTrivia() { - var text = @" -namespace TestApp -{ - class Test - { - /* __marker__ */ - } -} -"; + var text = """ + namespace TestApp + { + class Test + { + /* __marker__ */ + } + } + """; var position = text.IndexOf("/* __marker__ */"); var syntaxTree = CSharpSyntaxTree.ParseText(text); @@ -2304,20 +2580,24 @@ class Test [WpfFact] public void FormatUserDefinedOperator() { - var code = @"$$ -class C -{ - public static C operator + ( C x, C y){ - } -}"; + var code = """ + $$ + class C + { + public static C operator + ( C x, C y){ + } + } + """; - var expected = @"$$ -class C -{ - public static C operator +(C x, C y) - { - } -}"; + var expected = """ + $$ + class C + { + public static C operator +(C x, C y) + { + } + } + """; AssertFormatWithView(expected, code); } @@ -2325,20 +2605,24 @@ class C [WpfFact] public void FormatUserDefinedUnaryOperator() { - var code = @"$$ -class C -{ - public static C operator ++ ( C x){ - } -}"; + var code = """ + $$ + class C + { + public static C operator ++ ( C x){ + } + } + """; - var expected = @"$$ -class C -{ - public static C operator ++(C x) - { - } -}"; + var expected = """ + $$ + class C + { + public static C operator ++(C x) + { + } + } + """; AssertFormatWithView(expected, code); } @@ -2346,20 +2630,24 @@ class C [WpfFact] public void FormatUserDefinedExplicitCastOperator() { - var code = @"$$ -class C -{ - public static explicit operator C ( int x){ - } -}"; + var code = """ + $$ + class C + { + public static explicit operator C ( int x){ + } + } + """; - var expected = @"$$ -class C -{ - public static explicit operator C(int x) - { - } -}"; + var expected = """ + $$ + class C + { + public static explicit operator C(int x) + { + } + } + """; AssertFormatWithView(expected, code); } @@ -2367,17 +2655,19 @@ public static explicit operator C(int x) [WpfFact] public void FormatUserDefinedOperatorOnType() { - var code = @" -interface I1 -{ - abstract static I1 operator + ( I1 x, I1 y);$$ -}"; + var code = """ + interface I1 + { + abstract static I1 operator + ( I1 x, I1 y);$$ + } + """; - var expected = @" -interface I1 -{ - abstract static I1 operator +(I1 x, I1 y); -}"; + var expected = """ + interface I1 + { + abstract static I1 operator +(I1 x, I1 y); + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -2385,17 +2675,19 @@ interface I1 [WpfFact] public void FormatUserDefinedUnaryOperatorOnType() { - var code = @" -interface I1 -{ - abstract static I1 operator ++ ( I1 x);$$ -}"; + var code = """ + interface I1 + { + abstract static I1 operator ++ ( I1 x);$$ + } + """; - var expected = @" -interface I1 -{ - abstract static I1 operator ++(I1 x); -}"; + var expected = """ + interface I1 + { + abstract static I1 operator ++(I1 x); + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -2403,17 +2695,19 @@ interface I1 [WpfFact] public void FormatUserDefinedExplicitCastOperatorOnType() { - var code = @" -interface I1 where T : I1 -{ - abstract static explicit operator string ( T x);$$ -}"; + var code = """ + interface I1 where T : I1 + { + abstract static explicit operator string ( T x);$$ + } + """; - var expected = @" -interface I1 where T : I1 -{ - abstract static explicit operator string(T x); -}"; + var expected = """ + interface I1 where T : I1 + { + abstract static explicit operator string(T x); + } + """; AssertFormatAfterTypeChar(code, expected); } @@ -2421,20 +2715,24 @@ interface I1 where T : I1 [WpfFact] public void FormatUserDefinedCheckedOperator() { - var code = @"$$ -class C -{ - public static C operator checked + ( C x, C y){ - } -}"; + var code = """ + $$ + class C + { + public static C operator checked + ( C x, C y){ + } + } + """; - var expected = @"$$ -class C -{ - public static C operator checked +(C x, C y) - { - } -}"; + var expected = """ + $$ + class C + { + public static C operator checked +(C x, C y) + { + } + } + """; AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); } @@ -2442,20 +2740,24 @@ class C [WpfFact] public void FormatUserDefinedCheckedUnaryOperator() { - var code = @"$$ -class C -{ - public static C operator checked ++ ( C x){ - } -}"; + var code = """ + $$ + class C + { + public static C operator checked ++ ( C x){ + } + } + """; - var expected = @"$$ -class C -{ - public static C operator checked ++(C x) - { - } -}"; + var expected = """ + $$ + class C + { + public static C operator checked ++(C x) + { + } + } + """; AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); } @@ -2463,20 +2765,24 @@ class C [WpfFact] public void FormatUserDefinedExplicitCheckedCastOperator() { - var code = @"$$ -class C -{ - public static explicit operator checked C ( int x){ - } -}"; + var code = """ + $$ + class C + { + public static explicit operator checked C ( int x){ + } + } + """; - var expected = @"$$ -class C -{ - public static explicit operator checked C(int x) - { - } -}"; + var expected = """ + $$ + class C + { + public static explicit operator checked C(int x) + { + } + } + """; AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); } @@ -2484,17 +2790,19 @@ public static explicit operator checked C(int x) [WpfFact] public void FormatUserDefinedCheckedOperatorOnType() { - var code = @" -interface I1 -{ - abstract static I1 operator checked + ( I1 x, I1 y);$$ -}"; + var code = """ + interface I1 + { + abstract static I1 operator checked + ( I1 x, I1 y);$$ + } + """; - var expected = @" -interface I1 -{ - abstract static I1 operator checked +(I1 x, I1 y); -}"; + var expected = """ + interface I1 + { + abstract static I1 operator checked +(I1 x, I1 y); + } + """; AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); } @@ -2502,17 +2810,19 @@ interface I1 [WpfFact] public void FormatUserDefinedCheckedUnaryOperatorOnType() { - var code = @" -interface I1 -{ - abstract static I1 operator checked ++ ( I1 x);$$ -}"; + var code = """ + interface I1 + { + abstract static I1 operator checked ++ ( I1 x);$$ + } + """; - var expected = @" -interface I1 -{ - abstract static I1 operator checked ++(I1 x); -}"; + var expected = """ + interface I1 + { + abstract static I1 operator checked ++(I1 x); + } + """; AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); } @@ -2520,17 +2830,19 @@ interface I1 [WpfFact] public void FormatUserDefinedExplicitCheckedCastOperatorOnType() { - var code = @" -interface I1 where T : I1 -{ - abstract static explicit operator checked string ( T x);$$ -}"; + var code = """ + interface I1 where T : I1 + { + abstract static explicit operator checked string ( T x);$$ + } + """; - var expected = @" -interface I1 where T : I1 -{ - abstract static explicit operator checked string(T x); -}"; + var expected = """ + interface I1 where T : I1 + { + abstract static explicit operator checked string(T x); + } + """; AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); } @@ -2538,20 +2850,24 @@ interface I1 where T : I1 [WpfFact] public void FormatUnsignedRightShift() { - var code = @"$$ -class C -{ - public static C operator>>> ( C x, C y){ - } -}"; + var code = """ + $$ + class C + { + public static C operator>>> ( C x, C y){ + } + } + """; - var expected = @"$$ -class C -{ - public static C operator >>>(C x, C y) - { - } -}"; + var expected = """ + $$ + class C + { + public static C operator >>>(C x, C y) + { + } + } + """; AssertFormatWithView(expected, code); } @@ -2601,29 +2917,31 @@ void M() [WpfFact] public void FormatUnsignedRightShiftOnType() { - var code = @" -interface I1 -{ - abstract static I1 operator >>> ( I1 x, I1 y);$$ -}"; + var code = """ + interface I1 + { + abstract static I1 operator >>> ( I1 x, I1 y);$$ + } + """; - var expected = @" -interface I1 -{ - abstract static I1 operator >>>(I1 x, I1 y); -}"; + var expected = """ + interface I1 + { + abstract static I1 operator >>>(I1 x, I1 y); + } + """; AssertFormatAfterTypeChar(code, expected); } - private static void AssertFormatAfterTypeChar(string code, string expected, OptionsCollection globalOptions = null, ParseOptions parseOptions = null) + private static void AssertFormatAfterTypeChar(string code, string expected, OptionsCollection? globalOptions = null, ParseOptions? parseOptions = null) { using var workspace = TestWorkspace.CreateCSharp(code, parseOptions: parseOptions); var subjectDocument = workspace.Documents.Single(); var commandHandler = workspace.GetService(); - var typedChar = subjectDocument.GetTextBuffer().CurrentSnapshot.GetText(subjectDocument.CursorPosition.Value - 1, 1); + var typedChar = subjectDocument.GetTextBuffer().CurrentSnapshot.GetText(subjectDocument.CursorPosition!.Value - 1, 1); var textView = subjectDocument.GetTextView(); globalOptions?.SetGlobalOptions(workspace.GlobalOptions); From f0bbe09e25e584e08cc18a3dfd1f1721a82c2679 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 16 Aug 2023 09:25:04 -0700 Subject: [PATCH 4/4] File scoped namespace --- .../Formatting/FormattingEngineTests.cs | 1771 ++++++++--------- 1 file changed, 885 insertions(+), 886 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs index 5dd0ebc0530a8..f5031af43e12f 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs @@ -22,25 +22,25 @@ using Xunit; using Xunit.Abstractions; -namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Formatting -{ - [Trait(Traits.Feature, Traits.Features.Formatting)] - public class FormattingEngineTests : CSharpFormattingEngineTestBase - { - public FormattingEngineTests(ITestOutputHelper output) : base(output) { } +namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Formatting; - private static OptionsCollection SmartIndentButDoNotFormatWhileTyping() - => new(LanguageNames.CSharp) - { - { IndentationOptionsStorage.SmartIndent, FormattingOptions2.IndentStyle.Smart }, - { AutoFormattingOptionsStorage.FormatOnTyping, false }, - { AutoFormattingOptionsStorage.FormatOnCloseBrace, false }, - }; +[Trait(Traits.Feature, Traits.Features.Formatting)] +public class FormattingEngineTests : CSharpFormattingEngineTestBase +{ + public FormattingEngineTests(ITestOutputHelper output) : base(output) { } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539682")] - public void FormatDocumentCommandHandler() + private static OptionsCollection SmartIndentButDoNotFormatWhileTyping() + => new(LanguageNames.CSharp) { - var code = """ + { IndentationOptionsStorage.SmartIndent, FormattingOptions2.IndentStyle.Smart }, + { AutoFormattingOptionsStorage.FormatOnTyping, false }, + { AutoFormattingOptionsStorage.FormatOnCloseBrace, false }, + }; + + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539682")] + public void FormatDocumentCommandHandler() + { + var code = """ class Program { static void Main(string[] args) @@ -51,7 +51,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -62,13 +62,13 @@ static void Main(string[] args) } """; - AssertFormatWithView(expected, code); - } + AssertFormatWithView(expected, code); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539682")] - public void FormatDocumentPasteCommandHandler() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/539682")] + public void FormatDocumentPasteCommandHandler() + { + var code = """ class Program { static void Main(string[] args) @@ -79,7 +79,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -90,13 +90,13 @@ static void Main(string[] args) } """; - AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true); - } + AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/547261")] - public void FormatDocumentReadOnlyWorkspacePasteCommandHandler() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/547261")] + public void FormatDocumentReadOnlyWorkspacePasteCommandHandler() + { + var code = """ class Program { static void Main(string[] args) @@ -107,7 +107,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -118,13 +118,13 @@ static void Main(string[] args) } """; - AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: false); - } + AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: false); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] - public void DoNotFormatUsingStatementOnReturn() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] + public void DoNotFormatUsingStatementOnReturn() + { + var code = """ class Program { static void Main(string[] args) @@ -135,7 +135,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -146,13 +146,13 @@ static void Main(string[] args) } """; - AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true, isPaste: false); - } + AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true, isPaste: false); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] - public void FormatUsingStatementWhenTypingCloseParen() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] + public void FormatUsingStatementWhenTypingCloseParen() + { + var code = """ class Program { static void Main(string[] args) @@ -163,7 +163,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -174,13 +174,13 @@ static void Main(string[] args) } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] - public void FormatNotUsingStatementOnReturn() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/912965")] + public void FormatNotUsingStatementOnReturn() + { + var code = """ class Program { static void Main(string[] args) @@ -191,7 +191,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -202,13 +202,13 @@ static void Main(string[] args) } """; - AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true, isPaste: false); - } + AssertFormatWithPasteOrReturn(expected, code, allowDocumentChanges: true, isPaste: false); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/977133")] - public void DoNotFormatRangeOrFormatTokenOnOpenBraceOnSameLine() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/977133")] + public void DoNotFormatRangeOrFormatTokenOnOpenBraceOnSameLine() + { + var code = """ class C { public void M() @@ -217,7 +217,7 @@ public void M() } } """; - var expected = """ + var expected = """ class C { public void M() @@ -226,13 +226,13 @@ public void M() } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/pull/14491")] - public void DoNotFormatRangeButFormatTokenOnOpenBraceOnNextLine() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/pull/14491")] + public void DoNotFormatRangeButFormatTokenOnOpenBraceOnNextLine() + { + var code = """ class C { public void M() @@ -242,7 +242,7 @@ public void M() } } """; - var expected = """ + var expected = """ class C { public void M() @@ -252,13 +252,13 @@ public void M() } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1007071")] - public void FormatPragmaWarningInbetweenDelegateDeclarationStatement() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1007071")] + public void FormatPragmaWarningInbetweenDelegateDeclarationStatement() + { + var code = """ using System; class Program @@ -273,7 +273,7 @@ static void Main(string[] args) } } """; - var expected = """ + var expected = """ using System; class Program @@ -288,13 +288,13 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] - public void FormatHashRegion() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] + public void FormatHashRegion() + { + var code = """ using System; class Program @@ -305,7 +305,7 @@ static void Main(string[] args) } } """; - var expected = """ + var expected = """ using System; class Program @@ -316,13 +316,13 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] - public void FormatHashEndRegion() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/771761")] + public void FormatHashEndRegion() + { + var code = """ using System; class Program @@ -334,7 +334,7 @@ static void Main(string[] args) } } """; - var expected = """ + var expected = """ using System; class Program @@ -346,13 +346,13 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/987373")] - public async Task FormatSpansIndividuallyWithoutCollapsing() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/987373")] + public async Task FormatSpansIndividuallyWithoutCollapsing() + { + var code = """ class C { public void M() @@ -393,7 +393,7 @@ public void M() } } """; - var expected = """ + var expected = """ class C { public void M() @@ -434,21 +434,21 @@ public void M() } } """; - using var workspace = TestWorkspace.CreateCSharp(code); - var subjectDocument = workspace.Documents.Single(); - var spans = subjectDocument.SelectedSpans; + using var workspace = TestWorkspace.CreateCSharp(code); + var subjectDocument = workspace.Documents.Single(); + var spans = subjectDocument.SelectedSpans; - var document = workspace.CurrentSolution.Projects.Single().Documents.Single(); - var syntaxRoot = await document.GetRequiredSyntaxRootAsync(CancellationToken.None); - var options = CSharpSyntaxFormattingOptions.Default; - var node = Formatter.Format(syntaxRoot, spans, workspace.Services.SolutionServices, options, rules: null, CancellationToken.None); - Assert.Equal(expected, node.ToFullString()); - } + var document = workspace.CurrentSolution.Projects.Single().Documents.Single(); + var syntaxRoot = await document.GetRequiredSyntaxRootAsync(CancellationToken.None); + var options = CSharpSyntaxFormattingOptions.Default; + var node = Formatter.Format(syntaxRoot, spans, workspace.Services.SolutionServices, options, rules: null, CancellationToken.None); + Assert.Equal(expected, node.ToFullString()); + } - [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1044118")] - public void SemicolonInCommentOnLastLineDoesNotFormat() - { - var code = """ + [WpfFact, WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1044118")] + public void SemicolonInCommentOnLastLineDoesNotFormat() + { + var code = """ using System; class Program @@ -460,7 +460,7 @@ static void Main(string[] args) // ;$$ """; - var expected = """ + var expected = """ using System; class Program @@ -471,15 +471,15 @@ static void Main(string[] args) } // ; """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideSingleLineRegularComment_1() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideSingleLineRegularComment_1() + { + var code = """ class Program { // {$$ @@ -490,7 +490,7 @@ static void Main(int a, int b) } """; - var expected = """ + var expected = """ class Program { // { @@ -500,15 +500,15 @@ static void Main(int a, int b) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideSingleLineRegularComment_2() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideSingleLineRegularComment_2() + { + var code = """ class Program { // {$$ @@ -519,7 +519,7 @@ static void Main(int a, int b) } """; - var expected = """ + var expected = """ class Program { // { @@ -529,15 +529,15 @@ static void Main(int a, int b) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideMultiLineRegularComment_1() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideMultiLineRegularComment_1() + { + var code = """ class Program { static void Main(int a/* {$$ */, int b) @@ -547,7 +547,7 @@ static void Main(int a/* {$$ */, int b) } """; - var expected = """ + var expected = """ class Program { static void Main(int a/* { */, int b) @@ -556,15 +556,15 @@ static void Main(int a/* { */, int b) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideMultiLineRegularComment_2() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideMultiLineRegularComment_2() + { + var code = """ class Program { static void Main(int a/* {$$ @@ -575,7 +575,7 @@ static void Main(int a/* {$$ } """; - var expected = """ + var expected = """ class Program { static void Main(int a/* { @@ -585,15 +585,15 @@ static void Main(int a/* { } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideMultiLineRegularComment_3() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideMultiLineRegularComment_3() + { + var code = """ class Program { static void Main(int a/* {$$ @@ -604,7 +604,7 @@ static void Main(int a/* {$$ } """; - var expected = """ + var expected = """ class Program { static void Main(int a/* { @@ -614,15 +614,15 @@ static void Main(int a/* { } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideSingleLineDocComment_1() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideSingleLineDocComment_1() + { + var code = """ class Program { /// {$$ @@ -633,7 +633,7 @@ static void Main(int a, int b) } """; - var expected = """ + var expected = """ class Program { /// { @@ -643,15 +643,15 @@ static void Main(int a, int b) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideSingleLineDocComment_2() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideSingleLineDocComment_2() + { + var code = """ class Program { /// {$$ @@ -662,7 +662,7 @@ static void Main(int a, int b) } """; - var expected = """ + var expected = """ class Program { /// { @@ -672,15 +672,15 @@ static void Main(int a, int b) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideMultiLineDocComment_1() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideMultiLineDocComment_1() + { + var code = """ class Program { /** {$$ **/ @@ -691,7 +691,7 @@ static void Main(int a, int b) } """; - var expected = """ + var expected = """ class Program { /** { **/ @@ -701,15 +701,15 @@ static void Main(int a, int b) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideMultiLineDocComment_2() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideMultiLineDocComment_2() + { + var code = """ class Program { /** {$$ @@ -721,7 +721,7 @@ static void Main(int a, int b) } """; - var expected = """ + var expected = """ class Program { /** { @@ -732,15 +732,15 @@ static void Main(int a, int b) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideMultiLineDocComment_3() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideMultiLineDocComment_3() + { + var code = """ class Program { /** {$$ @@ -752,7 +752,7 @@ static void Main(int a, int b) } """; - var expected = """ + var expected = """ class Program { /** { @@ -763,15 +763,15 @@ static void Main(int a, int b) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideInactiveCode() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideInactiveCode() + { + var code = """ class Program { #if false @@ -785,7 +785,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { #if false @@ -798,15 +798,15 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideStringLiteral() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideStringLiteral() + { + var code = """ class Program { static void Main(string[] args) @@ -816,7 +816,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -825,15 +825,15 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideCharLiteral() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideCharLiteral() + { + var code = """ class Program { static void Main(string[] args) @@ -843,7 +843,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -852,15 +852,15 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/449")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] - public void NoFormattingInsideCommentsOfPreprocessorDirectives() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/449")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1077103")] + public void NoFormattingInsideCommentsOfPreprocessorDirectives() + { + var code = """ class Program { #region @@ -872,7 +872,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { #region @@ -883,15 +883,15 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void ColonInSwitchCase() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void ColonInSwitchCase() + { + var code = """ class Program { static void Main(string[] args) @@ -905,7 +905,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -918,15 +918,15 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void ColonInDefaultSwitchCase() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void ColonInDefaultSwitchCase() + { + var code = """ class Program { static void Main(string[] args) @@ -941,7 +941,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -955,13 +955,13 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/9097")] - public void ColonInPatternSwitchCase01() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/9097")] + public void ColonInPatternSwitchCase01() + { + var code = """ class Program { static void Main() @@ -974,7 +974,7 @@ static void Main() } """; - var expected = """ + var expected = """ class Program { static void Main() @@ -986,15 +986,15 @@ static void Main() } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void ColonInLabeledStatement() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void ColonInLabeledStatement() + { + var code = """ class Program { static void Main(string[] args) @@ -1004,7 +1004,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -1013,15 +1013,15 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void DoNotFormatColonInTargetAttribute() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void DoNotFormatColonInTargetAttribute() + { + var code = """ using System; [method :$$ C] class C : Attribute @@ -1029,41 +1029,41 @@ class C : Attribute } """; - var expected = """ + var expected = """ using System; [method : C] class C : Attribute { } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void DoNotFormatColonInBaseList() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void DoNotFormatColonInBaseList() + { + var code = """ class C :$$ Attribute { } """; - var expected = """ + var expected = """ class C : Attribute { } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void DoNotFormatColonInThisConstructor() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void DoNotFormatColonInThisConstructor() + { + var code = """ class Goo { Goo(int s) :$$ this() @@ -1076,7 +1076,7 @@ class Goo } """; - var expected = """ + var expected = """ class Goo { Goo(int s) : this() @@ -1088,15 +1088,15 @@ class Goo } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void DoNotFormatColonInConditionalOperator() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void DoNotFormatColonInConditionalOperator() + { + var code = """ class Program { static void Main(string[] args) @@ -1106,7 +1106,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -1115,15 +1115,15 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void DoNotFormatColonInArgument() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void DoNotFormatColonInArgument() + { + var code = """ class Program { static void Main(string[] args) @@ -1133,7 +1133,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -1142,15 +1142,15 @@ static void Main(string[] args) } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [WorkItem("https://github.com/dotnet/roslyn/issues/464")] - [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] - public void DoNotFormatColonInTypeParameter() - { - var code = """ + [WpfFact] + [WorkItem("https://github.com/dotnet/roslyn/issues/464")] + [WorkItem("http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/908729")] + public void DoNotFormatColonInTypeParameter() + { + var code = """ class Program { class C1 @@ -1161,7 +1161,7 @@ class C1 } """; - var expected = """ + var expected = """ class Program { class C1 @@ -1171,13 +1171,13 @@ class C1 } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/2224")] - public void DoNotSmartFormatBracesOnSmartIndentNone() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/2224")] + public void DoNotSmartFormatBracesOnSmartIndentNone() + { + var code = """ class Program { class C1 @@ -1185,25 +1185,25 @@ class C1 } """; - var expected = """ + var expected = """ class Program { class C1 { } """; - var globalOptions = new OptionsCollection(LanguageNames.CSharp) - { - { IndentationOptionsStorage.SmartIndent, FormattingOptions2.IndentStyle.None } - }; - AssertFormatAfterTypeChar(code, expected, globalOptions); - } - - [WpfFact] - [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] - public void StillAutoIndentCloseBraceWhenFormatOnCloseBraceIsOff() + var globalOptions = new OptionsCollection(LanguageNames.CSharp) { - var code = """ + { IndentationOptionsStorage.SmartIndent, FormattingOptions2.IndentStyle.None } + }; + AssertFormatAfterTypeChar(code, expected, globalOptions); + } + + [WpfFact] + [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + public void StillAutoIndentCloseBraceWhenFormatOnCloseBraceIsOff() + { + var code = """ namespace N { class C @@ -1214,7 +1214,7 @@ class C } """; - var expected = """ + var expected = """ namespace N { class C @@ -1225,19 +1225,19 @@ class C } """; - var globalOptions = new OptionsCollection(LanguageNames.CSharp) - { - { AutoFormattingOptionsStorage.FormatOnCloseBrace, false } - }; + var globalOptions = new OptionsCollection(LanguageNames.CSharp) + { + { AutoFormattingOptionsStorage.FormatOnCloseBrace, false } + }; - AssertFormatAfterTypeChar(code, expected, globalOptions); - } + AssertFormatAfterTypeChar(code, expected, globalOptions); + } - [WpfFact] - [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] - public void AutoIndentCloseBraceWhenFormatOnTypingIsOff() - { - var code = """ + [WpfFact] + [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + public void AutoIndentCloseBraceWhenFormatOnTypingIsOff() + { + var code = """ namespace N { class C @@ -1248,7 +1248,7 @@ class C } """; - var expected = """ + var expected = """ namespace N { class C @@ -1259,22 +1259,22 @@ class C } """; - var globalOptions = new OptionsCollection(LanguageNames.CSharp) - { - { AutoFormattingOptionsStorage.FormatOnTyping, false } - }; + var globalOptions = new OptionsCollection(LanguageNames.CSharp) + { + { AutoFormattingOptionsStorage.FormatOnTyping, false } + }; - AssertFormatAfterTypeChar(code, expected, globalOptions); - } + AssertFormatAfterTypeChar(code, expected, globalOptions); + } - [WpfFact, Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] - [WorkItem("https://github.com/dotnet/roslyn/issues/5873")] - public void KeepTabsInCommentsWhenFormattingIsOff() - { - // There are tabs in this test case. Tools that touch the Roslyn repo should - // not remove these as we are explicitly testing tab behavior. - var code = - """ + [WpfFact, Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + [WorkItem("https://github.com/dotnet/roslyn/issues/5873")] + public void KeepTabsInCommentsWhenFormattingIsOff() + { + // There are tabs in this test case. Tools that touch the Roslyn repo should + // not remove these as we are explicitly testing tab behavior. + var code = + """ class Program { static void Main() @@ -1284,8 +1284,8 @@ static void Main() } """; - var expected = - """ + var expected = + """ class Program { static void Main() @@ -1295,21 +1295,21 @@ static void Main() } """; - var globalOptions = new OptionsCollection(LanguageNames.CSharp) - { - { AutoFormattingOptionsStorage.FormatOnTyping, false } - }; + var globalOptions = new OptionsCollection(LanguageNames.CSharp) + { + { AutoFormattingOptionsStorage.FormatOnTyping, false } + }; - AssertFormatAfterTypeChar(code, expected, globalOptions); - } + AssertFormatAfterTypeChar(code, expected, globalOptions); + } - [WpfFact, Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] - [WorkItem("https://github.com/dotnet/roslyn/issues/5873")] - public void DoNotKeepTabsInCommentsWhenFormattingIsOn() - { - // There are tabs in this test case. Tools that touch the Roslyn repo should - // not remove these as we are explicitly testing tab behavior. - var code = """ + [WpfFact, Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + [WorkItem("https://github.com/dotnet/roslyn/issues/5873")] + public void DoNotKeepTabsInCommentsWhenFormattingIsOn() + { + // There are tabs in this test case. Tools that touch the Roslyn repo should + // not remove these as we are explicitly testing tab behavior. + var code = """ class Program { static void Main() @@ -1319,8 +1319,8 @@ static void Main() } """; - var expected = - """ + var expected = + """ class Program { static void Main() @@ -1330,15 +1330,15 @@ static void Main() } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] - public void DoNotFormatStatementIfSemicolonOptionIsOff() - { - var code = - """ + [WpfFact] + [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + public void DoNotFormatStatementIfSemicolonOptionIsOff() + { + var code = + """ namespace N { class C @@ -1348,8 +1348,8 @@ class C } """; - var expected = - """ + var expected = + """ namespace N { class C @@ -1359,20 +1359,20 @@ class C } """; - var globalOptions = new OptionsCollection(LanguageNames.CSharp) - { - { AutoFormattingOptionsStorage.FormatOnSemicolon, false } - }; + var globalOptions = new OptionsCollection(LanguageNames.CSharp) + { + { AutoFormattingOptionsStorage.FormatOnSemicolon, false } + }; - AssertFormatAfterTypeChar(code, expected, globalOptions); - } + AssertFormatAfterTypeChar(code, expected, globalOptions); + } - [WpfFact] - [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] - public void DoNotFormatStatementIfTypingOptionIsOff() - { - var code = - """ + [WpfFact] + [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + public void DoNotFormatStatementIfTypingOptionIsOff() + { + var code = + """ namespace N { class C @@ -1382,8 +1382,8 @@ class C } """; - var expected = - """ + var expected = + """ namespace N { class C @@ -1393,43 +1393,43 @@ class C } """; - var globalOptions = new OptionsCollection(LanguageNames.CSharp) - { - { AutoFormattingOptionsStorage.FormatOnTyping, false } - }; + var globalOptions = new OptionsCollection(LanguageNames.CSharp) + { + { AutoFormattingOptionsStorage.FormatOnTyping, false } + }; - AssertFormatAfterTypeChar(code, expected, globalOptions); - } + AssertFormatAfterTypeChar(code, expected, globalOptions); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/4435")] - [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] - public void OpenCurlyNotFormattedIfNotAtStartOfLine() - { - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/4435")] + [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + public void OpenCurlyNotFormattedIfNotAtStartOfLine() + { + var code = + """ class C { public int P {$$ } """; - var expected = - """ + var expected = + """ class C { public int P { } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/4435")] - [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] - public void OpenCurlyFormattedIfAtStartOfLine() - { - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/4435")] + [Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)] + public void OpenCurlyFormattedIfAtStartOfLine() + { + var code = + """ class C { public int P @@ -1437,8 +1437,8 @@ public int P } """; - var expected = - """ + var expected = + """ class C { public int P @@ -1446,13 +1446,13 @@ public int P } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly1() - { - var code = """ + [WpfFact] + public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly1() + { + var code = """ namespace ConsoleApplication1 { class Program @@ -1463,7 +1463,7 @@ static bool Property } } """; - var expected = """ + var expected = """ namespace ConsoleApplication1 { class Program @@ -1474,13 +1474,13 @@ static bool Property } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly2() - { - var code = """ + [WpfFact] + public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly2() + { + var code = """ namespace ConsoleApplication1 { class Program @@ -1489,7 +1489,7 @@ class Program } } """; - var expected = """ + var expected = """ namespace ConsoleApplication1 { class Program @@ -1498,13 +1498,13 @@ class Program } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly3() - { - var code = """ + [WpfFact] + public void DoNotFormatIncompleteBlockOnSingleLineIfNotTypingCloseCurly3() + { + var code = """ namespace ConsoleApplication1 { class Program @@ -1513,7 +1513,7 @@ class Program } } """; - var expected = """ + var expected = """ namespace ConsoleApplication1 { class Program @@ -1522,13 +1522,13 @@ class Program } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void DoNotFormatCompleteBlockOnSingleLineIfTypingCloseCurly1() - { - var code = """ + [WpfFact] + public void DoNotFormatCompleteBlockOnSingleLineIfTypingCloseCurly1() + { + var code = """ namespace ConsoleApplication1 { class Program @@ -1538,7 +1538,7 @@ static bool Property get { return true; }$$ } """; - var expected = """ + var expected = """ namespace ConsoleApplication1 { class Program @@ -1548,13 +1548,13 @@ static bool Property get { return true; } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void DoNotFormatCompleteBlockOnSingleLineIfTypingCloseCurly2() - { - var code = """ + [WpfFact] + public void DoNotFormatCompleteBlockOnSingleLineIfTypingCloseCurly2() + { + var code = """ namespace ConsoleApplication1 { class Program @@ -1562,7 +1562,7 @@ class Program static bool Property { get { return true; }$$ } """; - var expected = """ + var expected = """ namespace ConsoleApplication1 { class Program @@ -1570,13 +1570,13 @@ class Program static bool Property { get { return true; } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void FormatIncompleteBlockOnMultipleLinesIfTypingCloseCurly1() - { - var code = """ + [WpfFact] + public void FormatIncompleteBlockOnMultipleLinesIfTypingCloseCurly1() + { + var code = """ namespace ConsoleApplication1 { class Program @@ -1587,7 +1587,7 @@ static bool Property }$$ } """; - var expected = """ + var expected = """ namespace ConsoleApplication1 { class Program @@ -1600,13 +1600,13 @@ static bool Property } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void FormatIncompleteBlockOnMultipleLinesIfTypingCloseCurly2() - { - var code = """ + [WpfFact] + public void FormatIncompleteBlockOnMultipleLinesIfTypingCloseCurly2() + { + var code = """ namespace ConsoleApplication1 { class Program @@ -1617,7 +1617,7 @@ static bool Property } }$$ """; - var expected = """ + var expected = """ namespace ConsoleApplication1 { class Program @@ -1630,14 +1630,14 @@ static bool Property } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void DoNotFormatCompleteBlockOnSingleLineIfTypingSemicolon() - { - var code = - """ + [WpfFact] + public void DoNotFormatCompleteBlockOnSingleLineIfTypingSemicolon() + { + var code = + """ public class Class1 { void M() @@ -1648,8 +1648,8 @@ void M() } } """; - var expected = - """ + var expected = + """ public class Class1 { void M() @@ -1660,14 +1660,14 @@ void M() } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void FormatCompleteBlockOnSingleLineIfTypingCloseCurlyOnLaterLine() - { - var code = - """ + [WpfFact] + public void FormatCompleteBlockOnSingleLineIfTypingCloseCurlyOnLaterLine() + { + var code = + """ public class Class1 { void M() @@ -1679,8 +1679,8 @@ void M() } } """; - var expected = - """ + var expected = + """ public class Class1 { void M() @@ -1694,13 +1694,13 @@ void M() } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/7900")] - public void FormatLockStatementWithEmbeddedStatementOnSemicolonDifferentLine() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/7900")] + public void FormatLockStatementWithEmbeddedStatementOnSemicolonDifferentLine() + { + var code = """ class C { private object _l = new object(); @@ -1711,7 +1711,7 @@ public void M() } } """; - var expected = """ + var expected = """ class C { private object _l = new object(); @@ -1722,13 +1722,13 @@ public void M() } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/7900")] - public void FormatLockStatementWithEmbeddedStatementOnSemicolonSameLine() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/7900")] + public void FormatLockStatementWithEmbeddedStatementOnSemicolonSameLine() + { + var code = """ class C { private object _l = new object(); @@ -1738,7 +1738,7 @@ public void M() } } """; - var expected = """ + var expected = """ class C { private object _l = new object(); @@ -1748,24 +1748,24 @@ public void M() } } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/11642")] - public void FormatArbitraryNodeParenthesizedLambdaExpression() - { - // code equivalent to an expression synthesized like so: - // ParenthesizedExpression(ParenthesizedLambdaExpression(ParameterList(), Block())) - var code = @"(()=>{})"; - var node = SyntaxFactory.ParseExpression(code); - var expected = @"(() => { })"; - AssertFormatOnArbitraryNode(node, expected); - } - - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/57465")] - public async Task FormatLambdaWithDirective() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/11642")] + public void FormatArbitraryNodeParenthesizedLambdaExpression() + { + // code equivalent to an expression synthesized like so: + // ParenthesizedExpression(ParenthesizedLambdaExpression(ParameterList(), Block())) + var code = @"(()=>{})"; + var node = SyntaxFactory.ParseExpression(code); + var expected = @"(() => { })"; + AssertFormatOnArbitraryNode(node, expected); + } + + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/57465")] + public async Task FormatLambdaWithDirective() + { + var code = """ namespace N { public class C @@ -1787,7 +1787,7 @@ protected void Render() } } """; - var expected = """ + var expected = """ namespace N { public class C @@ -1810,13 +1810,13 @@ protected void Render() } """; - await AssertFormatAsync(expected, code, spans: null); - } + await AssertFormatAsync(expected, code, spans: null); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/57465")] - public async Task FormatLambdaWithComment() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/57465")] + public async Task FormatLambdaWithComment() + { + var code = """ namespace N { public class C @@ -1837,7 +1837,7 @@ protected void Render() } } """; - var expected = """ + var expected = """ namespace N { public class C @@ -1859,31 +1859,31 @@ protected void Render() } """; - await AssertFormatAsync(expected, code, spans: null); - } + await AssertFormatAsync(expected, code, spans: null); + } - [WpfTheory] - [CombinatorialData] - [WorkItem("https://github.com/dotnet/roslyn/issues/59637")] - public async Task FormatAttributeAtEndOfFile(bool trailingNewLine) - { - var endOfFile = trailingNewLine ? Environment.NewLine : ""; - var code = $@"using System.Diagnostics.CodeAnalysis; + [WpfTheory] + [CombinatorialData] + [WorkItem("https://github.com/dotnet/roslyn/issues/59637")] + public async Task FormatAttributeAtEndOfFile(bool trailingNewLine) + { + var endOfFile = trailingNewLine ? Environment.NewLine : ""; + var code = $@"using System.Diagnostics.CodeAnalysis; [assembly:SuppressMessage(""Globalization"", ""CA1308: Normalize strings to uppercase"", Justification = ""My reason"", Scope = ""member"", Target = ""~M:Method"") ] {endOfFile}"; - var expected = $@"using System.Diagnostics.CodeAnalysis; + var expected = $@"using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage(""Globalization"", ""CA1308: Normalize strings to uppercase"", Justification = ""My reason"", Scope = ""member"", Target = ""~M:Method"")]{endOfFile}"; - await AssertFormatAsync(expected, code, spans: null); - await AssertFormatAsync(expected, expected, spans: null); - } + await AssertFormatAsync(expected, code, spans: null); + await AssertFormatAsync(expected, expected, spans: null); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff1() - { - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff1() + { + var code = + """ class Program { void M() @@ -1894,8 +1894,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -1906,14 +1906,14 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff2() - { - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff2() + { + var code = + """ class Program { void M() @@ -1924,8 +1924,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -1936,15 +1936,15 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff3() - { - // We only smart indent the { if it's on it's own line. - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff3() + { + // We only smart indent the { if it's on it's own line. + var code = + """ class Program { void M() @@ -1954,8 +1954,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -1965,15 +1965,15 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff4() - { - // We only smart indent the { if it's on it's own line. - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff4() + { + // We only smart indent the { if it's on it's own line. + var code = + """ class Program { void M() @@ -1983,8 +1983,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -1994,15 +1994,15 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff5() - { - // Typing the { should not affect the formating of the preceding tokens. - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff5() + { + // Typing the { should not affect the formating of the preceding tokens. + var code = + """ class Program { void M() @@ -2013,8 +2013,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -2025,15 +2025,15 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff6() - { - // Typing the { should not affect the formating of the preceding tokens. - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff6() + { + // Typing the { should not affect the formating of the preceding tokens. + var code = + """ class Program { void M() @@ -2043,8 +2043,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -2054,14 +2054,14 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff7() - { - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentOpenBraceEvenWithFormatWhileTypingOff7() + { + var code = + """ class Program { void M() @@ -2069,8 +2069,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -2078,14 +2078,14 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff1() - { - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff1() + { + var code = + """ class Program { void M() @@ -2097,8 +2097,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -2110,15 +2110,15 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff2() - { - // Note that the { is not updated since we are not formatting. - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff2() + { + // Note that the { is not updated since we are not formatting. + var code = + """ class Program { void M() @@ -2129,8 +2129,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -2141,14 +2141,14 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff3() - { - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff3() + { + var code = + """ class Program { void M() @@ -2157,8 +2157,8 @@ void M() } """; - var expected = - """ + var expected = + """ class Program { void M() @@ -2167,15 +2167,15 @@ void M() } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] - public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff4() - { - // Should not affect formatting of open brace - var code = - """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30787")] + public void DoSmartIndentCloseBraceEvenWithFormatWhileTypingOff4() + { + // Should not affect formatting of open brace + var code = + """ class Program { void M() { @@ -2183,8 +2183,8 @@ void M() { } """; - var expected = - """ + var expected = + """ class Program { void M() { @@ -2192,13 +2192,13 @@ void M() { } """; - AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); - } + AssertFormatAfterTypeChar(code, expected, SmartIndentButDoNotFormatWhileTyping()); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/31907")] - public async Task NullableReferenceTypes() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/31907")] + public async Task NullableReferenceTypes() + { + var code = """ [| class MyClass { @@ -2209,7 +2209,7 @@ void MyMethod() } |] """; - var expected = """ + var expected = """ class MyClass { @@ -2221,38 +2221,38 @@ void MyMethod() """; - await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); - } + await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30518")] - public void FormatGeneratedNodeInInitializer() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/30518")] + public void FormatGeneratedNodeInInitializer() + { + var code = """ new bool[] { true, true } """; - var expected = """ + var expected = """ new bool[] { true, true == false, true } """; - var tree = SyntaxFactory.ParseSyntaxTree(code, options: TestOptions.Script); - var root = tree.GetRoot(); + var tree = SyntaxFactory.ParseSyntaxTree(code, options: TestOptions.Script); + var root = tree.GetRoot(); - var entry = SyntaxFactory.BinaryExpression(SyntaxKind.EqualsExpression, SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression), SyntaxFactory.LiteralExpression(SyntaxKind.FalseLiteralExpression)); - var newRoot = root.InsertNodesBefore(root.DescendantNodes().Last(), new[] { entry }); - AssertFormatOnArbitraryNode(newRoot, expected); - } + var entry = SyntaxFactory.BinaryExpression(SyntaxKind.EqualsExpression, SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression), SyntaxFactory.LiteralExpression(SyntaxKind.FalseLiteralExpression)); + var newRoot = root.InsertNodesBefore(root.DescendantNodes().Last(), new[] { entry }); + AssertFormatOnArbitraryNode(newRoot, expected); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27268")] - public async Task PositionalPattern() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/27268")] + public async Task PositionalPattern() + { + var code = """ [| class MyClass { @@ -2267,7 +2267,7 @@ void MyMethod() } |] """; - var expected = """ + var expected = """ class MyClass { @@ -2283,13 +2283,13 @@ void MyMethod() """; - await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); - } + await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); + } - [WpfFact] - public async Task WithExpression() - { - var code = """ + [WpfFact] + public async Task WithExpression() + { + var code = """ [| record C(int Property) { @@ -2300,7 +2300,7 @@ void M() } |] """; - var expected = """ + var expected = """ record C(int Property) { @@ -2312,13 +2312,13 @@ void M() """; - await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); - } + await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); + } - [WpfFact] - public async Task WithExpression_MultiLine() - { - var code = """ + [WpfFact] + public async Task WithExpression_MultiLine() + { + var code = """ [| record C(int Property, int Property2) { @@ -2333,7 +2333,7 @@ void M() } |] """; - var expected = """ + var expected = """ record C(int Property, int Property2) { @@ -2349,13 +2349,13 @@ void M() """; - await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); - } + await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); + } - [WpfFact] - public async Task WithExpression_MultiLine_UserPositionedBraces() - { - var code = """ + [WpfFact] + public async Task WithExpression_MultiLine_UserPositionedBraces() + { + var code = """ [| record C(int Property, int Property2) { @@ -2370,7 +2370,7 @@ void M() } |] """; - var expected = """ + var expected = """ record C(int Property, int Property2) { @@ -2386,13 +2386,13 @@ void M() """; - await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); - } + await AssertFormatWithBaseIndentAsync(expected, code, baseIndentation: 4); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - public void SeparateGroups_KeepMultipleLinesBetweenGroups() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] + public void SeparateGroups_KeepMultipleLinesBetweenGroups() + { + var code = """ $$ using System.A; using System.B; @@ -2402,7 +2402,7 @@ public void SeparateGroups_KeepMultipleLinesBetweenGroups() using MS.B; """; - var expected = """ + var expected = """ $$ using System.A; using System.B; @@ -2412,13 +2412,13 @@ public void SeparateGroups_KeepMultipleLinesBetweenGroups() using MS.B; """; - AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); - } + AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - public void SeparateGroups_KeepMultipleLinesBetweenGroups_FileScopedNamespace() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] + public void SeparateGroups_KeepMultipleLinesBetweenGroups_FileScopedNamespace() + { + var code = """ $$ namespace N; @@ -2430,7 +2430,7 @@ namespace N; using MS.B; """; - var expected = """ + var expected = """ $$ namespace N; @@ -2442,13 +2442,13 @@ namespace N; using MS.B; """; - AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); - } + AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - public void SeparateGroups_DoNotGroupIfNotSorted() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] + public void SeparateGroups_DoNotGroupIfNotSorted() + { + var code = """ $$ using System.B; using System.A; @@ -2456,7 +2456,7 @@ public void SeparateGroups_DoNotGroupIfNotSorted() using MS.A; """; - var expected = """ + var expected = """ $$ using System.B; using System.A; @@ -2464,13 +2464,13 @@ public void SeparateGroups_DoNotGroupIfNotSorted() using MS.A; """; - AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); - } + AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - public void SeparateGroups_GroupIfSorted() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] + public void SeparateGroups_GroupIfSorted() + { + var code = """ $$ using System.A; using System.B; @@ -2478,7 +2478,7 @@ public void SeparateGroups_GroupIfSorted() using MS.B; """; - var expected = """ + var expected = """ $$ using System.A; using System.B; @@ -2487,13 +2487,13 @@ public void SeparateGroups_GroupIfSorted() using MS.B; """; - AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); - } + AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] - public void SeparateGroups_GroupIfSorted_RecognizeSystemNotFirst() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/25003")] + public void SeparateGroups_GroupIfSorted_RecognizeSystemNotFirst() + { + var code = """ $$ using MS.A; using MS.B; @@ -2501,7 +2501,7 @@ public void SeparateGroups_GroupIfSorted_RecognizeSystemNotFirst() using System.B; """; - var expected = """ + var expected = """ $$ using MS.A; using MS.B; @@ -2510,13 +2510,13 @@ public void SeparateGroups_GroupIfSorted_RecognizeSystemNotFirst() using System.B; """; - AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); - } + AssertFormatWithView(expected, code, new OptionsCollection(LanguageNames.CSharp) { { GenerationOptions.SeparateImportDirectiveGroups, true } }); + } - [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/58157")] - public void FormatImplicitObjectCollection() - { - var code = """ + [WpfFact, WorkItem("https://github.com/dotnet/roslyn/issues/58157")] + public void FormatImplicitObjectCollection() + { + var code = """ class Program { static void Main(string[] args) @@ -2529,7 +2529,7 @@ static void Main(string[] args) } """; - var expected = """ + var expected = """ class Program { static void Main(string[] args) @@ -2542,13 +2542,13 @@ static void Main(string[] args) } """; - AssertFormatWithView(expected, code); - } + AssertFormatWithView(expected, code); + } - [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49492")] - public void PreserveAnnotationsOnMultiLineTrivia() - { - var text = """ + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/49492")] + public void PreserveAnnotationsOnMultiLineTrivia() + { + var text = """ namespace TestApp { class Test @@ -2558,29 +2558,29 @@ class Test } """; - var position = text.IndexOf("/* __marker__ */"); - var syntaxTree = CSharpSyntaxTree.ParseText(text); - var root = syntaxTree.GetRoot(); + var position = text.IndexOf("/* __marker__ */"); + var syntaxTree = CSharpSyntaxTree.ParseText(text); + var root = syntaxTree.GetRoot(); - var annotation = new SyntaxAnnotation("marker"); - var markerTrivia = root.FindTrivia(position, findInsideTrivia: true); - var annotatedMarkerTrivia = markerTrivia.WithAdditionalAnnotations(annotation); - root = root.ReplaceTrivia(markerTrivia, annotatedMarkerTrivia); + var annotation = new SyntaxAnnotation("marker"); + var markerTrivia = root.FindTrivia(position, findInsideTrivia: true); + var annotatedMarkerTrivia = markerTrivia.WithAdditionalAnnotations(annotation); + root = root.ReplaceTrivia(markerTrivia, annotatedMarkerTrivia); - using var workspace = new AdhocWorkspace(); + using var workspace = new AdhocWorkspace(); - var options = CSharpSyntaxFormattingOptions.Default; + var options = CSharpSyntaxFormattingOptions.Default; - var formattedRoot = Formatter.Format(root, workspace.Services.SolutionServices, options, CancellationToken.None); - var annotatedTrivia = formattedRoot.GetAnnotatedTrivia("marker"); + var formattedRoot = Formatter.Format(root, workspace.Services.SolutionServices, options, CancellationToken.None); + var annotatedTrivia = formattedRoot.GetAnnotatedTrivia("marker"); - Assert.Single(annotatedTrivia); - } + Assert.Single(annotatedTrivia); + } - [WpfFact] - public void FormatUserDefinedOperator() - { - var code = """ + [WpfFact] + public void FormatUserDefinedOperator() + { + var code = """ $$ class C { @@ -2589,7 +2589,7 @@ class C } """; - var expected = """ + var expected = """ $$ class C { @@ -2599,13 +2599,13 @@ class C } """; - AssertFormatWithView(expected, code); - } + AssertFormatWithView(expected, code); + } - [WpfFact] - public void FormatUserDefinedUnaryOperator() - { - var code = """ + [WpfFact] + public void FormatUserDefinedUnaryOperator() + { + var code = """ $$ class C { @@ -2614,7 +2614,7 @@ class C } """; - var expected = """ + var expected = """ $$ class C { @@ -2624,13 +2624,13 @@ class C } """; - AssertFormatWithView(expected, code); - } + AssertFormatWithView(expected, code); + } - [WpfFact] - public void FormatUserDefinedExplicitCastOperator() - { - var code = """ + [WpfFact] + public void FormatUserDefinedExplicitCastOperator() + { + var code = """ $$ class C { @@ -2639,7 +2639,7 @@ public static explicit operator C ( int x){ } """; - var expected = """ + var expected = """ $$ class C { @@ -2649,73 +2649,73 @@ public static explicit operator C(int x) } """; - AssertFormatWithView(expected, code); - } + AssertFormatWithView(expected, code); + } - [WpfFact] - public void FormatUserDefinedOperatorOnType() - { - var code = """ + [WpfFact] + public void FormatUserDefinedOperatorOnType() + { + var code = """ interface I1 { abstract static I1 operator + ( I1 x, I1 y);$$ } """; - var expected = """ + var expected = """ interface I1 { abstract static I1 operator +(I1 x, I1 y); } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void FormatUserDefinedUnaryOperatorOnType() - { - var code = """ + [WpfFact] + public void FormatUserDefinedUnaryOperatorOnType() + { + var code = """ interface I1 { abstract static I1 operator ++ ( I1 x);$$ } """; - var expected = """ + var expected = """ interface I1 { abstract static I1 operator ++(I1 x); } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void FormatUserDefinedExplicitCastOperatorOnType() - { - var code = """ + [WpfFact] + public void FormatUserDefinedExplicitCastOperatorOnType() + { + var code = """ interface I1 where T : I1 { abstract static explicit operator string ( T x);$$ } """; - var expected = """ + var expected = """ interface I1 where T : I1 { abstract static explicit operator string(T x); } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - [WpfFact] - public void FormatUserDefinedCheckedOperator() - { - var code = """ + [WpfFact] + public void FormatUserDefinedCheckedOperator() + { + var code = """ $$ class C { @@ -2724,7 +2724,7 @@ class C } """; - var expected = """ + var expected = """ $$ class C { @@ -2734,13 +2734,13 @@ class C } """; - AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); - } + AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); + } - [WpfFact] - public void FormatUserDefinedCheckedUnaryOperator() - { - var code = """ + [WpfFact] + public void FormatUserDefinedCheckedUnaryOperator() + { + var code = """ $$ class C { @@ -2749,7 +2749,7 @@ class C } """; - var expected = """ + var expected = """ $$ class C { @@ -2759,13 +2759,13 @@ class C } """; - AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); - } + AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); + } - [WpfFact] - public void FormatUserDefinedExplicitCheckedCastOperator() - { - var code = """ + [WpfFact] + public void FormatUserDefinedExplicitCheckedCastOperator() + { + var code = """ $$ class C { @@ -2774,7 +2774,7 @@ public static explicit operator checked C ( int x){ } """; - var expected = """ + var expected = """ $$ class C { @@ -2784,73 +2784,73 @@ public static explicit operator checked C(int x) } """; - AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); - } + AssertFormatWithView(expected, code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); + } - [WpfFact] - public void FormatUserDefinedCheckedOperatorOnType() - { - var code = """ + [WpfFact] + public void FormatUserDefinedCheckedOperatorOnType() + { + var code = """ interface I1 { abstract static I1 operator checked + ( I1 x, I1 y);$$ } """; - var expected = """ + var expected = """ interface I1 { abstract static I1 operator checked +(I1 x, I1 y); } """; - AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); - } + AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); + } - [WpfFact] - public void FormatUserDefinedCheckedUnaryOperatorOnType() - { - var code = """ + [WpfFact] + public void FormatUserDefinedCheckedUnaryOperatorOnType() + { + var code = """ interface I1 { abstract static I1 operator checked ++ ( I1 x);$$ } """; - var expected = """ + var expected = """ interface I1 { abstract static I1 operator checked ++(I1 x); } """; - AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); - } + AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); + } - [WpfFact] - public void FormatUserDefinedExplicitCheckedCastOperatorOnType() - { - var code = """ + [WpfFact] + public void FormatUserDefinedExplicitCheckedCastOperatorOnType() + { + var code = """ interface I1 where T : I1 { abstract static explicit operator checked string ( T x);$$ } """; - var expected = """ + var expected = """ interface I1 where T : I1 { abstract static explicit operator checked string(T x); } """; - AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); - } + AssertFormatAfterTypeChar(code, expected, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12)); + } - [WpfFact] - public void FormatUnsignedRightShift() - { - var code = """ + [WpfFact] + public void FormatUnsignedRightShift() + { + var code = """ $$ class C { @@ -2859,7 +2859,7 @@ class C } """; - var expected = """ + var expected = """ $$ class C { @@ -2869,29 +2869,29 @@ class C } """; - AssertFormatWithView(expected, code); - } + AssertFormatWithView(expected, code); + } - [WpfFact] - public void FormatCollectionExpressionAfterEquals() - { - var code = """ + [WpfFact] + public void FormatCollectionExpressionAfterEquals() + { + var code = """ $$ var v = [ 1 , 2 , 3 ] ; """; - var expected = """ + var expected = """ $$ var v = [1, 2, 3]; """; - AssertFormatWithView(expected, code); - } + AssertFormatWithView(expected, code); + } - [WpfFact] - public void FormatCollectionExpressionAfterEquals2() - { - var code = """ + [WpfFact] + public void FormatCollectionExpressionAfterEquals2() + { + var code = """ class C { void M() @@ -2901,7 +2901,7 @@ void M() } """; - var expected = """ + var expected = """ class C { void M() @@ -2911,47 +2911,46 @@ void M() } """; - AssertFormatWithView(expected, code); - } + AssertFormatWithView(expected, code); + } - [WpfFact] - public void FormatUnsignedRightShiftOnType() - { - var code = """ + [WpfFact] + public void FormatUnsignedRightShiftOnType() + { + var code = """ interface I1 { abstract static I1 operator >>> ( I1 x, I1 y);$$ } """; - var expected = """ + var expected = """ interface I1 { abstract static I1 operator >>>(I1 x, I1 y); } """; - AssertFormatAfterTypeChar(code, expected); - } + AssertFormatAfterTypeChar(code, expected); + } - private static void AssertFormatAfterTypeChar(string code, string expected, OptionsCollection? globalOptions = null, ParseOptions? parseOptions = null) - { - using var workspace = TestWorkspace.CreateCSharp(code, parseOptions: parseOptions); + private static void AssertFormatAfterTypeChar(string code, string expected, OptionsCollection? globalOptions = null, ParseOptions? parseOptions = null) + { + using var workspace = TestWorkspace.CreateCSharp(code, parseOptions: parseOptions); - var subjectDocument = workspace.Documents.Single(); + var subjectDocument = workspace.Documents.Single(); - var commandHandler = workspace.GetService(); - var typedChar = subjectDocument.GetTextBuffer().CurrentSnapshot.GetText(subjectDocument.CursorPosition!.Value - 1, 1); - var textView = subjectDocument.GetTextView(); + var commandHandler = workspace.GetService(); + var typedChar = subjectDocument.GetTextBuffer().CurrentSnapshot.GetText(subjectDocument.CursorPosition!.Value - 1, 1); + var textView = subjectDocument.GetTextView(); - globalOptions?.SetGlobalOptions(workspace.GlobalOptions); - workspace.GlobalOptions.SetEditorOptions(textView.Options.GlobalOptions, subjectDocument.Project.Language); + globalOptions?.SetGlobalOptions(workspace.GlobalOptions); + workspace.GlobalOptions.SetEditorOptions(textView.Options.GlobalOptions, subjectDocument.Project.Language); - commandHandler.ExecuteCommand(new TypeCharCommandArgs(textView, subjectDocument.GetTextBuffer(), typedChar[0]), () => { }, TestCommandExecutionContext.Create()); + commandHandler.ExecuteCommand(new TypeCharCommandArgs(textView, subjectDocument.GetTextBuffer(), typedChar[0]), () => { }, TestCommandExecutionContext.Create()); - var newSnapshot = subjectDocument.GetTextBuffer().CurrentSnapshot; + var newSnapshot = subjectDocument.GetTextBuffer().CurrentSnapshot; - AssertEx.EqualOrDiff(expected, newSnapshot.GetText()); - } + AssertEx.EqualOrDiff(expected, newSnapshot.GetText()); } }