Skip to content

Commit 462d9b9

Browse files
committed
Add test cases requested by @Przemyslaw-W
1 parent 279ca9d commit 462d9b9

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/LayoutRules/SA1509UnitTests.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,122 @@ void Bar()
673673
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
674674
}
675675

676+
[Fact]
677+
public async Task TestBlockStatementsWithBlockCommentAsync()
678+
{
679+
var testCode = @"
680+
class Foo
681+
{
682+
void Bar()
683+
{
684+
/* Comment */
685+
686+
{
687+
}
688+
689+
{
690+
}
691+
}
692+
}";
693+
694+
var fixedCode = @"
695+
class Foo
696+
{
697+
void Bar()
698+
{
699+
/* Comment */
700+
{
701+
}
702+
703+
{
704+
}
705+
}
706+
}";
707+
708+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 9);
709+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
710+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
711+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
712+
}
713+
714+
[Fact]
715+
public async Task TestBlockStatementsWithLineCommentAsync()
716+
{
717+
var testCode = @"
718+
class Foo
719+
{
720+
void Bar()
721+
{
722+
// Comment
723+
724+
{
725+
}
726+
727+
{
728+
}
729+
}
730+
}";
731+
732+
var fixedCode = @"
733+
class Foo
734+
{
735+
void Bar()
736+
{
737+
// Comment
738+
{
739+
}
740+
741+
{
742+
}
743+
}
744+
}";
745+
746+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 9);
747+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
748+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
749+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
750+
}
751+
752+
[Fact]
753+
public async Task TestBlockStatementsWithRegionAsync()
754+
{
755+
var testCode = @"
756+
class Foo
757+
{
758+
void Bar()
759+
{
760+
#region Region
761+
762+
{
763+
}
764+
765+
{
766+
}
767+
#endregion
768+
}
769+
}";
770+
771+
var fixedCode = @"
772+
class Foo
773+
{
774+
void Bar()
775+
{
776+
#region Region
777+
{
778+
}
779+
780+
{
781+
}
782+
#endregion
783+
}
784+
}";
785+
786+
DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(8, 9);
787+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
788+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
789+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
790+
}
791+
676792
[Fact]
677793
public async Task TestComplex1Async()
678794
{

0 commit comments

Comments
 (0)