Skip to content

Commit 56de02d

Browse files
committed
Update SA1017 tests for attributed local functions
1 parent 96f123a commit 56de02d

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/SpacingRules/SA1017CSharp9UnitTests.cs

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

44
namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.SpacingRules.SA1017ClosingAttributeBracketsMustBeSpacedCorrectly,
13+
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
714

815
public partial class SA1017CSharp9UnitTests : SA1017CSharp8UnitTests
916
{
17+
[Fact]
18+
[WorkItem(3978, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3978")]
19+
public async Task TestAttributesOnLocalFunctionsAsync()
20+
{
21+
var testCode = @"using System;
22+
23+
class TestClass
24+
{
25+
void Outer()
26+
{
27+
[Obsolete {|#0:]|}
28+
void Local1()
29+
{
30+
}
31+
32+
void Local2<[MyAttribute {|#1:]|} T>()
33+
{
34+
}
35+
36+
void Local3([MyAttribute {|#2:]|} int value)
37+
{
38+
}
39+
}
40+
}
41+
42+
[AttributeUsage(AttributeTargets.All)]
43+
class MyAttributeAttribute : Attribute
44+
{
45+
}
46+
";
47+
48+
var fixedCode = @"using System;
49+
50+
class TestClass
51+
{
52+
void Outer()
53+
{
54+
[Obsolete]
55+
void Local1()
56+
{
57+
}
58+
59+
void Local2<[MyAttribute] T>()
60+
{
61+
}
62+
63+
void Local3([MyAttribute] int value)
64+
{
65+
}
66+
}
67+
}
68+
69+
[AttributeUsage(AttributeTargets.All)]
70+
class MyAttributeAttribute : Attribute
71+
{
72+
}
73+
";
74+
75+
DiagnosticResult[] expected =
76+
{
77+
Diagnostic().WithLocation(0),
78+
Diagnostic().WithLocation(1),
79+
Diagnostic().WithLocation(2),
80+
};
81+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
82+
}
1083
}
1184
}

0 commit comments

Comments
 (0)