Skip to content

Commit b879caf

Browse files
committed
Add tests for attribute lists
1 parent 18d33e4 commit b879caf

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,77 @@ class Container
575575
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
576576
}
577577

578+
[Fact]
579+
public async Task TestAttributeListAsync()
580+
{
581+
string testCode = @"
582+
using System;
583+
584+
[My]
585+
[
586+
My]
587+
[
588+
My, My]
589+
class TypeName1
590+
{
591+
}
592+
593+
[
594+
My,
595+
My,
596+
My]
597+
[
598+
My,
599+
My,
600+
My]
601+
class TypeName2
602+
{
603+
}
604+
605+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
606+
class MyAttribute : Attribute { }
607+
";
608+
string fixedCode = @"
609+
using System;
610+
611+
[My]
612+
[
613+
My]
614+
[
615+
My, My]
616+
class TypeName1
617+
{
618+
}
619+
620+
[
621+
My,
622+
My,
623+
My]
624+
[
625+
My,
626+
My,
627+
My]
628+
class TypeName2
629+
{
630+
}
631+
632+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
633+
class MyAttribute : Attribute { }
634+
";
635+
636+
DiagnosticResult[] expected =
637+
{
638+
this.CSharpDiagnostic().WithLocation(15, 1),
639+
this.CSharpDiagnostic().WithLocation(16, 1),
640+
this.CSharpDiagnostic().WithLocation(19, 1),
641+
this.CSharpDiagnostic().WithLocation(20, 1),
642+
};
643+
644+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
645+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
646+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
647+
}
648+
578649
[Fact]
579650
public async Task TestBlockAsync()
580651
{

0 commit comments

Comments
 (0)