Skip to content

Commit e139096

Browse files
committed
Update SA1133 tests for attributed local functions
1 parent ff14d11 commit e139096

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/ReadabilityRules/SA1133CSharp9UnitTests.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,70 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
11+
StyleCop.Analyzers.ReadabilityRules.SA1133DoNotCombineAttributes,
12+
StyleCop.Analyzers.ReadabilityRules.SA1133CodeFixProvider>;
713

814
public partial class SA1133CSharp9UnitTests : SA1133CSharp8UnitTests
915
{
16+
[Fact]
17+
[WorkItem(3978, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3978")]
18+
public async Task TestLocalFunctionAttributeListAsync()
19+
{
20+
var testCode = @"using System;
21+
22+
class TestClass
23+
{
24+
void Outer()
25+
{
26+
[Attr1, {|#0:Attr2|}]
27+
void Local()
28+
{
29+
}
30+
}
31+
}
32+
33+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
34+
class Attr1Attribute : Attribute
35+
{
36+
}
37+
38+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
39+
class Attr2Attribute : Attribute
40+
{
41+
}
42+
";
43+
44+
var fixedCode = @"using System;
45+
46+
class TestClass
47+
{
48+
void Outer()
49+
{
50+
[Attr1]
51+
[Attr2]
52+
void Local()
53+
{
54+
}
55+
}
56+
}
57+
58+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
59+
class Attr1Attribute : Attribute
60+
{
61+
}
62+
63+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
64+
class Attr2Attribute : Attribute
65+
{
66+
}
67+
";
68+
69+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
70+
}
1071
}
1172
}

0 commit comments

Comments
 (0)