Skip to content

Commit c19a1fe

Browse files
committed
Add tests for type parameter lists
1 parent b84892b commit c19a1fe

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1137UnitTests.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,74 @@ public async Task TestTypeDeclarationConstraintClausesAsync(string typeKind)
223223
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
224224
}
225225

226+
[Theory]
227+
[InlineData("class", " { }")]
228+
[InlineData("void", "() { }")]
229+
public async Task TestValidTypeParameterListAsync(string prefix, string suffix)
230+
{
231+
string testCode = $@"
232+
class Container
233+
{{
234+
{prefix} ClassName1<T>{suffix}
235+
236+
{prefix} ClassName2<
237+
T>{suffix}
238+
239+
{prefix} ClassName3<
240+
T1, T2>{suffix}
241+
}}
242+
";
243+
244+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
245+
}
246+
247+
[Theory]
248+
[InlineData("class", " { }")]
249+
[InlineData("void", "() { }")]
250+
public async Task TestTypeParameterListAsync(string prefix, string suffix)
251+
{
252+
string testCode = $@"
253+
class Container
254+
{{
255+
{prefix} NonZeroAlignment<
256+
X,
257+
Y,
258+
Z>{suffix}
259+
260+
{prefix} ZeroAlignment<
261+
X,
262+
Y,
263+
Z>{suffix}
264+
}}
265+
";
266+
string fixedCode = $@"
267+
class Container
268+
{{
269+
{prefix} NonZeroAlignment<
270+
X,
271+
Y,
272+
Z>{suffix}
273+
274+
{prefix} ZeroAlignment<
275+
X,
276+
Y,
277+
Z>{suffix}
278+
}}
279+
";
280+
281+
DiagnosticResult[] expected =
282+
{
283+
this.CSharpDiagnostic().WithLocation(6, 1),
284+
this.CSharpDiagnostic().WithLocation(7, 1),
285+
this.CSharpDiagnostic().WithLocation(11, 1),
286+
this.CSharpDiagnostic().WithLocation(12, 1),
287+
};
288+
289+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
290+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
291+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
292+
}
293+
226294
[Fact]
227295
public async Task TestBlockAsync()
228296
{

0 commit comments

Comments
 (0)