Skip to content

Commit e2e7ed3

Browse files
committed
Add attribute argument list tests
1 parent b879caf commit e2e7ed3

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,91 @@ class MyAttribute : Attribute { }
646646
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
647647
}
648648

649+
[Fact]
650+
public async Task TestAttributeArgumentListAsync()
651+
{
652+
string testCode = @"
653+
using System;
654+
655+
[My(0)]
656+
[My(
657+
0)]
658+
[My(
659+
0, Y = 2)]
660+
class TypeName1
661+
{
662+
}
663+
664+
[My(
665+
0,
666+
Y = 2,
667+
Z = 3)]
668+
[My(
669+
0,
670+
Y = 2,
671+
Z = 3)]
672+
class TypeName2
673+
{
674+
}
675+
676+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
677+
class MyAttribute : Attribute
678+
{
679+
public MyAttribute() { }
680+
public MyAttribute(int value) { }
681+
682+
public int Y { get; set; }
683+
public int Z { get; set; }
684+
}
685+
";
686+
string fixedCode = @"
687+
using System;
688+
689+
[My(0)]
690+
[My(
691+
0)]
692+
[My(
693+
0, Y = 2)]
694+
class TypeName1
695+
{
696+
}
697+
698+
[My(
699+
0,
700+
Y = 2,
701+
Z = 3)]
702+
[My(
703+
0,
704+
Y = 2,
705+
Z = 3)]
706+
class TypeName2
707+
{
708+
}
709+
710+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
711+
class MyAttribute : Attribute
712+
{
713+
public MyAttribute() { }
714+
public MyAttribute(int value) { }
715+
716+
public int Y { get; set; }
717+
public int Z { get; set; }
718+
}
719+
";
720+
721+
DiagnosticResult[] expected =
722+
{
723+
this.CSharpDiagnostic().WithLocation(15, 1),
724+
this.CSharpDiagnostic().WithLocation(16, 1),
725+
this.CSharpDiagnostic().WithLocation(19, 1),
726+
this.CSharpDiagnostic().WithLocation(20, 1),
727+
};
728+
729+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
730+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
731+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
732+
}
733+
649734
[Fact]
650735
public async Task TestBlockAsync()
651736
{

0 commit comments

Comments
 (0)