Skip to content

Commit 4b4bfdb

Browse files
committed
Added additional test cases
1 parent 6644806 commit 4b4bfdb

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1500/SA1500UnitTests.ArrayInitializers.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,5 +433,94 @@ public class TestClass
433433
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
434434
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
435435
}
436+
437+
/// <summary>
438+
/// Verifies that a jagged array initialization produces the expected diagnostics.
439+
/// </summary>
440+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
441+
[Fact]
442+
[WorkItem(2632, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2632")]
443+
public async Task VerifyJaggedArrayInitializationAsync()
444+
{
445+
var testCode = @"
446+
public class TestClass
447+
{
448+
private static readonly int[][] TestMatrix1 =
449+
new int[][]
450+
{
451+
new[] { 0, 0, 1, 1 },
452+
new[] { 1, 1, 1, 0 },
453+
new[] { 0, 1, 0, 0 }
454+
};
455+
456+
private static readonly int[][] TestMatrix2 =
457+
new int[][]
458+
{ new[] { 0, 0, 1, 1 },
459+
new[] { 1, 1, 1, 0 },
460+
new[] { 0, 1, 0, 0 }
461+
};
462+
463+
private static readonly int[][] TestMatrix3 =
464+
new int[][]
465+
{
466+
new[] { 0, 0, 1, 1 },
467+
new[] { 1, 1, 1, 0 },
468+
new[] { 0, 1, 0, 0 } };
469+
470+
private static readonly int[][] TestMatrix4 =
471+
new int[][]
472+
{
473+
new[] { 0, 0, 1, 1 }, new[] { 1, 1, 1, 0 },
474+
new[] { 0, 1, 0, 0 }
475+
};
476+
}
477+
";
478+
479+
var fixedTestCode = @"
480+
public class TestClass
481+
{
482+
private static readonly int[][] TestMatrix1 =
483+
new int[][]
484+
{
485+
new[] { 0, 0, 1, 1 },
486+
new[] { 1, 1, 1, 0 },
487+
new[] { 0, 1, 0, 0 }
488+
};
489+
490+
private static readonly int[][] TestMatrix2 =
491+
new int[][]
492+
{
493+
new[] { 0, 0, 1, 1 },
494+
new[] { 1, 1, 1, 0 },
495+
new[] { 0, 1, 0, 0 }
496+
};
497+
498+
private static readonly int[][] TestMatrix3 =
499+
new int[][]
500+
{
501+
new[] { 0, 0, 1, 1 },
502+
new[] { 1, 1, 1, 0 },
503+
new[] { 0, 1, 0, 0 }
504+
};
505+
506+
private static readonly int[][] TestMatrix4 =
507+
new int[][]
508+
{
509+
new[] { 0, 0, 1, 1 }, new[] { 1, 1, 1, 0 },
510+
new[] { 0, 1, 0, 0 }
511+
};
512+
}
513+
";
514+
515+
DiagnosticResult[] expectedDiagnostics =
516+
{
517+
this.CSharpDiagnostic().WithLocation(14, 9),
518+
this.CSharpDiagnostic().WithLocation(24, 34),
519+
};
520+
521+
await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false);
522+
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
523+
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
524+
}
436525
}
437526
}

0 commit comments

Comments
 (0)