diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs index ebbcf31da2807..31c1af4de5738 100644 --- a/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs @@ -13,46 +13,48 @@ public class SyntaxNormalizerTests [Fact, WorkItem(52543, "https://github.com/dotnet/roslyn/issues/52543")] public void TestNormalizePatternInIf() { - TestNormalizeStatement( - @"{object x = 1; - if (x is {}) - { - } - if (x is {} t) - { - } - if (x is int {} t2) - { - } - if (x is System.ValueTuple(_, _) { Item1: > 10 } t3) - { + TestNormalizeStatement(""" + {object x = 1; + if (x is {}) + { + } + if (x is {} t) + { + } + if (x is int {} t2) + { + } + if (x is System.ValueTuple(_, _) { Item1: > 10 } t3) + { + } + if (x is System.ValueTuple(_, _) { Item1: > 10, Item2: < 20 }) + { + } } - if (x is System.ValueTuple(_, _) { Item1: > 10, Item2: < 20 }) + """, """ { - } -}", - @"{ - object x = 1; - if (x is { }) - { - } + object x = 1; + if (x is { }) + { + } - if (x is { } t) - { - } + if (x is { } t) + { + } - if (x is int { } t2) - { - } + if (x is int { } t2) + { + } - if (x is System.ValueTuple (_, _) { Item1: > 10 } t3) - { - } + if (x is System.ValueTuple (_, _) { Item1: > 10 } t3) + { + } - if (x is System.ValueTuple (_, _) { Item1: > 10, Item2: < 20 }) - { - } -}".NormalizeLineEndings() + if (x is System.ValueTuple (_, _) { Item1: > 10, Item2: < 20 }) + { + } + } + """ ); } @@ -60,14 +62,15 @@ public void TestNormalizePatternInIf() public void TestNormalizeSwitchExpression() { TestNormalizeStatement( - @"var x = (int)1 switch { 1 => ""one"", 2 => ""two"", 3 => ""three"", {} => "">= 4"" };", - @"var x = (int)1 switch -{ - 1 => ""one"", - 2 => ""two"", - 3 => ""three"", - { } => "">= 4"" -};".NormalizeLineEndings() + """var x = (int)1 switch { 1 => "one", 2 => "two", 3 => "three", {} => ">= 4" };""", """ + var x = (int)1 switch + { + 1 => "one", + 2 => "two", + 3 => "three", + { } => ">= 4" + }; + """ ); } @@ -75,14 +78,15 @@ public void TestNormalizeSwitchExpression() public void TestNormalizeSwitchExpressionRawStrings() { TestNormalizeStatement( - @"var x = (int)1 switch { 1 => """"""one"""""", 2 => """"""two"""""", 3 => """"""three"""""", {} => """""">= 4"""""" };", - @"var x = (int)1 switch -{ - 1 => """"""one"""""", - 2 => """"""two"""""", - 3 => """"""three"""""", - { } => """""">= 4"""""" -};".NormalizeLineEndings() + """"var x = (int)1 switch { 1 => """one""", 2 => """two""", 3 => """three""", {} => """>= 4""" };"""", """" + var x = (int)1 switch + { + 1 => """one""", + 2 => """two""", + 3 => """three""", + { } => """>= 4""" + }; + """" ); } @@ -90,153 +94,164 @@ public void TestNormalizeSwitchExpressionRawStrings() public void TestNormalizeSwitchExpressionRawStringsUtf8_01() { TestNormalizeStatement( - @"var x = (int)1 switch { 1 => """"""one""""""u8, 2 => """"""two""""""U8, 3 => """"""three""""""u8, {} => """""">= 4""""""U8 };", - @"var x = (int)1 switch -{ - 1 => """"""one""""""u8, - 2 => """"""two""""""U8, - 3 => """"""three""""""u8, - { } => """""">= 4""""""U8 -};".NormalizeLineEndings() + """"var x = (int)1 switch { 1 => """one"""u8, 2 => """two"""U8, 3 => """three"""u8, {} => """>= 4"""U8 };"""", """" + var x = (int)1 switch + { + 1 => """one"""u8, + 2 => """two"""U8, + 3 => """three"""u8, + { } => """>= 4"""U8 + }; + """" ); } [ConditionalFact(typeof(WindowsOnly))] public void TestNormalizeSwitchExpressionRawStringsMultiline() { - TestNormalizeStatement( - @"var x = (int)1 switch { 1 => """""" - one - """""", 2 => -"""""" - two -"""""" };", - @"var x = (int)1 switch -{ - 1 => """""" - one - """""", - 2 => """""" - two -"""""" -};".NormalizeLineEndings() + TestNormalizeStatement("""" + var x = (int)1 switch { 1 => """ + one + """, 2 => + """ + two + """ }; + """", """" + var x = (int)1 switch + { + 1 => """ + one + """, + 2 => """ + two + """ + }; + """" ); } [ConditionalFact(typeof(WindowsOnly))] public void TestNormalizeSwitchExpressionRawStringsMultilineUtf8_01() { - TestNormalizeStatement( - @"var x = (int)1 switch { 1 => """""" - one - """"""U8, 2 => -"""""" - two -""""""u8 };", - @"var x = (int)1 switch -{ - 1 => """""" - one - """"""U8, - 2 => """""" - two -""""""u8 -};".NormalizeLineEndings() + TestNormalizeStatement("""" + var x = (int)1 switch { 1 => """ + one + """U8, 2 => + """ + two + """u8 }; + """", """" + var x = (int)1 switch + { + 1 => """ + one + """U8, + 2 => """ + two + """u8 + }; + """" ); } [Fact] public void TestNormalizeSwitchExpressionStringsUtf8() { - TestNormalizeStatement( - @"var x = (int)1 switch { 1 => - ""one""u8 , 2 => - @""two""u8 , 3 => - ""three""U8 , {} => -@"">= 4""U8 };", - @"var x = (int)1 switch -{ - 1 => ""one""u8, - 2 => @""two""u8, - 3 => ""three""U8, - { } => @"">= 4""U8 -};".NormalizeLineEndings() + TestNormalizeStatement(""" + var x = (int)1 switch { 1 => + "one"u8 , 2 => + @"two"u8 , 3 => + "three"U8 , {} => + @">= 4"U8 }; + """, """ + var x = (int)1 switch + { + 1 => "one"u8, + 2 => @"two"u8, + 3 => "three"U8, + { } => @">= 4"U8 + }; + """ ); } [Fact, WorkItem(52543, "https://github.com/dotnet/roslyn/issues/52543")] public void TestNormalizeSwitchRecPattern() { - TestNormalizeStatement( - @"var x = (object)1 switch { - int { } => ""two"", - { } t when t.GetHashCode() == 42 => ""42"", - System.ValueTuple (1, _) { Item2: > 2 and < 20 } => ""tuple.Item2 < 20"", - System.ValueTuple (1, _) { Item2: >= 100 } greater => greater.ToString(), - System.ValueType {} => ""not null value"", - object {} i when i is not 42 => ""not 42"", - { } => ""not null"", - null => ""null"", -};", - @"var x = (object)1 switch -{ - int { } => ""two"", - { } t when t.GetHashCode() == 42 => ""42"", - System.ValueTuple (1, _) { Item2: > 2 and < 20 } => ""tuple.Item2 < 20"", - System.ValueTuple (1, _) { Item2: >= 100 } greater => greater.ToString(), - System.ValueType { } => ""not null value"", - object { } i when i is not 42 => ""not 42"", - { } => ""not null"", - null => ""null"", -};".NormalizeLineEndings() + TestNormalizeStatement(""" + var x = (object)1 switch { + int { } => "two", + { } t when t.GetHashCode() == 42 => "42", + System.ValueTuple (1, _) { Item2: > 2 and < 20 } => "tuple.Item2 < 20", + System.ValueTuple (1, _) { Item2: >= 100 } greater => greater.ToString(), + System.ValueType {} => "not null value", + object {} i when i is not 42 => "not 42", + { } => "not null", + null => "null", + }; + """, """ + var x = (object)1 switch + { + int { } => "two", + { } t when t.GetHashCode() == 42 => "42", + System.ValueTuple (1, _) { Item2: > 2 and < 20 } => "tuple.Item2 < 20", + System.ValueTuple (1, _) { Item2: >= 100 } greater => greater.ToString(), + System.ValueType { } => "not null value", + object { } i when i is not 42 => "not 42", + { } => "not null", + null => "null", + }; + """ ); } [Fact, WorkItem(52543, "https://github.com/dotnet/roslyn/issues/52543")] public void TestNormalizeSwitchExpressionComplex() { - var a = @"var x = vehicle switch - { - Car { Passengers: 0 } => 2.00m + 0.50m, - Car { Passengers: 1 } => 2.0m, - Car { Passengers: 2 } => 2.0m - 0.50m, - Car c => 2.00m - 1.0m, - - Taxi { Fares: 0 } => 3.50m + 1.00m, - Taxi { Fares: 1 } => 3.50m, - Taxi { Fares: 2 } => 3.50m - 0.50m, - Taxi t => 3.50m - 1.00m, - - Bus b when ((double)b.Riders / (double)b.Capacity) < 0.50 => 5.00m + 2.00m, - Bus b when ((double)b.Riders / (double)b.Capacity) > 0.90 => 5.00m - 1.00m, - Bus b => 5.00m, - - DeliveryTruck t when (t.GrossWeightClass > 5000) => 10.00m + 5.00m, - DeliveryTruck t when (t.GrossWeightClass < 3000) => 10.00m - 2.00m, - DeliveryTruck t => 10.00m, - { } => -1, //throw new ArgumentException(message: ""Not a known vehicle type"", paramName: nameof(vehicle)), - null => 0//throw new ArgumentNullException(nameof(vehicle)) - };"; - var b = @"var x = vehicle switch -{ - Car { Passengers: 0 } => 2.00m + 0.50m, - Car { Passengers: 1 } => 2.0m, - Car { Passengers: 2 } => 2.0m - 0.50m, - Car c => 2.00m - 1.0m, - Taxi { Fares: 0 } => 3.50m + 1.00m, - Taxi { Fares: 1 } => 3.50m, - Taxi { Fares: 2 } => 3.50m - 0.50m, - Taxi t => 3.50m - 1.00m, - Bus b when ((double)b.Riders / (double)b.Capacity) < 0.50 => 5.00m + 2.00m, - Bus b when ((double)b.Riders / (double)b.Capacity) > 0.90 => 5.00m - 1.00m, - Bus b => 5.00m, - DeliveryTruck t when (t.GrossWeightClass > 5000) => 10.00m + 5.00m, - DeliveryTruck t when (t.GrossWeightClass < 3000) => 10.00m - 2.00m, - DeliveryTruck t => 10.00m, - { } => -1, //throw new ArgumentException(message: ""Not a known vehicle type"", paramName: nameof(vehicle)), - null => 0 //throw new ArgumentNullException(nameof(vehicle)) -};".NormalizeLineEndings(); - TestNormalizeStatement(a, b); + TestNormalizeStatement(""" + var x = vehicle switch + { + Car { Passengers: 0 } => 2.00m + 0.50m, + Car { Passengers: 1 } => 2.0m, + Car { Passengers: 2 } => 2.0m - 0.50m, + Car c => 2.00m - 1.0m, + + Taxi { Fares: 0 } => 3.50m + 1.00m, + Taxi { Fares: 1 } => 3.50m, + Taxi { Fares: 2 } => 3.50m - 0.50m, + Taxi t => 3.50m - 1.00m, + + Bus b when ((double)b.Riders / (double)b.Capacity) < 0.50 => 5.00m + 2.00m, + Bus b when ((double)b.Riders / (double)b.Capacity) > 0.90 => 5.00m - 1.00m, + Bus b => 5.00m, + + DeliveryTruck t when (t.GrossWeightClass > 5000) => 10.00m + 5.00m, + DeliveryTruck t when (t.GrossWeightClass < 3000) => 10.00m - 2.00m, + DeliveryTruck t => 10.00m, + { } => -1, //throw new ArgumentException(message: "Not a known vehicle type", paramName: nameof(vehicle)), + null => 0//throw new ArgumentNullException(nameof(vehicle)) + }; + """, """ + var x = vehicle switch + { + Car { Passengers: 0 } => 2.00m + 0.50m, + Car { Passengers: 1 } => 2.0m, + Car { Passengers: 2 } => 2.0m - 0.50m, + Car c => 2.00m - 1.0m, + Taxi { Fares: 0 } => 3.50m + 1.00m, + Taxi { Fares: 1 } => 3.50m, + Taxi { Fares: 2 } => 3.50m - 0.50m, + Taxi t => 3.50m - 1.00m, + Bus b when ((double)b.Riders / (double)b.Capacity) < 0.50 => 5.00m + 2.00m, + Bus b when ((double)b.Riders / (double)b.Capacity) > 0.90 => 5.00m - 1.00m, + Bus b => 5.00m, + DeliveryTruck t when (t.GrossWeightClass > 5000) => 10.00m + 5.00m, + DeliveryTruck t when (t.GrossWeightClass < 3000) => 10.00m - 2.00m, + DeliveryTruck t => 10.00m, + { } => -1, //throw new ArgumentException(message: "Not a known vehicle type", paramName: nameof(vehicle)), + null => 0 //throw new ArgumentNullException(nameof(vehicle)) + }; + """); } [Fact] @@ -266,56 +281,66 @@ public void TestNormalizeListPattern_EmptyList() [Fact, WorkItem(50742, "https://github.com/dotnet/roslyn/issues/50742")] public void TestLineBreakInterpolations() { - TestNormalizeExpression( - @"$""Printed: { new Printer() { TextToPrint = ""Hello world!"" }.PrintedText }""", - @"$""Printed: {new Printer() { TextToPrint = ""Hello world!"" }.PrintedText}""" + TestNormalizeExpression(""" + $"Printed: { new Printer() { TextToPrint = "Hello world!" }.PrintedText }" + """, """ + $"Printed: {new Printer() { TextToPrint = "Hello world!" }.PrintedText}" + """ ); } [Fact] public void TestLineBreakRawInterpolations() { - TestNormalizeExpression( - @"$""""""Printed: { new Printer() { TextToPrint = ""Hello world!"" }.PrintedText }""""""", - @"$""""""Printed: {new Printer() { TextToPrint = ""Hello world!"" }.PrintedText}""""""" + TestNormalizeExpression("""" + $"""Printed: { new Printer() { TextToPrint = "Hello world!" }.PrintedText }""" + """", """" + $"""Printed: {new Printer() { TextToPrint = "Hello world!" }.PrintedText}""" + """" ); } [Fact, WorkItem(50742, "https://github.com/dotnet/roslyn/issues/50742")] public void TestVerbatimStringInterpolationWithLineBreaks() { - TestNormalizeStatement(@"Console.WriteLine($@""Test with line -breaks -{ - new[]{ - 1, 2, 3 - }[2] -} - "");", - @"Console.WriteLine($@""Test with line -breaks -{new[] { 1, 2, 3 }[2]} - "");" + TestNormalizeStatement(""" + Console.WriteLine($@"Test with line + breaks + { + new[]{ + 1, 2, 3 + }[2] + } + "); + """, """ + Console.WriteLine($@"Test with line + breaks + {new[] { 1, 2, 3 }[2]} + "); + """ ); } [Fact] public void TestRawStringInterpolationWithLineBreaks() { - TestNormalizeStatement(@"Console.WriteLine($"""""" - Test with line - breaks - { - new[]{ - 1, 2, 3 - }[2] - } - """""");", - @"Console.WriteLine($"""""" - Test with line - breaks - {new[] { 1, 2, 3 }[2]} - """""");" + TestNormalizeStatement("""" + Console.WriteLine($""" + Test with line + breaks + { + new[]{ + 1, 2, 3 + }[2] + } + """); + """", """" + Console.WriteLine($""" + Test with line + breaks + {new[] { 1, 2, 3 }[2]} + """); + """" ); } @@ -364,7 +389,12 @@ public void TestNormalizeExpression1() TestNormalizeExpression("m(a,b(c,d))", "m(a, b(c, d))"); TestNormalizeExpression("a?b:c", "a ? b : c"); - TestNormalizeExpression("from a in b where c select d", "from a in b\r\nwhere c\r\nselect d"); + TestNormalizeExpression( + "from a in b where c select d", """ + from a in b + where c + select d + """); TestNormalizeExpression("a().b().c()", "a().b().c()"); TestNormalizeExpression("a->b->c", "a->b->c"); @@ -377,9 +407,9 @@ public void TestNormalizeExpression1() TestNormalizeExpression("(IList)args", "(IList)args"); } - private void TestNormalizeExpression(string text, string expected) + private static void TestNormalizeExpression(string text, string expected) { - var node = SyntaxFactory.ParseExpression(text); + var node = SyntaxFactory.ParseExpression(text.NormalizeLineEndings()); var actual = node.NormalizeWhitespace(" ").ToFullString(); Assert.Equal(expected.NormalizeLineEndings(), actual.NormalizeLineEndings()); } @@ -391,43 +421,173 @@ public void TestNormalizeStatement1() TestNormalizeStatement("a;", "a;"); // blocks - TestNormalizeStatement("{a;}", "{\r\n a;\r\n}"); - TestNormalizeStatement("{a;b;}", "{\r\n a;\r\n b;\r\n}"); - TestNormalizeStatement("\t{a;}", "{\r\n a;\r\n}"); - TestNormalizeStatement("\t{a;b;}", "{\r\n a;\r\n b;\r\n}"); + TestNormalizeStatement( + "{a;}", """ + { + a; + } + """); + TestNormalizeStatement( + "{a;b;}", """ + { + a; + b; + } + """); + TestNormalizeStatement( + "\t{a;}", """ + { + a; + } + """); + TestNormalizeStatement( + "\t{a;b;}", """ + { + a; + b; + } + """); // if - TestNormalizeStatement("if(a)b;", "if (a)\r\n b;"); - TestNormalizeStatement("if(a){b;}", "if (a)\r\n{\r\n b;\r\n}"); - TestNormalizeStatement("if(a){b;c;}", "if (a)\r\n{\r\n b;\r\n c;\r\n}"); - TestNormalizeStatement("if(a)b;else c;", "if (a)\r\n b;\r\nelse\r\n c;"); - TestNormalizeStatement("if(a)b;else if(c)d;", "if (a)\r\n b;\r\nelse if (c)\r\n d;"); + TestNormalizeStatement( + "if(a)b;", """ + if (a) + b; + """); + TestNormalizeStatement( + "if(a){b;}", """ + if (a) + { + b; + } + """); + TestNormalizeStatement( + "if(a){b;c;}", """ + if (a) + { + b; + c; + } + """); + TestNormalizeStatement( + "if(a)b;else c;", """ + if (a) + b; + else + c; + """); + TestNormalizeStatement( + "if(a)b;else if(c)d;", """ + if (a) + b; + else if (c) + d; + """); // while - TestNormalizeStatement("while(a)b;", "while (a)\r\n b;"); - TestNormalizeStatement("while(a){b;}", "while (a)\r\n{\r\n b;\r\n}"); + TestNormalizeStatement( + "while(a)b;", """ + while (a) + b; + """); + TestNormalizeStatement( + "while(a){b;}", """ + while (a) + { + b; + } + """); // do - TestNormalizeStatement("do{a;}while(b);", "do\r\n{\r\n a;\r\n}\r\nwhile (b);"); + TestNormalizeStatement( + "do{a;}while(b);", """ + do + { + a; + } + while (b); + """); // for - TestNormalizeStatement("for(a;b;c)d;", "for (a; b; c)\r\n d;"); - TestNormalizeStatement("for(;;)a;", "for (;;)\r\n a;"); + TestNormalizeStatement( + "for(a;b;c)d;", """ + for (a; b; c) + d; + """); + TestNormalizeStatement( + "for(;;)a;", """ + for (;;) + a; + """); // foreach - TestNormalizeStatement("foreach(a in b)c;", "foreach (a in b)\r\n c;"); + TestNormalizeStatement( + "foreach(a in b)c;", """ + foreach (a in b) + c; + """); // try - TestNormalizeStatement("try{a;}catch(b){c;}", "try\r\n{\r\n a;\r\n}\r\ncatch (b)\r\n{\r\n c;\r\n}"); - TestNormalizeStatement("try{a;}finally{b;}", "try\r\n{\r\n a;\r\n}\r\nfinally\r\n{\r\n b;\r\n}"); + TestNormalizeStatement( + "try{a;}catch(b){c;}", """ + try + { + a; + } + catch (b) + { + c; + } + """); + TestNormalizeStatement( + "try{a;}finally{b;}", """ + try + { + a; + } + finally + { + b; + } + """); // other - TestNormalizeStatement("lock(a)b;", "lock (a)\r\n b;"); - TestNormalizeStatement("fixed(a)b;", "fixed (a)\r\n b;"); - TestNormalizeStatement("using(a)b;", "using (a)\r\n b;"); - TestNormalizeStatement("checked{a;}", "checked\r\n{\r\n a;\r\n}"); - TestNormalizeStatement("unchecked{a;}", "unchecked\r\n{\r\n a;\r\n}"); - TestNormalizeStatement("unsafe{a;}", "unsafe\r\n{\r\n a;\r\n}"); + TestNormalizeStatement( + "lock(a)b;", """ + lock (a) + b; + """); + TestNormalizeStatement( + "fixed(a)b;", """ + fixed (a) + b; + """); + TestNormalizeStatement( + "using(a)b;", """ + using (a) + b; + """); + TestNormalizeStatement( + "checked{a;}", """ + checked + { + a; + } + """); + TestNormalizeStatement( + "unchecked{a;}", """ + unchecked + { + a; + } + """); + TestNormalizeStatement( + "unsafe{a;}", """ + unsafe + { + a; + } + """); // declaration statements TestNormalizeStatement("a b;", "a b;"); @@ -438,11 +598,25 @@ public void TestNormalizeStatement1() // empty statements TestNormalizeStatement(";", ";"); - TestNormalizeStatement("{;;}", "{\r\n ;\r\n ;\r\n}"); + TestNormalizeStatement( + "{;;}", """ + { + ; + ; + } + """); // labelled statements - TestNormalizeStatement("goo:;", "goo:\r\n ;"); - TestNormalizeStatement("goo:a;", "goo:\r\n a;"); + TestNormalizeStatement( + "goo:;", """ + goo: + ; + """); + TestNormalizeStatement( + "goo:a;", """ + goo: + a; + """); // return/goto TestNormalizeStatement("return;", "return;"); @@ -458,70 +632,204 @@ public void TestNormalizeStatement1() TestNormalizeStatement("return this.Bar()", "return this.Bar()"); // switch - TestNormalizeStatement("switch(a){case b:c;}", "switch (a)\r\n{\r\n case b:\r\n c;\r\n}"); - TestNormalizeStatement("switch(a){case b:c;case d:e;}", "switch (a)\r\n{\r\n case b:\r\n c;\r\n case d:\r\n e;\r\n}"); - TestNormalizeStatement("switch(a){case b:c;default:d;}", "switch (a)\r\n{\r\n case b:\r\n c;\r\n default:\r\n d;\r\n}"); - TestNormalizeStatement("switch(a){case b:{}default:{}}", "switch (a)\r\n{\r\n case b:\r\n {\r\n }\r\n\r\n default:\r\n {\r\n }\r\n}"); - TestNormalizeStatement("switch(a){case b:c();d();default:e();f();}", "switch (a)\r\n{\r\n case b:\r\n c();\r\n d();\r\n default:\r\n e();\r\n f();\r\n}"); - TestNormalizeStatement("switch(a){case b:{c();}}", "switch (a)\r\n{\r\n case b:\r\n {\r\n c();\r\n }\r\n}"); + TestNormalizeStatement( + "switch(a){case b:c;}", """ + switch (a) + { + case b: + c; + } + """); + TestNormalizeStatement( + "switch(a){case b:c;case d:e;}", """ + switch (a) + { + case b: + c; + case d: + e; + } + """); + TestNormalizeStatement( + "switch(a){case b:c;default:d;}", """ + switch (a) + { + case b: + c; + default: + d; + } + """); + TestNormalizeStatement( + "switch(a){case b:{}default:{}}", """ + switch (a) + { + case b: + { + } + + default: + { + } + } + """); + TestNormalizeStatement( + "switch(a){case b:c();d();default:e();f();}", """ + switch (a) + { + case b: + c(); + d(); + default: + e(); + f(); + } + """); + TestNormalizeStatement( + "switch(a){case b:{c();}}", """ + switch (a) + { + case b: + { + c(); + } + } + """); // curlies - TestNormalizeStatement("{if(goo){}if(bar){}}", "{\r\n if (goo)\r\n {\r\n }\r\n\r\n if (bar)\r\n {\r\n }\r\n}"); + TestNormalizeStatement( + "{if(goo){}if(bar){}}", """ + { + if (goo) + { + } + + if (bar) + { + } + } + """); // Queries - TestNormalizeStatement("int i=from v in vals select v;", "int i =\r\n from v in vals\r\n select v;"); - TestNormalizeStatement("Goo(from v in vals select v);", "Goo(\r\n from v in vals\r\n select v);"); - TestNormalizeStatement("int i=from v in vals select from x in xxx where x > 10 select x;", "int i =\r\n from v in vals\r\n select\r\n from x in xxx\r\n where x > 10\r\n select x;"); - TestNormalizeStatement("int i=from v in vals group v by x into g where g > 10 select g;", "int i =\r\n from v in vals\r\n group v by x into g\r\n where g > 10\r\n select g;"); + TestNormalizeStatement( + "int i=from v in vals select v;", """ + int i = + from v in vals + select v; + """); + TestNormalizeStatement( + "Goo(from v in vals select v);", """ + Goo( + from v in vals + select v); + """); + TestNormalizeStatement( + "int i=from v in vals select from x in xxx where x > 10 select x;", """ + int i = + from v in vals + select + from x in xxx + where x > 10 + select x; + """); + TestNormalizeStatement( + "int i=from v in vals group v by x into g where g > 10 select g;", """ + int i = + from v in vals + group v by x into g + where g > 10 + select g; + """); // Generics TestNormalizeStatement("Func f = blah;", "Func f = blah;"); } - [Theory] - [InlineData("[ return:A ]void Local( [ B ]object o){}", "[return: A]\r\nvoid Local([B] object o)\r\n{\r\n}")] - [InlineData("[A,B][C]T Local()=>default;", "[A, B]\r\n[C]\r\nT Local() => default;")] - public void TestLocalFunctionAttributes(string text, string expected) + [Fact] + public void TestLocalFunctionAttributes() { - TestNormalizeStatement(text, expected); + TestNormalizeStatement( + "[ return:A ]void Local( [ B ]object o){}", """ + [return: A] + void Local([B] object o) + { + } + """); + TestNormalizeStatement( + "[A,B][C]T Local()=>default;", """ + [A, B] + [C] + T Local() => default; + """); } - [Theory] - [InlineData("( [ A ]x)=>x", "([A] x) => x")] - [InlineData("( [ A ]int x=1)=>x", "([A] int x = 1) => x")] - [InlineData("[return:A]([B]object o)=>{}", "[return: A]\r\n([B] object o) =>\r\n{\r\n}")] - [InlineData("[ A ,B ] [C]()=>x", "[A, B]\r\n[C]\r\n() => x")] - [InlineData("[A]B()=>{ }", "[A]\r\nB() =>\r\n{\r\n}")] - [WorkItem(59653, "https://github.com/dotnet/roslyn/issues/59653")] - public void TestLambdaAttributes(string text, string expected) + [Fact, WorkItem(59653, "https://github.com/dotnet/roslyn/issues/59653")] + public void TestLambdaAttributes() { - TestNormalizeExpression(text, expected); + TestNormalizeExpression("( [ A ]x)=>x", "([A] x) => x"); + TestNormalizeExpression("( [ A ]int x=1)=>x", "([A] int x = 1) => x"); + TestNormalizeExpression( + "[return:A]([B]object o)=>{}", """ + [return: A] + ([B] object o) => + { + } + """); + TestNormalizeExpression( + "[ A ,B ] [C]()=>x", """ + [A, B] + [C] + () => x + """); + TestNormalizeExpression( + "[A]B()=>{ }", """ + [A] + B() => + { + } + """); } - [Theory] - [InlineData("int( x )=>x", "int (x) => x")] - [InlineData("A( B b )=>{}", "A(B b) =>\r\n{\r\n}")] - [InlineData("static\r\nasync\r\nA()=>x", "static async A() => x")] - [WorkItem(59653, "https://github.com/dotnet/roslyn/issues/59653")] - public void TestLambdaReturnType(string text, string expected) + [Fact, WorkItem(59653, "https://github.com/dotnet/roslyn/issues/59653")] + public void TestLambdaReturnType() { - TestNormalizeExpression(text, expected); + TestNormalizeExpression("int( x )=>x", "int (x) => x"); + TestNormalizeExpression( + "A( B b )=>{}", """ + A(B b) => + { + } + """); + TestNormalizeExpression(""" + static + async + A()=>x + """, + "static async A() => x"); } - [Theory] - [InlineData("( int x=1 )=>x", "(int x = 1) => x")] - [InlineData("(int x = 1,int y,int z=2)=>{}", "(int x = 1, int y, int z = 2) =>\r\n{\r\n}")] - public void TestLambdaOptionalParameters(string text, string expected) + [Fact] + public void TestLambdaOptionalParameters() { - TestNormalizeExpression(text, expected); + TestNormalizeExpression("( int x=1 )=>x", "(int x = 1) => x"); + TestNormalizeExpression( + "(int x = 1,int y,int z=2)=>{}", """ + (int x = 1, int y, int z = 2) => + { + } + """); } - [Theory] - [InlineData("( params int []xs)=>xs.Length", "(params int[] xs) => xs.Length")] - [InlineData("(int x = 1,int y,int z=2,params int []xs)=>{}", "(int x = 1, int y, int z = 2, params int[] xs) =>\r\n{\r\n}")] - public void TestLambdaParamsArray(string text, string expected) + [Fact] + public void TestLambdaParamsArray() { - TestNormalizeExpression(text, expected); + TestNormalizeExpression("( params int []xs)=>xs.Length", "(params int[] xs) => xs.Length"); + TestNormalizeExpression( + "(int x = 1,int y,int z=2,params int []xs)=>{}", """ + (int x = 1, int y, int z = 2, params int[] xs) => + { + } + """); } [Theory] @@ -539,38 +847,41 @@ public void TestNormalizeAsteriskInPointerDeclaration(string text, string expect TestNormalizeStatement(text, expected); } - [Fact] - [WorkItem(49733, "https://github.com/dotnet/roslyn/issues/49733")] + [Fact, WorkItem(49733, "https://github.com/dotnet/roslyn/issues/49733")] public void TestNormalizeAsteriskInPointerReturnTypeOfIndexer() { - var text = @"public unsafe class C -{ - int*this[int x,int y]{get=>(int*)0;} -}"; - var expected = @"public unsafe class C -{ - int* this[int x, int y] { get => (int*)0; } -}"; - TestNormalizeDeclaration(text, expected); + TestNormalizeDeclaration(""" + public unsafe class C + { + int*this[int x,int y]{get=>(int*)0;} + } + """, """ + public unsafe class C + { + int* this[int x, int y] { get => (int*)0; } + } + """); } [Fact] public void TestNormalizeAsteriskInVoidPointerCast() { - var text = @"public unsafe class C -{ - void*this[int x,int y]{get => ( void * ) 0;} -}"; - var expected = @"public unsafe class C -{ - void* this[int x, int y] { get => (void*)0; } -}"; - TestNormalizeDeclaration(text, expected); + TestNormalizeDeclaration(""" + public unsafe class C + { + void*this[int x,int y]{get => ( void * ) 0;} + } + """, """ + public unsafe class C + { + void* this[int x, int y] { get => (void*)0; } + } + """); } - private void TestNormalizeStatement(string text, string expected) + private static void TestNormalizeStatement(string text, string expected) { - var node = SyntaxFactory.ParseStatement(text); + var node = SyntaxFactory.ParseStatement(text.NormalizeLineEndings()); var actual = node.NormalizeWhitespace(" ").ToFullString(); Assert.Equal(expected.NormalizeLineEndings(), actual.NormalizeLineEndings()); } @@ -582,114 +893,1262 @@ public void TestNormalizeDeclaration1() TestNormalizeDeclaration("using a;", "using a;"); TestNormalizeDeclaration("using a=b;", "using a = b;"); TestNormalizeDeclaration("using a.b;", "using a.b;"); - TestNormalizeDeclaration("using A; using B; class C {}", "using A;\r\nusing B;\r\n\r\nclass C\r\n{\r\n}"); + TestNormalizeDeclaration( + "using A; using B; class C {}", """ + using A; + using B; + + class C + { + } + """); TestNormalizeDeclaration("global using a;", "global using a;"); TestNormalizeDeclaration("global using a=b;", "global using a = b;"); TestNormalizeDeclaration("global using a.b;", "global using a.b;"); - TestNormalizeDeclaration("global using A; global using B; class C {}", "global using A;\r\nglobal using B;\r\n\r\nclass C\r\n{\r\n}"); - TestNormalizeDeclaration("global using A; using B; class C {}", "global using A;\r\nusing B;\r\n\r\nclass C\r\n{\r\n}"); - TestNormalizeDeclaration("using A; global using B; class C {}", "using A;\r\nglobal using B;\r\n\r\nclass C\r\n{\r\n}"); + TestNormalizeDeclaration( + "global using A; global using B; class C {}", """ + global using A; + global using B; - // namespace - TestNormalizeDeclaration("namespace a{}", "namespace a\r\n{\r\n}"); - TestNormalizeDeclaration("namespace a{using b;}", "namespace a\r\n{\r\n using b;\r\n}"); - TestNormalizeDeclaration("namespace a{global using b;}", "namespace a\r\n{\r\n global using b;\r\n}"); - TestNormalizeDeclaration("namespace a{namespace b{}}", "namespace a\r\n{\r\n namespace b\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("namespace a{}namespace b{}", "namespace a\r\n{\r\n}\r\n\r\nnamespace b\r\n{\r\n}"); + class C + { + } + """); + TestNormalizeDeclaration( + "global using A; using B; class C {}", """ + global using A; + using B; + + class C + { + } + """); + TestNormalizeDeclaration( + "using A; global using B; class C {}", """ + using A; + global using B; + + class C + { + } + """); + + // namespace + TestNormalizeDeclaration( + "namespace a{}", """ + namespace a + { + } + """); + TestNormalizeDeclaration( + "namespace a{using b;}", """ + namespace a + { + using b; + } + """); + TestNormalizeDeclaration( + "namespace a{global using b;}", """ + namespace a + { + global using b; + } + """); + TestNormalizeDeclaration( + "namespace a{namespace b{}}", """ + namespace a + { + namespace b + { + } + } + """); + TestNormalizeDeclaration( + "namespace a{}namespace b{}", """ + namespace a + { + } + + namespace b + { + } + """); // type - TestNormalizeDeclaration("class a{}", "class a\r\n{\r\n}"); - TestNormalizeDeclaration("class a{class b{}}", "class a\r\n{\r\n class b\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class awhere a:c{}", "class a\r\n where a : c\r\n{\r\n}"); - TestNormalizeDeclaration("class awhere a:c{}", "class a\r\n where a : c\r\n{\r\n}"); - TestNormalizeDeclaration("class a:b{}", "class a : b\r\n{\r\n}"); + TestNormalizeDeclaration( + "class a{}", """ + class a + { + } + """); + TestNormalizeDeclaration( + "class a{class b{}}", """ + class a + { + class b + { + } + } + """); + TestNormalizeDeclaration( + "class awhere a:c{}", """ + class a + where a : c + { + } + """); + TestNormalizeDeclaration( + "class awhere a:c{}", """ + class a + where a : c + { + } + """); + TestNormalizeDeclaration( + "class a:b{}", """ + class a : b + { + } + """); // methods - TestNormalizeDeclaration("class a{void b(){}}", "class a\r\n{\r\n void b()\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{void b(){}void c(){}}", "class a\r\n{\r\n void b()\r\n {\r\n }\r\n\r\n void c()\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{a(){}}", "class a\r\n{\r\n a()\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{~a(){}}", "class a\r\n{\r\n ~a()\r\n {\r\n }\r\n}"); + TestNormalizeDeclaration( + "class a{void b(){}}", """ + class a + { + void b() + { + } + } + """); + TestNormalizeDeclaration( + "class a{void b(){}void c(){}}", """ + class a + { + void b() + { + } + + void c() + { + } + } + """); + TestNormalizeDeclaration( + "class a{a(){}}", """ + class a + { + a() + { + } + } + """); + TestNormalizeDeclaration( + "class a{~a(){}}", """ + class a + { + ~a() + { + } + } + """); // operators - TestNormalizeDeclaration("class a{b operator checked-(c d){}}", "class a\r\n{\r\n b operator checked -(c d)\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{ implicit operator checked b(c d){}}", "class a\r\n{\r\n implicit operator checked b(c d)\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{ explicit operator checked b(c d){}}", "class a\r\n{\r\n explicit operator checked b(c d)\r\n {\r\n }\r\n}"); + TestNormalizeDeclaration( + "class a{b operator checked-(c d){}}", """ + class a + { + b operator checked -(c d) + { + } + } + """); + TestNormalizeDeclaration( + "class a{ implicit operator checked b(c d){}}", """ + class a + { + implicit operator checked b(c d) + { + } + } + """); + TestNormalizeDeclaration( + "class a{ explicit operator checked b(c d){}}", """ + class a + { + explicit operator checked b(c d) + { + } + } + """); - TestNormalizeDeclaration("class a{b I1 . operator checked-(c d){}}", "class a\r\n{\r\n b I1.operator checked -(c d)\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{ implicit I1 . operator checked b(c d){}}", "class a\r\n{\r\n implicit I1.operator checked b(c d)\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{ explicit I1 . operator checked b(c d){}}", "class a\r\n{\r\n explicit I1.operator checked b(c d)\r\n {\r\n }\r\n}"); + TestNormalizeDeclaration( + "class a{b I1 . operator checked-(c d){}}", """ + class a + { + b I1.operator checked -(c d) + { + } + } + """); + TestNormalizeDeclaration( + "class a{ implicit I1 . operator checked b(c d){}}", """ + class a + { + implicit I1.operator checked b(c d) + { + } + } + """); + TestNormalizeDeclaration( + "class a{ explicit I1 . operator checked b(c d){}}", """ + class a + { + explicit I1.operator checked b(c d) + { + } + } + """); - TestNormalizeDeclaration("class a{b operator >>> ( c d , e f ){}}", "class a\r\n{\r\n b operator >>>(c d, e f)\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{b I1 . operator >>> ( c d , e f ){}}", "class a\r\n{\r\n b I1.operator >>>(c d, e f)\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{b operator>>> ( c d , e f ){}}", "class a\r\n{\r\n b operator >>>(c d, e f)\r\n {\r\n }\r\n}"); - TestNormalizeDeclaration("class a{b I1 . operator>>> ( c d , e f ){}}", "class a\r\n{\r\n b I1.operator >>>(c d, e f)\r\n {\r\n }\r\n}"); + TestNormalizeDeclaration( + "class a{b operator >>> ( c d , e f ){}}", """ + class a + { + b operator >>>(c d, e f) + { + } + } + """); + TestNormalizeDeclaration( + "class a{b I1 . operator >>> ( c d , e f ){}}", """ + class a + { + b I1.operator >>>(c d, e f) + { + } + } + """); + TestNormalizeDeclaration( + "class a{b operator>>> ( c d , e f ){}}", """ + class a + { + b operator >>>(c d, e f) + { + } + } + """); + TestNormalizeDeclaration( + "class a{b I1 . operator>>> ( c d , e f ){}}", """ + class a + { + b I1.operator >>>(c d, e f) + { + } + } + """); // properties - TestNormalizeDeclaration("class a{b c{get;}}", "class a\r\n{\r\n b c { get; }\r\n}"); - TestNormalizeDeclaration("class a {\r\nint X{get;set;}= 2;\r\n}\r\n", "class a\r\n{\r\n int X { get; set; } = 2;\r\n}"); - TestNormalizeDeclaration("class a {\r\nint Y\r\n{get;\r\nset;\r\n}\r\n=99;\r\n}\r\n", "class a\r\n{\r\n int Y { get; set; } = 99;\r\n}"); - TestNormalizeDeclaration("class a {\r\nint Z{get;}\r\n}\r\n", "class a\r\n{\r\n int Z { get; }\r\n}"); - TestNormalizeDeclaration("class a {\r\nint T{get;init;}\r\nint R{get=>1;}\r\n}\r\n", "class a\r\n{\r\n int T { get; init; }\r\n\r\n int R { get => 1; }\r\n}"); - TestNormalizeDeclaration("class a {\r\nint Q{get{return 0;}init{}}\r\nint R{get=>1;}\r\n}\r\n", "class a\r\n{\r\n int Q\r\n {\r\n get\r\n {\r\n return 0;\r\n }\r\n\r\n init\r\n {\r\n }\r\n }\r\n\r\n int R { get => 1; }\r\n}"); - TestNormalizeDeclaration("class a {\r\nint R{get=>1;}\r\n}\r\n", "class a\r\n{\r\n int R { get => 1; }\r\n}"); - TestNormalizeDeclaration("class a {\r\nint S=>2;\r\n}\r\n", "class a\r\n{\r\n int S => 2;\r\n}"); - TestNormalizeDeclaration("class x\r\n{\r\nint _g;\r\nint G\r\n{\r\nget\r\n{\r\nreturn\r\n_g;\r\n}\r\ninit;\r\n}\r\nint H\r\n{\r\nget;\r\nset\r\n{\r\n_g\r\n=\r\n12;\r\n}\r\n}\r\n}\r\n", - "class x\r\n{\r\n int _g;\r\n int G\r\n {\r\n get\r\n {\r\n return _g;\r\n }\r\n\r\n init;\r\n }\r\n\r\n int H\r\n {\r\n get;\r\n set\r\n {\r\n _g = 12;\r\n }\r\n }\r\n}"); - - TestNormalizeDeclaration("class i1\r\n{\r\nint\r\np\r\n{\r\nget;\r\n}\r\n}", "class i1\r\n{\r\n int p { get; }\r\n}"); - TestNormalizeDeclaration("class i2\r\n{\r\nint\r\np\r\n{\r\nget=>2;\r\n}\r\n}", "class i2\r\n{\r\n int p { get => 2; }\r\n}"); - TestNormalizeDeclaration("class i2a\r\n{\r\nint _p;\r\nint\r\np\r\n{\r\nget=>\r\n_p;set\r\n=>_p\r\n=value\r\n;\r\n}\r\n}", "class i2a\r\n{\r\n int _p;\r\n int p { get => _p; set => _p = value; }\r\n}"); - TestNormalizeDeclaration("class i3\r\n{\r\nint\r\np\r\n{\r\nget{}\r\n}\r\n}", "class i3\r\n{\r\n int p\r\n {\r\n get\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class i4\r\n{\r\nint\r\np\r\n{\r\nset;\r\n}\r\n}", "class i4\r\n{\r\n int p { set; }\r\n}"); - TestNormalizeDeclaration("class i5\r\n{\r\nint\r\np\r\n{\r\nset{}\r\n}\r\n}", "class i5\r\n{\r\n int p\r\n {\r\n set\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class i6\r\n{\r\nint\r\np\r\n{\r\ninit;\r\n}\r\n}", "class i6\r\n{\r\n int p { init; }\r\n}"); - TestNormalizeDeclaration("class i7\r\n{\r\nint\r\np\r\n{\r\ninit{}\r\n}\r\n}", "class i7\r\n{\r\n int p\r\n {\r\n init\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class i8\r\n{\r\nint\r\np\r\n{\r\nget{}\r\nset{}\r\n}\r\n}", "class i8\r\n{\r\n int p\r\n {\r\n get\r\n {\r\n }\r\n\r\n set\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class i9\r\n{\r\nint\r\np\r\n{\r\nget=>1;\r\nset{z=1;}\r\n}\r\n}", "class i9\r\n{\r\n int p\r\n {\r\n get => 1;\r\n set\r\n {\r\n z = 1;\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class ia\r\n{\r\nint\r\np\r\n{\r\nget{}\r\nset;\r\n}\r\n}", "class ia\r\n{\r\n int p\r\n {\r\n get\r\n {\r\n }\r\n\r\n set;\r\n }\r\n}"); - TestNormalizeDeclaration("class ib\r\n{\r\nint\r\np\r\n{\r\nget;\r\nset{}\r\n}\r\n}", "class ib\r\n{\r\n int p\r\n {\r\n get;\r\n set\r\n {\r\n }\r\n }\r\n}"); + TestNormalizeDeclaration( + "class a{b c{get;}}", """ + class a + { + b c { get; } + } + """); + TestNormalizeDeclaration(""" + class a { + int X{get;set;}= 2; + } - // properties with initializers - TestNormalizeDeclaration("class i4\r\n{\r\nint\r\np\r\n{\r\nset;\r\n}=1;\r\n}", "class i4\r\n{\r\n int p { set; } = 1;\r\n}"); - TestNormalizeDeclaration("class i5\r\n{\r\nint\r\np\r\n{\r\nset{}\r\n}=1;\r\n}", "class i5\r\n{\r\n int p\r\n {\r\n set\r\n {\r\n }\r\n } = 1;\r\n}"); - TestNormalizeDeclaration("class i6\r\n{\r\nint\r\np\r\n{\r\ninit;\r\n}=1;\r\n}", "class i6\r\n{\r\n int p { init; } = 1;\r\n}"); - TestNormalizeDeclaration("class i7\r\n{\r\nint\r\np\r\n{\r\ninit{}\r\n}=1;\r\n}", "class i7\r\n{\r\n int p\r\n {\r\n init\r\n {\r\n }\r\n } = 1;\r\n}"); - TestNormalizeDeclaration("class i8\r\n{\r\nint\r\np\r\n{\r\nget{}\r\nset{}\r\n}=1;\r\n}", "class i8\r\n{\r\n int p\r\n {\r\n get\r\n {\r\n }\r\n\r\n set\r\n {\r\n }\r\n } = 1;\r\n}"); - TestNormalizeDeclaration("class i9\r\n{\r\nint\r\np\r\n{\r\nget=>1;\r\nset{z=1;}\r\n}=1;\r\n}", "class i9\r\n{\r\n int p\r\n {\r\n get => 1;\r\n set\r\n {\r\n z = 1;\r\n }\r\n } = 1;\r\n}"); - TestNormalizeDeclaration("class ia\r\n{\r\nint\r\np\r\n{\r\nget{}\r\nset;\r\n}=1;\r\n}", "class ia\r\n{\r\n int p\r\n {\r\n get\r\n {\r\n }\r\n\r\n set;\r\n } = 1;\r\n}"); - TestNormalizeDeclaration("class ib\r\n{\r\nint\r\np\r\n{\r\nget;\r\nset{}\r\n}=1;\r\n}", "class ib\r\n{\r\n int p\r\n {\r\n get;\r\n set\r\n {\r\n }\r\n } = 1;\r\n}"); + """, """ + class a + { + int X { get; set; } = 2; + } + """); + TestNormalizeDeclaration(""" + class a { + int Y + {get; + set; + } + =99; + } + + """, """ + class a + { + int Y { get; set; } = 99; + } + """); + TestNormalizeDeclaration(""" + class a { + int Z{get;} + } + + """, """ + class a + { + int Z { get; } + } + """); + TestNormalizeDeclaration(""" + class a { + int T{get;init;} + int R{get=>1;} + } + + """, """ + class a + { + int T { get; init; } + + int R { get => 1; } + } + """); + TestNormalizeDeclaration(""" + class a { + int Q{get{return 0;}init{}} + int R{get=>1;} + } + + """, """ + class a + { + int Q + { + get + { + return 0; + } + + init + { + } + } + + int R { get => 1; } + } + """); + TestNormalizeDeclaration(""" + class a { + int R{get=>1;} + } + + """, """ + class a + { + int R { get => 1; } + } + """); + TestNormalizeDeclaration(""" + class a { + int S=>2; + } + + """, """ + class a + { + int S => 2; + } + """); + TestNormalizeDeclaration(""" + class x + { + int _g; + int G + { + get + { + return + _g; + } + init; + } + int H + { + get; + set + { + _g + = + 12; + } + } + } + + """, """ + class x + { + int _g; + int G + { + get + { + return _g; + } + + init; + } + + int H + { + get; + set + { + _g = 12; + } + } + } + """); + + TestNormalizeDeclaration(""" + class i1 + { + int + p + { + get; + } + } + """, """ + class i1 + { + int p { get; } + } + """); + TestNormalizeDeclaration(""" + class i2 + { + int + p + { + get=>2; + } + } + """, """ + class i2 + { + int p { get => 2; } + } + """); + TestNormalizeDeclaration(""" + class i2a + { + int _p; + int + p + { + get=> + _p;set + =>_p + =value + ; + } + } + """, """ + class i2a + { + int _p; + int p { get => _p; set => _p = value; } + } + """); + TestNormalizeDeclaration(""" + class i3 + { + int + p + { + get{} + } + } + """, """ + class i3 + { + int p + { + get + { + } + } + } + """); + TestNormalizeDeclaration(""" + class i4 + { + int + p + { + set; + } + } + """, """ + class i4 + { + int p { set; } + } + """); + TestNormalizeDeclaration(""" + class i5 + { + int + p + { + set{} + } + } + """, """ + class i5 + { + int p + { + set + { + } + } + } + """); + TestNormalizeDeclaration(""" + class i6 + { + int + p + { + init; + } + } + """, """ + class i6 + { + int p { init; } + } + """); + TestNormalizeDeclaration(""" + class i7 + { + int + p + { + init{} + } + } + """, """ + class i7 + { + int p + { + init + { + } + } + } + """); + TestNormalizeDeclaration(""" + class i8 + { + int + p + { + get{} + set{} + } + } + """, """ + class i8 + { + int p + { + get + { + } + + set + { + } + } + } + """); + TestNormalizeDeclaration(""" + class i9 + { + int + p + { + get=>1; + set{z=1;} + } + } + """, """ + class i9 + { + int p + { + get => 1; + set + { + z = 1; + } + } + } + """); + TestNormalizeDeclaration(""" + class ia + { + int + p + { + get{} + set; + } + } + """, """ + class ia + { + int p + { + get + { + } + + set; + } + } + """); + TestNormalizeDeclaration(""" + class ib + { + int + p + { + get; + set{} + } + } + """, """ + class ib + { + int p + { + get; + set + { + } + } + } + """); + + // properties with initializers + TestNormalizeDeclaration(""" + class i4 + { + int + p + { + set; + }=1; + } + """, """ + class i4 + { + int p { set; } = 1; + } + """); + TestNormalizeDeclaration(""" + class i5 + { + int + p + { + set{} + }=1; + } + """, """ + class i5 + { + int p + { + set + { + } + } = 1; + } + """); + TestNormalizeDeclaration(""" + class i6 + { + int + p + { + init; + }=1; + } + """, """ + class i6 + { + int p { init; } = 1; + } + """); + TestNormalizeDeclaration(""" + class i7 + { + int + p + { + init{} + }=1; + } + """, """ + class i7 + { + int p + { + init + { + } + } = 1; + } + """); + TestNormalizeDeclaration(""" + class i8 + { + int + p + { + get{} + set{} + }=1; + } + """, """ + class i8 + { + int p + { + get + { + } + + set + { + } + } = 1; + } + """); + TestNormalizeDeclaration(""" + class i9 + { + int + p + { + get=>1; + set{z=1;} + }=1; + } + """, """ + class i9 + { + int p + { + get => 1; + set + { + z = 1; + } + } = 1; + } + """); + TestNormalizeDeclaration(""" + class ia + { + int + p + { + get{} + set; + }=1; + } + """, """ + class ia + { + int p + { + get + { + } + + set; + } = 1; + } + """); + TestNormalizeDeclaration(""" + class ib + { + int + p + { + get; + set{} + }=1; + } + """, """ + class ib + { + int p + { + get; + set + { + } + } = 1; + } + """); + + // indexers + TestNormalizeDeclaration( + "class a{b this[c d]{get;}}", """ + class a + { + b this[c d] { get; } + } + """); + TestNormalizeDeclaration(""" + class i1 + { + int + this[b c] + { + get; + } + } + """, """ + class i1 + { + int this[b c] { get; } + } + """); + TestNormalizeDeclaration(""" + class i2 + { + int + this[b c] + { + get=>1; + } + } + """, """ + class i2 + { + int this[b c] { get => 1; } + } + """); + TestNormalizeDeclaration(""" + class i3 + { + int + this[b c] + { + get{} + } + } + """, """ + class i3 + { + int this[b c] + { + get + { + } + } + } + """); + TestNormalizeDeclaration(""" + class i4 + { + int + this[b c] + { + set; + } + } + """, """ + class i4 + { + int this[b c] { set; } + } + """); + TestNormalizeDeclaration(""" + class i5 + { + int + this[b c] + { + set{} + } + } + """, """ + class i5 + { + int this[b c] + { + set + { + } + } + } + """); + TestNormalizeDeclaration(""" + class i6 + { + int + this[b c] + { + init; + } + } + """, """ + class i6 + { + int this[b c] { init; } + } + """); + TestNormalizeDeclaration(""" + class i7 + { + int + this[b c] + { + init{} + } + } + """, """ + class i7 + { + int this[b c] + { + init + { + } + } + } + """); + TestNormalizeDeclaration(""" + class i8 + { + int + this[b c] + { + get{} + set{} + } + } + """, """ + class i8 + { + int this[b c] + { + get + { + } + + set + { + } + } + } + """); + TestNormalizeDeclaration(""" + class i9 + { + int + this[b c] + { + get=>1; + set{z=1;} + } + } + """, """ + class i9 + { + int this[b c] + { + get => 1; + set + { + z = 1; + } + } + } + """); + TestNormalizeDeclaration(""" + class ia + { + int + this[b c] + { + get{} + set; + } + } + """, """ + class ia + { + int this[b c] + { + get + { + } + + set; + } + } + """); + TestNormalizeDeclaration(""" + class ib + { + int + this[b c] + { + get; + set{} + } + } + """, """ + class ib + { + int this[b c] + { + get; + set + { + } + } + } + """); + + // events + TestNormalizeDeclaration(""" + class a + { + public + event + w + e; + } + """, """ + class a + { + public event w e; + } + """); + TestNormalizeDeclaration(""" + abstract class b + { + event + w + e + ; + } + """, """ + abstract class b + { + event w e; + } + """); + TestNormalizeDeclaration(""" + interface c1 + { + event + w + e + ; + } + """, """ + interface c1 + { + event w e; + } + """); + TestNormalizeDeclaration(""" + interface c2 : c1 + { + abstract + event + w + c1 + . + e + ; + } + """, """ + interface c2 : c1 + { + abstract event w c1.e; + } + """); + TestNormalizeDeclaration(""" + class d + { + event w x; + event + w + e + { + add + => + x+= + value; + remove + =>x + -= + value; + }} + """, """ + class d + { + event w x; + event w e { add => x += value; remove => x -= value; } + } + """); + TestNormalizeDeclaration(""" + class e + { + event w e + { + add{} + remove{ + } + } + } + """, """ + class e + { + event w e + { + add + { + } - // indexers - TestNormalizeDeclaration("class a{b this[c d]{get;}}", "class a\r\n{\r\n b this[c d] { get; }\r\n}"); - TestNormalizeDeclaration("class i1\r\n{\r\nint\r\nthis[b c]\r\n{\r\nget;\r\n}\r\n}", "class i1\r\n{\r\n int this[b c] { get; }\r\n}"); - TestNormalizeDeclaration("class i2\r\n{\r\nint\r\nthis[b c]\r\n{\r\nget=>1;\r\n}\r\n}", "class i2\r\n{\r\n int this[b c] { get => 1; }\r\n}"); - TestNormalizeDeclaration("class i3\r\n{\r\nint\r\nthis[b c]\r\n{\r\nget{}\r\n}\r\n}", "class i3\r\n{\r\n int this[b c]\r\n {\r\n get\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class i4\r\n{\r\nint\r\nthis[b c]\r\n{\r\nset;\r\n}\r\n}", "class i4\r\n{\r\n int this[b c] { set; }\r\n}"); - TestNormalizeDeclaration("class i5\r\n{\r\nint\r\nthis[b c]\r\n{\r\nset{}\r\n}\r\n}", "class i5\r\n{\r\n int this[b c]\r\n {\r\n set\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class i6\r\n{\r\nint\r\nthis[b c]\r\n{\r\ninit;\r\n}\r\n}", "class i6\r\n{\r\n int this[b c] { init; }\r\n}"); - TestNormalizeDeclaration("class i7\r\n{\r\nint\r\nthis[b c]\r\n{\r\ninit{}\r\n}\r\n}", "class i7\r\n{\r\n int this[b c]\r\n {\r\n init\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class i8\r\n{\r\nint\r\nthis[b c]\r\n{\r\nget{}\r\nset{}\r\n}\r\n}", "class i8\r\n{\r\n int this[b c]\r\n {\r\n get\r\n {\r\n }\r\n\r\n set\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class i9\r\n{\r\nint\r\nthis[b c]\r\n{\r\nget=>1;\r\nset{z=1;}\r\n}\r\n}", "class i9\r\n{\r\n int this[b c]\r\n {\r\n get => 1;\r\n set\r\n {\r\n z = 1;\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class ia\r\n{\r\nint\r\nthis[b c]\r\n{\r\nget{}\r\nset;\r\n}\r\n}", "class ia\r\n{\r\n int this[b c]\r\n {\r\n get\r\n {\r\n }\r\n\r\n set;\r\n }\r\n}"); - TestNormalizeDeclaration("class ib\r\n{\r\nint\r\nthis[b c]\r\n{\r\nget;\r\nset{}\r\n}\r\n}", "class ib\r\n{\r\n int this[b c]\r\n {\r\n get;\r\n set\r\n {\r\n }\r\n }\r\n}"); + remove + { + } + } + } + """); + TestNormalizeDeclaration(""" + class f + { + event w x; + event w e + { + add + { + x + += + value; + } + remove + { + x + -= + value; + } + } + } + """, """ + class f + { + event w x; + event w e + { + add + { + x += value; + } - // events - TestNormalizeDeclaration("class a\r\n{\r\npublic\r\nevent\r\nw\r\ne;\r\n}", "class a\r\n{\r\n public event w e;\r\n}"); - TestNormalizeDeclaration("abstract class b\r\n{\r\nevent\r\nw\r\ne\r\n;\r\n}", "abstract class b\r\n{\r\n event w e;\r\n}"); - TestNormalizeDeclaration("interface c1\r\n{\r\nevent\r\nw\r\ne\r\n;\r\n}", "interface c1\r\n{\r\n event w e;\r\n}"); - TestNormalizeDeclaration("interface c2 : c1\r\n{\r\nabstract\r\nevent\r\nw\r\nc1\r\n.\r\ne\r\n;\r\n}", "interface c2 : c1\r\n{\r\n abstract event w c1.e;\r\n}"); - TestNormalizeDeclaration("class d\r\n{\r\nevent w x;\r\nevent\r\nw\r\ne\r\n{\r\nadd\r\n=>\r\nx+=\r\nvalue;\r\nremove\r\n=>x\r\n-=\r\nvalue;\r\n}}", "class d\r\n{\r\n event w x;\r\n event w e { add => x += value; remove => x -= value; }\r\n}"); - TestNormalizeDeclaration("class e\r\n{\r\nevent w e\r\n{\r\nadd{}\r\nremove{\r\n}\r\n}\r\n}", "class e\r\n{\r\n event w e\r\n {\r\n add\r\n {\r\n }\r\n\r\n remove\r\n {\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class f\r\n{\r\nevent w x;\r\nevent w e\r\n{\r\nadd\r\n{\r\nx\r\n+=\r\nvalue;\r\n}\r\nremove\r\n{\r\nx\r\n-=\r\nvalue;\r\n}\r\n}\r\n}", "class f\r\n{\r\n event w x;\r\n event w e\r\n {\r\n add\r\n {\r\n x += value;\r\n }\r\n\r\n remove\r\n {\r\n x -= value;\r\n }\r\n }\r\n}"); - TestNormalizeDeclaration("class g\r\n{\r\nextern\r\nevent\r\nw\r\ne\r\n=\r\nnull\r\n;\r\n}", "class g\r\n{\r\n extern event w e = null;\r\n}"); - TestNormalizeDeclaration("class h\r\n{\r\npublic event w e\r\n{\r\nadd\r\n=>\r\nc\r\n(\r\n);\r\nremove\r\n=>\r\nd(\r\n);\r\n}\r\n}", "class h\r\n{\r\n public event w e { add => c(); remove => d(); }\r\n}"); - TestNormalizeDeclaration("class i\r\n{\r\nevent w e\r\n{\r\nadd;\r\nremove;\r\n}\r\n}", "class i\r\n{\r\n event w e { add; remove; }\r\n}"); + remove + { + x -= value; + } + } + } + """); + TestNormalizeDeclaration(""" + class g + { + extern + event + w + e + = + null + ; + } + """, """ + class g + { + extern event w e = null; + } + """); + TestNormalizeDeclaration(""" + class h + { + public event w e + { + add + => + c + ( + ); + remove + => + d( + ); + } + } + """, """ + class h + { + public event w e { add => c(); remove => d(); } + } + """); + TestNormalizeDeclaration(""" + class i + { + event w e + { + add; + remove; + } + } + """, """ + class i + { + event w e { add; remove; } + } + """); // fields - TestNormalizeDeclaration("class a{b c;}", "class a\r\n{\r\n b c;\r\n}"); - TestNormalizeDeclaration("class a{b c=d;}", "class a\r\n{\r\n b c = d;\r\n}"); - TestNormalizeDeclaration("class a{b c=d,e=f;}", "class a\r\n{\r\n b c = d, e = f;\r\n}"); + TestNormalizeDeclaration( + "class a{b c;}", """ + class a + { + b c; + } + """); + TestNormalizeDeclaration( + "class a{b c=d;}", """ + class a + { + b c = d; + } + """); + TestNormalizeDeclaration( + "class a{b c=d,e=f;}", """ + class a + { + b c = d, e = f; + } + """); // delegate TestNormalizeDeclaration("delegate a b();", "delegate a b();"); @@ -697,28 +2156,109 @@ public void TestNormalizeDeclaration1() TestNormalizeDeclaration("delegate a b(c,d);", "delegate a b(c, d);"); // enums - TestNormalizeDeclaration("enum a{}", "enum a\r\n{\r\n}"); - TestNormalizeDeclaration("enum a{b}", "enum a\r\n{\r\n b\r\n}"); - TestNormalizeDeclaration("enum a{b,c}", "enum a\r\n{\r\n b,\r\n c\r\n}"); - TestNormalizeDeclaration("enum a{b=c}", "enum a\r\n{\r\n b = c\r\n}"); + TestNormalizeDeclaration( + "enum a{}", """ + enum a + { + } + """); + TestNormalizeDeclaration( + "enum a{b}", """ + enum a + { + b + } + """); + TestNormalizeDeclaration( + "enum a{b,c}", """ + enum a + { + b, + c + } + """); + TestNormalizeDeclaration( + "enum a{b=c}", """ + enum a + { + b = c + } + """); // attributes - TestNormalizeDeclaration("[a]class b{}", "[a]\r\nclass b\r\n{\r\n}"); - TestNormalizeDeclaration("\t[a]class b{}", "[a]\r\nclass b\r\n{\r\n}"); - TestNormalizeDeclaration("[a,b]class c{}", "[a, b]\r\nclass c\r\n{\r\n}"); - TestNormalizeDeclaration("[a(b)]class c{}", "[a(b)]\r\nclass c\r\n{\r\n}"); - TestNormalizeDeclaration("[a(b,c)]class d{}", "[a(b, c)]\r\nclass d\r\n{\r\n}"); - TestNormalizeDeclaration("[a][b]class c{}", "[a]\r\n[b]\r\nclass c\r\n{\r\n}"); - TestNormalizeDeclaration("[a:b]class c{}", "[a: b]\r\nclass c\r\n{\r\n}"); + TestNormalizeDeclaration( + "[a]class b{}", """ + [a] + class b + { + } + """); + TestNormalizeDeclaration( + "\t[a]class b{}", """ + [a] + class b + { + } + """); + TestNormalizeDeclaration( + "[a,b]class c{}", """ + [a, b] + class c + { + } + """); + TestNormalizeDeclaration( + "[a(b)]class c{}", """ + [a(b)] + class c + { + } + """); + TestNormalizeDeclaration( + "[a(b,c)]class d{}", """ + [a(b, c)] + class d + { + } + """); + TestNormalizeDeclaration( + "[a][b]class c{}", """ + [a] + [b] + class c + { + } + """); + TestNormalizeDeclaration( + "[a:b]class c{}", """ + [a: b] + class c + { + } + """); // parameter attributes - TestNormalizeDeclaration("class c{void M([a]int x,[b] [c,d]int y){}}", "class c\r\n{\r\n void M([a] int x, [b][c, d] int y)\r\n {\r\n }\r\n}"); + TestNormalizeDeclaration( + "class c{void M([a]int x,[b] [c,d]int y){}}", """ + class c + { + void M([a] int x, [b][c, d] int y) + { + } + } + """); } [Fact] public void TestFileScopedNamespace() { - TestNormalizeDeclaration("namespace NS;class C{}", "namespace NS;\r\nclass C\r\n{\r\n}"); + TestNormalizeDeclaration( + "namespace NS;class C{}", """ + namespace NS; + class C + { + } + """); } [Fact] @@ -728,8 +2268,7 @@ public void TestSpacingOnRecord() TestNormalizeDeclaration("record struct S(int I, int J);", "record struct S(int I, int J);"); } - [Fact] - [WorkItem(23618, "https://github.com/dotnet/roslyn/issues/23618")] + [Fact, WorkItem(23618, "https://github.com/dotnet/roslyn/issues/23618")] public void TestSpacingOnInvocationLikeKeywords() { // no space between typeof and ( @@ -744,18 +2283,34 @@ public void TestSpacingOnInvocationLikeKeywords() // no space between new and ( // newline between > and where TestNormalizeDeclaration( - "class C where T : new() { }", - "class C\r\n where T : new()\r\n{\r\n}"); + "class C where T : new() { }", """ + class C + where T : new() + { + } + """); // no space between this and ( TestNormalizeDeclaration( - "class C { C() : this () { } }", - "class C\r\n{\r\n C() : this()\r\n {\r\n }\r\n}"); + "class C { C() : this () { } }", """ + class C + { + C() : this() + { + } + } + """); // no space between base and ( TestNormalizeDeclaration( - "class C { C() : base () { } }", - "class C\r\n{\r\n C() : base()\r\n {\r\n }\r\n}"); + "class C { C() : base () { } }", """ + class C + { + C() : base() + { + } + } + """); // no space between checked and ( TestNormalizeExpression("checked (a)", "checked(a)"); @@ -767,8 +2322,7 @@ public void TestSpacingOnInvocationLikeKeywords() TestNormalizeExpression("__arglist (a)", "__arglist(a)"); } - [Fact] - [WorkItem(24454, "https://github.com/dotnet/roslyn/issues/24454")] + [Fact, WorkItem(24454, "https://github.com/dotnet/roslyn/issues/24454")] public void TestSpacingOnInterpolatedString() { TestNormalizeExpression("$\"{3:C}\"", "$\"{3:C}\""); @@ -778,61 +2332,170 @@ public void TestSpacingOnInterpolatedString() [Fact] public void TestSpacingOnRawInterpolatedString() { - TestNormalizeExpression("$\"\"\"{3:C}\"\"\"", "$\"\"\"{3:C}\"\"\""); - TestNormalizeExpression("$\"\"\"{3: C}\"\"\"", "$\"\"\"{3: C}\"\"\""); - TestNormalizeExpression("$\"\"\"{3:C }\"\"\"", "$\"\"\"{3:C }\"\"\""); - TestNormalizeExpression("$\"\"\"{3: C }\"\"\"", "$\"\"\"{3: C }\"\"\""); - - TestNormalizeExpression("$\"\"\"{ 3:C}\"\"\"", "$\"\"\"{3:C}\"\"\""); - TestNormalizeExpression("$\"\"\"{ 3: C}\"\"\"", "$\"\"\"{3: C}\"\"\""); - TestNormalizeExpression("$\"\"\"{ 3:C }\"\"\"", "$\"\"\"{3:C }\"\"\""); - TestNormalizeExpression("$\"\"\"{ 3: C }\"\"\"", "$\"\"\"{3: C }\"\"\""); - TestNormalizeExpression("$\"\"\"{3 :C}\"\"\"", "$\"\"\"{3:C}\"\"\""); - TestNormalizeExpression("$\"\"\"{3 : C}\"\"\"", "$\"\"\"{3: C}\"\"\""); - TestNormalizeExpression("$\"\"\"{3 :C }\"\"\"", "$\"\"\"{3:C }\"\"\""); - TestNormalizeExpression("$\"\"\"{3 : C }\"\"\"", "$\"\"\"{3: C }\"\"\""); - - TestNormalizeExpression("$\"\"\"{ 3 :C}\"\"\"", "$\"\"\"{3:C}\"\"\""); - TestNormalizeExpression("$\"\"\"{ 3 : C}\"\"\"", "$\"\"\"{3: C}\"\"\""); - TestNormalizeExpression("$\"\"\"{ 3 :C }\"\"\"", "$\"\"\"{3:C }\"\"\""); - TestNormalizeExpression("$\"\"\"{ 3 : C }\"\"\"", "$\"\"\"{3: C }\"\"\""); + TestNormalizeExpression("""" + $"""{3:C}""" + """", """" + $"""{3:C}""" + """"); + TestNormalizeExpression("""" + $"""{3: C}""" + """", """" + $"""{3: C}""" + """"); + TestNormalizeExpression("""" + $"""{3:C }""" + """", """" + $"""{3:C }""" + """"); + TestNormalizeExpression("""" + $"""{3: C }""" + """", """" + $"""{3: C }""" + """"); + + TestNormalizeExpression("""" + $"""{ 3:C}""" + """", """" + $"""{3:C}""" + """"); + TestNormalizeExpression("""" + $"""{ 3: C}""" + """", """" + $"""{3: C}""" + """"); + TestNormalizeExpression("""" + $"""{ 3:C }""" + """", """" + $"""{3:C }""" + """"); + TestNormalizeExpression("""" + $"""{ 3: C }""" + """", """" + $"""{3: C }""" + """"); + TestNormalizeExpression("""" + $"""{3 :C}""" + """", """" + $"""{3:C}""" + """"); + TestNormalizeExpression("""" + $"""{3 : C}""" + """", """" + $"""{3: C}""" + """"); + TestNormalizeExpression("""" + $"""{3 :C }""" + """", """" + $"""{3:C }""" + """"); + TestNormalizeExpression("""" + $"""{3 : C }""" + """", """" + $"""{3: C }""" + """"); + + TestNormalizeExpression("""" + $"""{ 3 :C}""" + """", """" + $"""{3:C}""" + """"); + TestNormalizeExpression("""" + $"""{ 3 : C}""" + """", """" + $"""{3: C}""" + """"); + TestNormalizeExpression("""" + $"""{ 3 :C }""" + """", """" + $"""{3:C }""" + """"); + TestNormalizeExpression("""" + $"""{ 3 : C }""" + """", """" + $"""{3: C }""" + """"); } - [Fact] - [WorkItem(23618, "https://github.com/dotnet/roslyn/issues/23618")] + [Fact, WorkItem(23618, "https://github.com/dotnet/roslyn/issues/23618")] public void TestSpacingOnMethodConstraint() { // newline between ) and where TestNormalizeDeclaration( - "class C { void M() where T : struct { } }", - "class C\r\n{\r\n void M()\r\n where T : struct\r\n {\r\n }\r\n}"); + "class C { void M() where T : struct { } }", """ + class C + { + void M() + where T : struct + { + } + } + """); } - [WorkItem(541684, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541684")] - [Fact] + [Fact, WorkItem(541684, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541684")] public void TestNormalizeRegion1() { // NOTE: the space after the region name is retained, since the text after the space // following "#region" is a single, unstructured trivia element. - TestNormalizeDeclaration( - "\r\nclass Class \r\n{ \r\n#region Methods \r\nvoid Method() \r\n{ \r\n} \r\n#endregion \r\n}", - "class Class\r\n{\r\n#region Methods \r\n void Method()\r\n {\r\n }\r\n#endregion\r\n}"); - TestNormalizeDeclaration( - "\r\n#region\r\n#endregion", - "#region\r\n#endregion\r\n"); - TestNormalizeDeclaration( - "\r\n#region \r\n#endregion", - "#region\r\n#endregion\r\n"); - TestNormalizeDeclaration( - "\r\n#region name //comment\r\n#endregion", - "#region name //comment\r\n#endregion\r\n"); - TestNormalizeDeclaration( - "\r\n#region /*comment*/\r\n#endregion", - "#region /*comment*/\r\n#endregion\r\n"); + TestNormalizeDeclaration(""" + + class Class + { + #region Methods + void Method() + { + } + #endregion + } + """, """ + class Class + { + #region Methods + void Method() + { + } + #endregion + } + """); + TestNormalizeDeclaration(""" + + #region + #endregion + """, """ + #region + #endregion + + """); + TestNormalizeDeclaration(""" + + #region + #endregion + """, """ + #region + #endregion + + """); + TestNormalizeDeclaration(""" + + #region name //comment + #endregion + """, """ + #region name //comment + #endregion + + """); + TestNormalizeDeclaration(""" + + #region /*comment*/ + #endregion + """, """ + #region /*comment*/ + #endregion + + """); } - [WorkItem(2076, "github")] - [Fact] + [Fact, WorkItem(2076, "github")] public void TestNormalizeInterpolatedString() { TestNormalizeExpression(@"$""Message is {a}""", @"$""Message is {a}"""); @@ -841,28 +2504,48 @@ public void TestNormalizeInterpolatedString() [Fact] public void TestNormalizeRawInterpolatedString() { - TestNormalizeExpression(@"$""""""Message is {a}""""""", @"$""""""Message is {a}"""""""); + TestNormalizeExpression("""" + $"""Message is {a}""" + """", """" + $"""Message is {a}""" + """"); } - [WorkItem(528584, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/528584")] - [Fact] + [Fact, WorkItem(528584, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/528584")] public void TestNormalizeRegion2() { - TestNormalizeDeclaration( - "\r\n#region //comment\r\n#endregion", + TestNormalizeDeclaration(""" + + #region //comment + #endregion + """, // NOTE: the extra newline should be removed, but it's not worth the // effort (see DevDiv #8564) - "#region //comment\r\n\r\n#endregion\r\n"); - TestNormalizeDeclaration( - "\r\n#region //comment\r\n\r\n#endregion", + """ + #region //comment + + #endregion + + """); + TestNormalizeDeclaration(""" + + #region //comment + + #endregion + """, // NOTE: the extra newline should be removed, but it's not worth the // effort (see DevDiv #8564). - "#region //comment\r\n\r\n#endregion\r\n"); + """ + #region //comment + + #endregion + + """); } - private void TestNormalizeDeclaration(string text, string expected) + private static void TestNormalizeDeclaration(string text, string expected) { - var node = SyntaxFactory.ParseCompilationUnit(text); + var node = SyntaxFactory.ParseCompilationUnit(text.NormalizeLineEndings()); Assert.Equal(text.NormalizeLineEndings(), node.ToFullString().NormalizeLineEndings()); var actual = node.NormalizeWhitespace(" ").ToFullString(); Assert.Equal(expected.NormalizeLineEndings(), actual.NormalizeLineEndings()); @@ -871,72 +2554,220 @@ private void TestNormalizeDeclaration(string text, string expected) [Fact] public void TestNormalizeComments() { - TestNormalizeToken("a//b", "a //b\r\n"); + TestNormalizeToken( + "a//b", """ + a //b + + """); TestNormalizeToken("a/*b*/", "a /*b*/"); - TestNormalizeToken("//a\r\nb", "//a\r\nb"); + TestNormalizeToken(""" + //a + b + """, """ + //a + b + """); TestNormalizeExpression("a/*b*/+c", "a /*b*/ + c"); - TestNormalizeExpression("/*a*/b", "/*a*/\r\nb"); - TestNormalizeExpression("/*a\r\n*/b", "/*a\r\n*/\r\nb"); - TestNormalizeStatement("{/*a*/b}", "{ /*a*/\r\n b\r\n}"); - TestNormalizeStatement("{\r\na//b\r\n}", "{\r\n a //b\r\n}"); - TestNormalizeStatement("{\r\n//a\r\n}", "{\r\n//a\r\n}"); - TestNormalizeStatement("{\r\n//a\r\nb}", "{\r\n //a\r\n b\r\n}"); - TestNormalizeStatement("{\r\n/*a*/b}", "{\r\n /*a*/\r\n b\r\n}"); - TestNormalizeStatement("{\r\n/// \r\na}", "{\r\n /// \r\n a\r\n}"); - TestNormalizeStatement("{\r\n///\r\na}", "{\r\n ///\r\n a\r\n}"); - TestNormalizeStatement("{\r\n/// \r\n/// \r\na}", "{\r\n /// \r\n /// \r\n a\r\n}"); - TestNormalizeToken("/// \r\n/// \r\na", "/// \r\n/// \r\na"); - TestNormalizeStatement("{\r\n/*** ***/\r\na}", "{\r\n /*** ***/\r\n a\r\n}"); - TestNormalizeStatement("{\r\n/*** \r\n ***/\r\na}", "{\r\n /*** \r\n ***/\r\n a\r\n}"); - } - - private void TestNormalizeToken(string text, string expected) - { - var token = SyntaxFactory.ParseToken(text); + TestNormalizeExpression( + "/*a*/b", """ + /*a*/ + b + """); + TestNormalizeExpression(""" + /*a + */b + """, """ + /*a + */ + b + """); + TestNormalizeStatement( + "{/*a*/b}", """ + { /*a*/ + b + } + """); + TestNormalizeStatement(""" + { + a//b + } + """, """ + { + a //b + } + """); + TestNormalizeStatement(""" + { + //a + } + """, """ + { + //a + } + """); + TestNormalizeStatement(""" + { + //a + b} + """, """ + { + //a + b + } + """); + TestNormalizeStatement(""" + { + /*a*/b} + """, """ + { + /*a*/ + b + } + """); + TestNormalizeStatement(""" + { + /// + a} + """, """ + { + /// + a + } + """); + TestNormalizeStatement(""" + { + /// + a} + """, """ + { + /// + a + } + """); + TestNormalizeStatement(""" + { + /// + /// + a} + """, """ + { + /// + /// + a + } + """); + TestNormalizeToken(""" + /// + /// + a + """, """ + /// + /// + a + """); + TestNormalizeStatement(""" + { + /*** ***/ + a} + """, """ + { + /*** ***/ + a + } + """); + TestNormalizeStatement(""" + { + /*** + ***/ + a} + """, """ + { + /*** + ***/ + a + } + """); + } + + private static void TestNormalizeToken(string text, string expected) + { + var token = SyntaxFactory.ParseToken(text.NormalizeLineEndings()); var actual = token.NormalizeWhitespace().ToFullString(); Assert.Equal(expected.NormalizeLineEndings(), actual.NormalizeLineEndings()); } - [Fact] - [WorkItem(1066, "github")] + [Fact, WorkItem(1066, "github")] public void TestNormalizePreprocessorDirectives() { // directive as node - TestNormalize(SyntaxFactory.DefineDirectiveTrivia(SyntaxFactory.Identifier("a"), false), "#define a\r\n"); + TestNormalize( + SyntaxFactory.DefineDirectiveTrivia( + SyntaxFactory.Identifier("a"), false), """ + #define a + + """); // directive as trivia - TestNormalizeTrivia(" # define a", "#define a\r\n"); - TestNormalizeTrivia("#if(a||b)", "#if (a || b)\r\n"); - TestNormalizeTrivia("#if(a&&b)", "#if (a && b)\r\n"); - TestNormalizeTrivia(" #if a\r\n #endif", "#if a\r\n#endif\r\n"); + TestNormalizeTrivia( + " # define a", """ + #define a + + """); + TestNormalizeTrivia( + "#if(a||b)", """ + #if (a || b) + + """); + TestNormalizeTrivia( + "#if(a&&b)", """ + #if (a && b) + + """); + TestNormalizeTrivia(""" + #if a + #endif + """, """ + #if a + #endif + + """); TestNormalize( SyntaxFactory.TriviaList( SyntaxFactory.Trivia( - SyntaxFactory.IfDirectiveTrivia(SyntaxFactory.IdentifierName("a"), false, false, false)), + SyntaxFactory.IfDirectiveTrivia( + SyntaxFactory.IdentifierName("a"), false, false, false)), SyntaxFactory.Trivia( - SyntaxFactory.EndIfDirectiveTrivia(false))), - "#if a\r\n#endif\r\n"); + SyntaxFactory.EndIfDirectiveTrivia(false))), """ + #if a + #endif - TestNormalizeTrivia("#endregion goo", "#endregion goo\r\n"); + """); - TestNormalizeDeclaration( -@"#pragma warning disable 123 + TestNormalizeTrivia( + "#endregion goo", """ + #endregion goo -namespace goo { -} + """); -#pragma warning restore 123", -@"#pragma warning disable 123 -namespace goo -{ -} -#pragma warning restore 123 -"); + TestNormalizeDeclaration(""" + #pragma warning disable 123 + + namespace goo { + } + + #pragma warning restore 123 + """, """ + #pragma warning disable 123 + namespace goo + { + } + #pragma warning restore 123 + + """); } - [Fact] - [WorkItem(531607, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531607")] + [Fact, WorkItem(531607, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531607")] public void TestNormalizeLineDirectiveTrivia() { TestNormalize( @@ -954,9 +2785,10 @@ public void TestNormalizeLineDirectiveTrivia() SyntaxFactory.TokenList( SyntaxFactory.Literal(@"""a\b"""))))), SyntaxKind.EndOfDirectiveToken, - default(SyntaxTriviaList))))), - @"#line 1 ""\""a\\b\"""" -"); + default(SyntaxTriviaList))))), """ + #line 1 "\"a\\b\"" + + """); // Note: without all the escaping, it looks like this '#line 1 @"""a\b"""' (i.e. the string literal has a value of '"a\b"'). // Note: the literal was formatted as a C# string literal, not as a directive string literal. } @@ -974,66 +2806,89 @@ public void TestNormalizeLineSpanDirectiveNode() SyntaxFactory.Literal(5), SyntaxFactory.Literal("a.txt"), SyntaxFactory.Token(SyntaxKind.EndOfDirectiveToken), - isActive: true), - "#line (1, 2) - (3, 4) 5 \"a.txt\"\r\n"); + isActive: true), """ + #line (1, 2) - (3, 4) 5 "a.txt" + + """); } [Fact] public void TestNormalizeLineSpanDirectiveTrivia() { - TestNormalizeTrivia(" # line( 1,2 )-(3,4)5\"a.txt\"", "#line (1, 2) - (3, 4) 5 \"a.txt\"\r\n"); + TestNormalizeTrivia( + " # line( 1,2 )-(3,4)5\"a.txt\"", """ + #line (1, 2) - (3, 4) 5 "a.txt" + + """); } - [WorkItem(538115, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538115")] - [Fact] + [Fact, WorkItem(538115, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/538115")] public void TestNormalizeWithinDirectives() { - TestNormalizeDeclaration( -"class C\r\n{\r\n#if true\r\nvoid Goo(A x) { }\r\n#else\r\n#endif\r\n}\r\n", -"class C\r\n{\r\n#if true\r\n void Goo(A x)\r\n {\r\n }\r\n#else\r\n#endif\r\n}"); + TestNormalizeDeclaration(""" + class C + { + #if true + void Goo(A x) { } + #else + #endif + } + + """, """ + class C + { + #if true + void Goo(A x) + { + } + #else + #endif + } + """); } - [WorkItem(542887, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542887")] - [Fact] + [Fact, WorkItem(542887, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542887")] public void TestFormattingForBlockSyntax() { - var code = -@"class c1 -{ -void goo() -{ -{ -int i = 1; -} -} -}"; + var code = """ + class c1 + { + void goo() + { + { + int i = 1; + } + } + } + """; var tree = SyntaxFactory.ParseSyntaxTree(code); - TestNormalize(tree.GetCompilationUnitRoot(), -@"class c1 -{ - void goo() - { - { - int i = 1; - } - } -}".NormalizeLineEndings()); + TestNormalize(tree.GetCompilationUnitRoot(), """ + class c1 + { + void goo() + { + { + int i = 1; + } + } + } + """.NormalizeLineEndings()); } - [WorkItem(1079042, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1079042")] - [Fact] + [Fact, WorkItem(1079042, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1079042")] public void TestNormalizeDocumentationComments() { - var code = -@"class c1 -{ - /// - /// A documentation comment - /// - void goo() - { - } -}"; + var code = """ + class c1 + { + /// + /// A documentation comment + /// + void goo() + { + } + } + """; var tree = SyntaxFactory.ParseSyntaxTree(code); TestNormalize(tree.GetCompilationUnitRoot(), "class c1\r\n" + @@ -1052,16 +2907,17 @@ void goo() [Fact] public void TestNormalizeDocumentationComments2() { - var code = -@"class c1 -{ - /// - /// A documentation comment - /// - void goo() - { - } -}"; + var code = """ + class c1 + { + /// + /// A documentation comment + /// + void goo() + { + } + } + """; var tree = SyntaxFactory.ParseSyntaxTree(code); TestNormalize(tree.GetCompilationUnitRoot(), "class c1\r\n" + @@ -1089,13 +2945,19 @@ public void TestNormalizeEOL() public void TestNormalizeTabs() { var code = "class c{void m(){}}"; - var expected = "class c\r\n{\r\n\tvoid m()\r\n\t{\r\n\t}\r\n}"; - var actual = SyntaxFactory.ParseCompilationUnit(code).NormalizeWhitespace(indentation: "\t").ToFullString(); - Assert.Equal(expected, actual); + var expected = """ + class c + { + void m() + { + } + } + """; + var actual = SyntaxFactory.ParseCompilationUnit(code).NormalizeWhitespace(indentation: " ").ToFullString(); + Assert.Equal(expected.NormalizeLineEndings(), actual); } - [Fact] - [WorkItem(29390, "https://github.com/dotnet/roslyn/issues/29390")] + [Fact, WorkItem(29390, "https://github.com/dotnet/roslyn/issues/29390")] public void TestNormalizeTuples() { TestNormalizeDeclaration("new(string prefix,string uri)[10]", "new (string prefix, string uri)[10]"); @@ -1106,271 +2968,407 @@ public void TestNormalizeTuples() TestNormalizeDeclaration("public (string prefix,string uri)Foo()", "public (string prefix, string uri) Foo()"); } - [Fact] - [WorkItem(50664, "https://github.com/dotnet/roslyn/issues/50664")] + [Fact, WorkItem(50664, "https://github.com/dotnet/roslyn/issues/50664")] public void TestNormalizeFunctionPointer() { - var content = -@"unsafe class C -{ - delegate * < int , int > functionPointer; -}"; - - var expected = -@"unsafe class C -{ - delegate* functionPointer; -}"; - - TestNormalizeDeclaration(content, expected); + TestNormalizeDeclaration(""" + unsafe class C + { + delegate * < int , int > functionPointer; + } + """, """ + unsafe class C + { + delegate* functionPointer; + } + """); } - [Fact] - [WorkItem(50664, "https://github.com/dotnet/roslyn/issues/50664")] + [Fact, WorkItem(50664, "https://github.com/dotnet/roslyn/issues/50664")] public void TestNormalizeFunctionPointerWithManagedCallingConvention() { - var content = -@"unsafe class C -{ - delegate *managed < int , int > functionPointer; -}"; - - var expected = -@"unsafe class C -{ - delegate* managed functionPointer; -}"; - - TestNormalizeDeclaration(content, expected); + TestNormalizeDeclaration(""" + unsafe class C + { + delegate *managed < int , int > functionPointer; + } + """, """ + unsafe class C + { + delegate* managed functionPointer; + } + """); } - [Fact] - [WorkItem(50664, "https://github.com/dotnet/roslyn/issues/50664")] + [Fact, WorkItem(50664, "https://github.com/dotnet/roslyn/issues/50664")] public void TestNormalizeFunctionPointerWithUnmanagedCallingConvention() { - var content = -@"unsafe class C -{ - delegate *unmanaged < int , int > functionPointer; -}"; - - var expected = -@"unsafe class C -{ - delegate* unmanaged functionPointer; -}"; - - TestNormalizeDeclaration(content, expected); + TestNormalizeDeclaration(""" + unsafe class C + { + delegate *unmanaged < int , int > functionPointer; + } + """, """ + unsafe class C + { + delegate* unmanaged functionPointer; + } + """); } - [Fact] - [WorkItem(50664, "https://github.com/dotnet/roslyn/issues/50664")] + [Fact, WorkItem(50664, "https://github.com/dotnet/roslyn/issues/50664")] public void TestNormalizeFunctionPointerWithUnmanagedCallingConventionAndSpecifiers() { - var content = -@"unsafe class C -{ - delegate *unmanaged [ Cdecl , Thiscall ] < int , int > functionPointer; -}"; - - var expected = -@"unsafe class C -{ - delegate* unmanaged[Cdecl, Thiscall] functionPointer; -}"; - - TestNormalizeDeclaration(content, expected); + TestNormalizeDeclaration(""" + unsafe class C + { + delegate *unmanaged [ Cdecl , Thiscall ] < int , int > functionPointer; + } + """, """ + unsafe class C + { + delegate* unmanaged[Cdecl, Thiscall] functionPointer; + } + """); } - [Fact] - [WorkItem(53254, "https://github.com/dotnet/roslyn/issues/53254")] + [Fact, WorkItem(53254, "https://github.com/dotnet/roslyn/issues/53254")] public void TestNormalizeColonInConstructorInitializer() { - var content = -@"class Base -{ -} - -class Derived : Base -{ - public Derived():base(){} -}"; - - var expected = -@"class Base -{ -} + TestNormalizeDeclaration(""" + class Base + { + } -class Derived : Base -{ - public Derived() : base() - { - } -}"; + class Derived : Base + { + public Derived():base(){} + } + """, """ + class Base + { + } - TestNormalizeDeclaration(content, expected); + class Derived : Base + { + public Derived() : base() + { + } + } + """); } - [Fact] - [WorkItem(49732, "https://github.com/dotnet/roslyn/issues/49732")] + [Fact, WorkItem(49732, "https://github.com/dotnet/roslyn/issues/49732")] public void TestNormalizeXmlInDocComment() { - var code = @"/// -/// If this method succeeds, it returns S_OK. -/// "; + var code = """ + /// + /// If this method succeeds, it returns S_OK. + /// + """; TestNormalizeDeclaration(code, code); } - [Theory] - [InlineData("_=()=>{};", "_ = () =>\r\n{\r\n};")] - [InlineData("_=x=>{};", "_ = x =>\r\n{\r\n};")] - [InlineData("Add(()=>{});", "Add(() =>\r\n{\r\n});")] - [InlineData("Add(delegate(){});", "Add(delegate ()\r\n{\r\n});")] - [InlineData("Add(()=>{{_=x=>{};}});", "Add(() =>\r\n{\r\n {\r\n _ = x =>\r\n {\r\n };\r\n }\r\n});")] - [WorkItem(46656, "https://github.com/dotnet/roslyn/issues/46656")] - public void TestNormalizeBlockAnonymousFunctions(string actual, string expected) + [Fact, WorkItem(46656, "https://github.com/dotnet/roslyn/issues/46656")] + public void TestNormalizeBlockAnonymousFunctions() { - TestNormalizeStatement(actual, expected); + TestNormalizeStatement( + "_=()=>{};", """ + _ = () => + { + }; + """); + TestNormalizeStatement( + "_=x=>{};", """ + _ = x => + { + }; + """); + TestNormalizeStatement( + "Add(()=>{});", """ + Add(() => + { + }); + """); + TestNormalizeStatement( + "Add(delegate(){});", """ + Add(delegate () + { + }); + """); + TestNormalizeStatement( + "Add(()=>{{_=x=>{};}});", """ + Add(() => + { + { + _ = x => + { + }; + } + }); + """); } [Fact] public void TestNormalizeExtendedPropertyPattern() { - var text = "_ = this is{Property . Property :2};"; - - var expected = @"_ = this is { Property.Property: 2 };"; - TestNormalizeStatement(text, expected); + TestNormalizeStatement( + "_ = this is{Property . Property :2};", + "_ = this is { Property.Property: 2 };"); } - private void TestNormalize(CSharpSyntaxNode node, string expected) + private static void TestNormalize(CSharpSyntaxNode node, string expected) { var actual = node.NormalizeWhitespace(" ").ToFullString(); Assert.Equal(expected.NormalizeLineEndings(), actual.NormalizeLineEndings()); } - private void TestNormalizeTrivia(string text, string expected) + private static void TestNormalizeTrivia(string text, string expected) { - var list = SyntaxFactory.ParseLeadingTrivia(text); + var list = SyntaxFactory.ParseLeadingTrivia(text.NormalizeLineEndings()); TestNormalize(list, expected.NormalizeLineEndings()); } - private void TestNormalize(SyntaxTriviaList trivia, string expected) + private static void TestNormalize(SyntaxTriviaList trivia, string expected) { var actual = trivia.NormalizeWhitespace(" ").ToFullString(); Assert.Equal(expected.NormalizeLineEndings(), actual.NormalizeLineEndings()); } - [Fact] - [WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] + [Fact, WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] public void TestNormalizeXmlArgumentsInDocComment1() { - const string Expected = @"/// Prefix S_OK suffix"; - const string Text = @"/// Prefix S_OK suffix"; - TestNormalizeDeclaration(Text, Expected); + TestNormalizeDeclaration( + """/// Prefix S_OK suffix""", + """/// Prefix S_OK suffix"""); } - [Fact] - [WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] + [Fact, WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] public void TestNormalizeXmlArgumentsInDocComment2() { - const string Expected = @"/// Prefix S_OK suffix"; - TestNormalizeDeclaration(Expected, Expected); + var code = """/// Prefix S_OK suffix"""; + TestNormalizeDeclaration(code, code); } - [Fact] - [WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] + [Fact, WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] public void TestNormalizeXmlArgumentsInDocComment3() { - const string Expected = @"/// Prefix suffix"; - const string Text = @"/// Prefix suffix"; - TestNormalizeDeclaration(Text, Expected); + TestNormalizeDeclaration( + """/// Prefix suffix""", + """/// Prefix suffix"""); } - [Fact] - [WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] + [Fact, WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] public void TestNormalizeXmlArgumentsInDocComment4() { - const string Expected = @"/// Prefix S_OK suffix"; - const string Text = @"/// Prefix S_OK suffix"; - TestNormalizeDeclaration(Text, Expected); + TestNormalizeDeclaration( + """/// Prefix S_OK suffix""", + """/// Prefix S_OK suffix"""); } - [Fact] - [WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] + [Fact, WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] public void TestNormalizeXmlArgumentsInDocComment5() { - const string Expected = @"/// Prefix suffix"; - TestNormalizeDeclaration(Expected, Expected); + var code = """/// Prefix suffix"""; + TestNormalizeDeclaration(code, code); } - [Fact] - [WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] + [Fact, WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] public void TestNormalizeXmlArgumentsInDocComment6() { - const string Expected = @"/// Prefix suffix"; - const string Text = @"/// Prefix suffix"; - TestNormalizeDeclaration(Text, Expected); + TestNormalizeDeclaration( + """/// Prefix suffix""", + """/// Prefix suffix"""); } - [Fact] - [WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] + [Fact, WorkItem(60884, "https://github.com/dotnet/roslyn/issues/60884")] public void TestNormalizeXmlArgumentsInDocComment7() { - const string Expected = @"/// Prefix S_OK suffix"; - const string Text = @"/// Prefix S_OK suffix"; - TestNormalizeDeclaration(Text, Expected); + TestNormalizeDeclaration( + """/// Prefix S_OK suffix""", + """/// Prefix S_OK suffix"""); } [Fact] public void TestRequiredKeywordNormalization() { - const string Expected = @"public required partial int Field;"; - const string Text = @"public required partial int Field;"; - TestNormalizeDeclaration(Text, Expected); + TestNormalizeDeclaration( + "public required partial int Field;", + "public required partial int Field;"); } - [Fact] - [WorkItem(61518, "https://github.com/dotnet/roslyn/issues/61518")] + [Fact, WorkItem(61518, "https://github.com/dotnet/roslyn/issues/61518")] public void TestNormalizeNestedUsingStatements1() { - TestNormalizeStatement("using(a)using(b)c;", "using (a)\r\nusing (b)\r\n c;"); - TestNormalizeStatement("using(a)using(b){c;}", "using (a)\r\nusing (b)\r\n{\r\n c;\r\n}"); - TestNormalizeStatement("using(a)using(b)using(c)d;", "using (a)\r\nusing (b)\r\nusing (c)\r\n d;"); - TestNormalizeStatement("using(a)using(b)using(c){d;}", "using (a)\r\nusing (b)\r\nusing (c)\r\n{\r\n d;\r\n}"); + TestNormalizeStatement( + "using(a)using(b)c;", """ + using (a) + using (b) + c; + """); + TestNormalizeStatement( + "using(a)using(b){c;}", """ + using (a) + using (b) + { + c; + } + """); + TestNormalizeStatement( + "using(a)using(b)using(c)d;", """ + using (a) + using (b) + using (c) + d; + """); + TestNormalizeStatement( + "using(a)using(b)using(c){d;}", """ + using (a) + using (b) + using (c) + { + d; + } + """); - TestNormalizeStatement("using(a){using(b)c;}", "using (a)\r\n{\r\n using (b)\r\n c;\r\n}"); - TestNormalizeStatement("using(a){using(b)using(c)d;}", "using (a)\r\n{\r\n using (b)\r\n using (c)\r\n d;\r\n}"); - TestNormalizeStatement("using(a)using(b){using(c)d;}", "using (a)\r\nusing (b)\r\n{\r\n using (c)\r\n d;\r\n}"); - TestNormalizeStatement("using(a){using(b){using(c)d;}}", "using (a)\r\n{\r\n using (b)\r\n {\r\n using (c)\r\n d;\r\n }\r\n}"); + TestNormalizeStatement( + "using(a){using(b)c;}", """ + using (a) + { + using (b) + c; + } + """); + TestNormalizeStatement( + "using(a){using(b)using(c)d;}", """ + using (a) + { + using (b) + using (c) + d; + } + """); + TestNormalizeStatement( + "using(a)using(b){using(c)d;}", """ + using (a) + using (b) + { + using (c) + d; + } + """); + TestNormalizeStatement( + "using(a){using(b){using(c)d;}}", """ + using (a) + { + using (b) + { + using (c) + d; + } + } + """); } - [Fact] - [WorkItem(61518, "https://github.com/dotnet/roslyn/issues/61518")] + [Fact, WorkItem(61518, "https://github.com/dotnet/roslyn/issues/61518")] public void TestNormalizeNestedFixedStatements1() { - TestNormalizeStatement("fixed(int* a = null)fixed(int* b = null)c;", "fixed (int* a = null)\r\nfixed (int* b = null)\r\n c;"); - TestNormalizeStatement("fixed(int* a = null)fixed(int* b = null){c;}", "fixed (int* a = null)\r\nfixed (int* b = null)\r\n{\r\n c;\r\n}"); - TestNormalizeStatement("fixed(int* a = null)fixed(int* b = null)fixed(int* c = null)d;", "fixed (int* a = null)\r\nfixed (int* b = null)\r\nfixed (int* c = null)\r\n d;"); - TestNormalizeStatement("fixed(int* a = null)fixed(int* b = null)fixed(int* c = null){d;}", "fixed (int* a = null)\r\nfixed (int* b = null)\r\nfixed (int* c = null)\r\n{\r\n d;\r\n}"); + TestNormalizeStatement( + "fixed(int* a = null)fixed(int* b = null)c;", """ + fixed (int* a = null) + fixed (int* b = null) + c; + """); + TestNormalizeStatement( + "fixed(int* a = null)fixed(int* b = null){c;}", """ + fixed (int* a = null) + fixed (int* b = null) + { + c; + } + """); + TestNormalizeStatement( + "fixed(int* a = null)fixed(int* b = null)fixed(int* c = null)d;", """ + fixed (int* a = null) + fixed (int* b = null) + fixed (int* c = null) + d; + """); + TestNormalizeStatement( + "fixed(int* a = null)fixed(int* b = null)fixed(int* c = null){d;}", """ + fixed (int* a = null) + fixed (int* b = null) + fixed (int* c = null) + { + d; + } + """); - TestNormalizeStatement("fixed(int* a = null){fixed(int* b = null)c;}", "fixed (int* a = null)\r\n{\r\n fixed (int* b = null)\r\n c;\r\n}"); - TestNormalizeStatement("fixed(int* a = null){fixed(int* b = null)fixed(int* c = null)d;}", "fixed (int* a = null)\r\n{\r\n fixed (int* b = null)\r\n fixed (int* c = null)\r\n d;\r\n}"); - TestNormalizeStatement("fixed(int* a = null)fixed(int* b = null){fixed(int* c = null)d;}", "fixed (int* a = null)\r\nfixed (int* b = null)\r\n{\r\n fixed (int* c = null)\r\n d;\r\n}"); - TestNormalizeStatement("fixed(int* a = null){fixed(int* b = null){fixed(int* c = null)d;}}", "fixed (int* a = null)\r\n{\r\n fixed (int* b = null)\r\n {\r\n fixed (int* c = null)\r\n d;\r\n }\r\n}"); + TestNormalizeStatement( + "fixed(int* a = null){fixed(int* b = null)c;}", """ + fixed (int* a = null) + { + fixed (int* b = null) + c; + } + """); + TestNormalizeStatement( + "fixed(int* a = null){fixed(int* b = null)fixed(int* c = null)d;}", """ + fixed (int* a = null) + { + fixed (int* b = null) + fixed (int* c = null) + d; + } + """); + TestNormalizeStatement( + "fixed(int* a = null)fixed(int* b = null){fixed(int* c = null)d;}", """ + fixed (int* a = null) + fixed (int* b = null) + { + fixed (int* c = null) + d; + } + """); + TestNormalizeStatement( + "fixed(int* a = null){fixed(int* b = null){fixed(int* c = null)d;}}", """ + fixed (int* a = null) + { + fixed (int* b = null) + { + fixed (int* c = null) + d; + } + } + """); } - [Fact] - [WorkItem(61518, "https://github.com/dotnet/roslyn/issues/61518")] + [Fact, WorkItem(61518, "https://github.com/dotnet/roslyn/issues/61518")] public void TestNormalizeNestedFixedUsingStatements1() { - TestNormalizeStatement("using(a)fixed(int* b = null)c;", "using (a)\r\n fixed (int* b = null)\r\n c;"); - TestNormalizeStatement("fixed(int* b = null)using(a)c;", "fixed (int* b = null)\r\n using (a)\r\n c;"); + TestNormalizeStatement( + "using(a)fixed(int* b = null)c;", """ + using (a) + fixed (int* b = null) + c; + """); + TestNormalizeStatement( + "fixed(int* b = null)using(a)c;", """ + fixed (int* b = null) + using (a) + c; + """); } [Fact] public void TestNormalizeScopedParameters() { - TestNormalizeStatement("static void F ( scoped R x , scoped ref R y , ref scoped R z ) { }", "static void F(scoped R x, scoped ref R y, ref scoped R z)\r\n{\r\n}"); + TestNormalizeStatement( + "static void F ( scoped R x , scoped ref R y , ref scoped R z ) { }", """ + static void F(scoped R x, scoped ref R y, ref scoped R z) + { + } + """); } [Fact] @@ -3060,7 +5058,7 @@ void M() """); } - private void VerifySingleLineInitializer(string text, string expected) + private static void VerifySingleLineInitializer(string text, string expected) { TestNormalizeExpression( "$\"{" + text + "}\"",