|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp11.SpacingRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
6 | 8 | using StyleCop.Analyzers.Test.CSharp10.SpacingRules; |
| 9 | + using Xunit; |
| 10 | + |
| 11 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 12 | + StyleCop.Analyzers.SpacingRules.SA1000KeywordsMustBeSpacedCorrectly, |
| 13 | + StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>; |
7 | 14 |
|
8 | 15 | public class SA1000CSharp11UnitTests : SA1000CSharp10UnitTests |
9 | 16 | { |
| 17 | + [Fact] |
| 18 | + public async Task TestCheckedOperatorDeclarationAsync() |
| 19 | + { |
| 20 | + // NOTE: A checked operator requires a non-checked operator as well |
| 21 | + // NOTE: Implicit conversion operators can not be checked |
| 22 | + var testCode = @" |
| 23 | +public class MyClass |
| 24 | +{ |
| 25 | + public static MyClass operator {|#0:checked|}-(MyClass x) => x; |
| 26 | + public static MyClass operator -(MyClass x) => x; |
| 27 | +
|
| 28 | + public static explicit operator {|#1:checked|}@MyClass(int i) => new MyClass(); |
| 29 | + public static explicit operator MyClass(int i) => new MyClass(); |
| 30 | +}"; |
| 31 | + |
| 32 | + var fixedCode = @" |
| 33 | +public class MyClass |
| 34 | +{ |
| 35 | + public static MyClass operator checked -(MyClass x) => x; |
| 36 | + public static MyClass operator -(MyClass x) => x; |
| 37 | +
|
| 38 | + public static explicit operator checked @MyClass(int i) => new MyClass(); |
| 39 | + public static explicit operator MyClass(int i) => new MyClass(); |
| 40 | +}"; |
| 41 | + |
| 42 | + var expected = new[] |
| 43 | + { |
| 44 | + Diagnostic().WithArguments("checked", string.Empty, "followed").WithLocation(0), |
| 45 | + Diagnostic().WithArguments("checked", string.Empty, "followed").WithLocation(1), |
| 46 | + }; |
| 47 | + await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 48 | + } |
10 | 49 | } |
11 | 50 | } |
0 commit comments