|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.Testing; |
6 | 9 | 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>; |
7 | 14 |
|
8 | 15 | public partial class SA1017CSharp9UnitTests : SA1017CSharp8UnitTests |
9 | 16 | { |
| 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 | + } |
10 | 83 | } |
11 | 84 | } |
0 commit comments