|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp8.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.CSharp7.SpacingRules;
|
| 11 | + using StyleCop.Analyzers.Test.Verifiers; |
| 12 | + using Xunit; |
| 13 | + |
| 14 | + using static StyleCop.Analyzers.SpacingRules.SA1003SymbolsMustBeSpacedCorrectly; |
| 15 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 16 | + StyleCop.Analyzers.SpacingRules.SA1003SymbolsMustBeSpacedCorrectly, |
| 17 | + StyleCop.Analyzers.SpacingRules.SA1003CodeFixProvider>; |
7 | 18 |
|
8 | 19 | public class SA1003CSharp8UnitTests : SA1003CSharp7UnitTests
|
9 | 20 | {
|
| 21 | + /// <summary> |
| 22 | + /// Verifies that spacing around a range expression double dots isn't required. |
| 23 | + /// </summary> |
| 24 | + /// <remarks> |
| 25 | + /// <para>Double dots of range expressions already provide enough spacing for readability so there is no |
| 26 | + /// need to surround the range expression with spaces.</para> |
| 27 | + /// </remarks> |
| 28 | + /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> |
| 29 | + [Fact] |
| 30 | + public async Task TestRangeExpressionAsync() |
| 31 | + { |
| 32 | + var testCode = SpecialTypeDefinitions.IndexAndRange + @" |
| 33 | +namespace TestNamespace |
| 34 | +{ |
| 35 | + using System; |
| 36 | + public class TestClass |
| 37 | + { |
| 38 | + public void TestMethod() |
| 39 | + { |
| 40 | + var test1 = .. (int)1; |
| 41 | + } |
| 42 | + } |
| 43 | +} |
| 44 | +"; |
| 45 | + |
| 46 | + var fixedCode = SpecialTypeDefinitions.IndexAndRange + @" |
| 47 | +namespace TestNamespace |
| 48 | +{ |
| 49 | + using System; |
| 50 | + public class TestClass |
| 51 | + { |
| 52 | + public void TestMethod() |
| 53 | + { |
| 54 | + var test1 = ..(int)1; |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | +"; |
| 59 | + var expectedResults = new DiagnosticResult[] |
| 60 | + { |
| 61 | + Diagnostic(DescriptorNotPrecededByWhitespace).WithLocation(26, 28).WithArguments("(int)"), |
| 62 | + }; |
| 63 | + |
| 64 | + await VerifyCSharpFixAsync( |
| 65 | + LanguageVersion.CSharp8, |
| 66 | + testCode, |
| 67 | + expectedResults, |
| 68 | + fixedCode, |
| 69 | + CancellationToken.None).ConfigureAwait(false); |
| 70 | + } |
10 | 71 | }
|
11 | 72 | }
|
0 commit comments