|
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.CSharp; |
| 9 | + using Microsoft.CodeAnalysis.Testing; |
6 | 10 | using StyleCop.Analyzers.Test.CSharp8.SpacingRules; |
| 11 | + using StyleCop.Analyzers.Test.Verifiers; |
| 12 | + using Xunit; |
| 13 | + using static StyleCop.Analyzers.SpacingRules.SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly; |
| 14 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 15 | + StyleCop.Analyzers.SpacingRules.SA1023DereferenceAndAccessOfSymbolsMustBeSpacedCorrectly, |
| 16 | + StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>; |
7 | 17 |
|
8 | 18 | public class SA1023CSharp9UnitTests : SA1023CSharp8UnitTests |
9 | 19 | { |
| 20 | + [Fact] |
| 21 | + public async Task TestFunctionPointerParameterInvalidSpacingAsync() |
| 22 | + { |
| 23 | + var testCode = @"public class TestClass |
| 24 | +{ |
| 25 | + unsafe delegate*<int {|#0:*|}> FuncPtr1; |
| 26 | + unsafe delegate*<int{|#1:*|} > FuncPtr2; |
| 27 | +} |
| 28 | +"; |
| 29 | + |
| 30 | + var fixedCode = @"public class TestClass |
| 31 | +{ |
| 32 | + unsafe delegate*<int*> FuncPtr1; |
| 33 | + unsafe delegate*<int*> FuncPtr2; |
| 34 | +} |
| 35 | +"; |
| 36 | + |
| 37 | + var expected = new[] |
| 38 | + { |
| 39 | + Diagnostic(DescriptorNotPreceded).WithLocation(0), |
| 40 | + Diagnostic(DescriptorNotFollowed).WithLocation(1), |
| 41 | + }; |
| 42 | + |
| 43 | + await VerifyCSharpFixAsync(LanguageVersion.CSharp9, testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public async Task TestFunctionPointerTypeInvalidSpacingAsync() |
| 48 | + { |
| 49 | + var testCode = @"public class TestClass |
| 50 | +{ |
| 51 | + unsafe delegate {|#0:*|}<int*> FuncPtr1; |
| 52 | + unsafe delegate{|#1:*|} <int*> FuncPtr2; |
| 53 | + unsafe delegate {|#2:*|} managed<int*> FuncPtr3; |
| 54 | + unsafe delegate{|#3:*|}managed<int*> FuncPtr4; |
| 55 | + unsafe delegate {|#4:*|} unmanaged<int*> FuncPtr5; |
| 56 | + unsafe delegate{|#5:*|}unmanaged<int*> FuncPtr6; |
| 57 | +} |
| 58 | +"; |
| 59 | + |
| 60 | + var fixedCode = @"public class TestClass |
| 61 | +{ |
| 62 | + unsafe delegate*<int*> FuncPtr1; |
| 63 | + unsafe delegate*<int*> FuncPtr2; |
| 64 | + unsafe delegate* managed<int*> FuncPtr3; |
| 65 | + unsafe delegate* managed<int*> FuncPtr4; |
| 66 | + unsafe delegate* unmanaged<int*> FuncPtr5; |
| 67 | + unsafe delegate* unmanaged<int*> FuncPtr6; |
| 68 | +} |
| 69 | +"; |
| 70 | + |
| 71 | + await new CSharpTest(LanguageVersion.CSharp9) |
| 72 | + { |
| 73 | + ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50, |
| 74 | + TestCode = testCode, |
| 75 | + FixedCode = fixedCode, |
| 76 | + ExpectedDiagnostics = |
| 77 | + { |
| 78 | + Diagnostic(DescriptorNotPreceded).WithLocation(0), |
| 79 | + Diagnostic(DescriptorNotFollowed).WithLocation(1), |
| 80 | + Diagnostic(DescriptorNotPreceded).WithLocation(2), |
| 81 | + Diagnostic(DescriptorFollowed).WithLocation(3), |
| 82 | + Diagnostic(DescriptorNotPreceded).WithLocation(4), |
| 83 | + Diagnostic(DescriptorFollowed).WithLocation(5), |
| 84 | + }, |
| 85 | + }.RunAsync().ConfigureAwait(false); |
| 86 | + } |
10 | 87 | } |
11 | 88 | } |
0 commit comments