11// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22// Licensed under the MIT License. See LICENSE in the project root for license information.
33
4- // Several test methods in this file use the same member data, but in some cases the test does not use all of the
5- // supported parameters. See https://github.com/xunit/xunit/issues/1556.
6- #pragma warning disable xUnit1026 // Theory methods should use all of their parameters
7-
84namespace StyleCop . Analyzers . Test . ReadabilityRules
95{
106 using System . Collections . Generic ;
117 using System . Threading ;
128 using System . Threading . Tasks ;
139 using Microsoft . CodeAnalysis . Testing ;
14- using TestHelper ;
1510 using Xunit ;
1611 using static StyleCop . Analyzers . Test . Verifiers . StyleCopDiagnosticVerifier < StyleCop . Analyzers . ReadabilityRules . SA1117ParametersMustBeOnSameLineOrSeparateLines > ;
1712
1813 public class SA1117UnitTests
1914 {
2015 public static IEnumerable < object [ ] > GetTestDeclarations ( string delimiter )
2116 {
22- yield return new object [ ] { $ "public Foo(int a, int b,{ delimiter } string s) {{ }}" } ;
23- yield return new object [ ] { $ "public object Bar(int a, int b,{ delimiter } string s) => null;" } ;
24- yield return new object [ ] { $ "public object this[int a, int b,{ delimiter } string s] => null;" } ;
25- yield return new object [ ] { $ "public delegate void Bar(int a, int b,{ delimiter } string s);" } ;
17+ yield return new object [ ] { $ "public Foo(int a, int b,{ delimiter } {{|#0: string s|}} ) {{ }}" } ;
18+ yield return new object [ ] { $ "public object Bar(int a, int b,{ delimiter } {{|#0: string s|}} ) => null;" } ;
19+ yield return new object [ ] { $ "public object this[int a, int b,{ delimiter } {{|#0: string s|}} ] => null;" } ;
20+ yield return new object [ ] { $ "public delegate void Bar(int a, int b,{ delimiter } {{|#0: string s|}} );" } ;
2621 }
2722
2823 public static IEnumerable < object [ ] > GetTestConstructorInitializers ( string delimiter )
2924 {
30- yield return new object [ ] { $ "this(42, 43, { delimiter } \" hello\" )" } ;
31- yield return new object [ ] { $ "base(42, 43, { delimiter } \" hello\" )" } ;
25+ yield return new object [ ] { $ "this(42, 43, { delimiter } {{|#0: \" hello\" |}} )" } ;
26+ yield return new object [ ] { $ "base(42, 43, { delimiter } {{|#0: \" hello\" |}} )" } ;
3227 }
3328
3429 public static IEnumerable < object [ ] > GetTestExpressions ( string delimiter )
3530 {
36- yield return new object [ ] { $ "Bar(1, 2, { delimiter } 2)" , 13 } ;
37- yield return new object [ ] { $ "System.Action<int, int, int> func = (int x, int y, { delimiter } int z) => Bar(x, y, z)", 41 } ;
38- yield return new object [ ] { $ "System.Action<int, int, int> func = delegate(int x, int y, { delimiter } int z) {{ Bar(x, y, z); }}", 49 } ;
39- yield return new object [ ] { $ "new System.DateTime(2015, 9, { delimiter } 14)" , 20 } ;
40- yield return new object [ ] { $ "var arr = new string[2, 2, { delimiter } 2 ];", 30 } ;
41- yield return new object [ ] { $ "char cc = (new char[3, 3, 3])[2, 2,{ delimiter } 2 ];", 36 } ;
42- yield return new object [ ] { $ "char? c = (new char[3, 3, 3])?[2, 2,{ delimiter } 2 ];", 37 } ;
43- yield return new object [ ] { $ "long ll = this[2, 2,{ delimiter } 2 ];", 24 } ;
31+ yield return new object [ ] { $ "Bar(1, 2, { delimiter } {{|#0:2|}})" } ;
32+ yield return new object [ ] { $ "System.Action<int, int, int> func = (int x, int y, { delimiter } {{|#0: int z|}} ) => Bar(x, y, z)" } ;
33+ yield return new object [ ] { $ "System.Action<int, int, int> func = delegate(int x, int y, { delimiter } {{|#0: int z|}} ) {{ Bar(x, y, z); }}" } ;
34+ yield return new object [ ] { $ "new System.DateTime(2015, 9, { delimiter } {{|#0:14|}})" } ;
35+ yield return new object [ ] { $ "var arr = new string[2, 2, { delimiter } {{|#0:2|}} ];" } ;
36+ yield return new object [ ] { $ "char cc = (new char[3, 3, 3])[2, 2,{ delimiter } {{|#0:2|}} ];" } ;
37+ yield return new object [ ] { $ "char? c = (new char[3, 3, 3])?[2, 2,{ delimiter } {{|#0:2|}} ];" } ;
38+ yield return new object [ ] { $ "long ll = this[2, 2,{ delimiter } {{|#0:2|}} ];" } ;
4439 }
4540
4641 public static IEnumerable < object [ ] > ValidTestExpressions ( )
4742 {
48- yield return new object [ ] { $ "System.Action func = () => Bar(0, 2, 3)", 0 } ;
49- yield return new object [ ] { $ "System.Action<int> func = x => Bar(x, 2, 3)", 0 } ;
50- yield return new object [ ] { $ "System.Action func = delegate {{ Bar(0, 0, 0); }}", 0 } ;
51- yield return new object [ ] { "var weird = new int[10][,,,];" , 0 } ;
43+ yield return new object [ ] { $ "System.Action func = () => Bar(0, 2, 3)" } ;
44+ yield return new object [ ] { $ "System.Action<int> func = x => Bar(x, 2, 3)" } ;
45+ yield return new object [ ] { $ "System.Action func = delegate {{ Bar(0, 0, 0); }}" } ;
46+ yield return new object [ ] { "var weird = new int[10][,,,];" } ;
5247 }
5348
5449 public static IEnumerable < object [ ] > ValidTestDeclarations ( )
@@ -90,7 +85,7 @@ class Foo
9085 { declaration }
9186}}" ;
9287
93- DiagnosticResult expected = Diagnostic ( ) . WithLocation ( 5 , 2 ) ;
88+ DiagnosticResult expected = Diagnostic ( ) . WithLocation ( 0 ) ;
9489 await VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
9590 }
9691
@@ -147,18 +142,15 @@ public Derived(int i, int j, string z)
147142 }}
148143}}" ;
149144
150- DiagnosticResult expected = Diagnostic ( ) . WithLocation ( 13 , 2 ) ;
145+ DiagnosticResult expected = Diagnostic ( ) . WithLocation ( 0 ) ;
151146 await VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
152147 }
153148
154149 [ Theory ]
155150 [ MemberData ( nameof ( GetTestExpressions ) , "" ) ]
156151 [ MemberData ( nameof ( ValidTestExpressions ) ) ]
157- public async Task TestValidExpressionAsync ( string expression , int column )
152+ public async Task TestValidExpressionAsync ( string expression )
158153 {
159- // Not needed for this test
160- _ = column ;
161-
162154 var testCode = $@ "
163155class Foo
164156{{
@@ -179,11 +171,8 @@ public void Baz()
179171
180172 [ Theory ]
181173 [ MemberData ( nameof ( GetTestExpressions ) , "\r \n " ) ]
182- public async Task TestInvalidExpressionAsync ( string expression , int column )
174+ public async Task TestInvalidExpressionAsync ( string expression )
183175 {
184- // Not needed for this test
185- _ = column ;
186-
187176 var testCode = $@ "
188177class Foo
189178{{
@@ -199,7 +188,7 @@ public void Baz()
199188 public long this[int a, int b, int s] => a + b + s;
200189}}" ;
201190
202- DiagnosticResult expected = Diagnostic ( ) . WithLocation ( 11 , 2 ) ;
191+ DiagnosticResult expected = Diagnostic ( ) . WithLocation ( 0 ) ;
203192 await VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
204193 }
205194
@@ -243,12 +232,12 @@ public MyAttribute(int a, int b, int c)
243232
244233[MyAttribute(
245234 1,
246- 2, 3 )]
235+ 2, {|#0:3|} )]
247236class Foo
248237{
249238}" ;
250239
251- DiagnosticResult expected = Diagnostic ( ) . WithLocation ( 12 , 8 ) ;
240+ DiagnosticResult expected = Diagnostic ( ) . WithLocation ( 0 ) ;
252241 await VerifyCSharpDiagnosticAsync ( testCode , expected , CancellationToken . None ) . ConfigureAwait ( false ) ;
253242 }
254243 }
0 commit comments