@@ -985,6 +985,49 @@ await Task.Delay(1000)
985985 await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
986986 }
987987
988+ [ Theory ]
989+ [ InlineData ( "if (true)" ) ]
990+ [ InlineData ( "while (true)" ) ]
991+ [ InlineData ( "for (var i = 0; i < 10; i++)" ) ]
992+ [ InlineData ( "foreach (var i in a)" ) ]
993+ [ WorkItem ( 3731 , "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3731" ) ]
994+ public async Task TestControlStatementWithBodyOnSameLineAsync ( string stmt )
995+ {
996+ var testCode = $@ "
997+ public class TestClass
998+ {{
999+ public async void TestMethod(int x, int[] a)
1000+ {{
1001+ { stmt } ++x;
1002+ { stmt } --x;
1003+ { stmt } x++;
1004+ { stmt } {{ x++; }}
1005+ }}
1006+ }}" ;
1007+
1008+ var fixedCode = $@ "
1009+ public class TestClass
1010+ {{
1011+ public async void TestMethod(int x, int[] a)
1012+ {{
1013+ { stmt } ++x;
1014+ { stmt } --x;
1015+ { stmt } x++;
1016+ { stmt } {{ x++; }}
1017+ }}
1018+ }}" ;
1019+
1020+ var expected = new [ ]
1021+ {
1022+ Diagnostic ( DescriptorFollowed ) . WithLocation ( 6 , 8 + stmt . Length ) ,
1023+ Diagnostic ( DescriptorFollowed ) . WithLocation ( 7 , 8 + stmt . Length ) ,
1024+ Diagnostic ( DescriptorFollowed ) . WithLocation ( 8 , 8 + stmt . Length ) ,
1025+ Diagnostic ( DescriptorFollowed ) . WithLocation ( 9 , 8 + stmt . Length ) ,
1026+ } ;
1027+
1028+ await VerifyCSharpFixAsync ( testCode , expected , fixedCode , CancellationToken . None ) . ConfigureAwait ( false ) ;
1029+ }
1030+
9881031 private async Task TestWhitespaceInStatementOrDeclAsync ( string originalStatement , string fixedStatement , params DiagnosticResult [ ] expected )
9891032 {
9901033 string template = @"namespace Foo
0 commit comments