|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules |
5 | 5 | { |
| 6 | + using System.Threading; |
6 | 7 | using System.Threading.Tasks; |
7 | 8 | using StyleCop.Analyzers.Test.SpacingRules; |
8 | 9 | using TestHelper; |
@@ -71,5 +72,59 @@ ref @Int32 Call(ref @Int32 p) |
71 | 72 |
|
72 | 73 | await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false); |
73 | 74 | } |
| 75 | + |
| 76 | + /// <summary> |
| 77 | + /// Verifies that spacing for tuple expressions is handled properly. |
| 78 | + /// </summary> |
| 79 | + /// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns> |
| 80 | + /// <seealso cref="SA1008CSharp7UnitTests.TestTupleExpressionsAsync"/> |
| 81 | + [Fact] |
| 82 | + public async Task TestReturnTupleExpressionsAsync() |
| 83 | + { |
| 84 | + var testCode = @"using System.Collections.Generic; |
| 85 | +
|
| 86 | +namespace TestNamespace |
| 87 | +{ |
| 88 | + public class TestClass |
| 89 | + { |
| 90 | + public void TestMethod() |
| 91 | + { |
| 92 | + // Returns (leading spaces after keyword checked in SA1000, not SA1008) |
| 93 | + (int, int) LocalFunction1() { return( 1, 2); } |
| 94 | + (int, int) LocalFunction2() { return(1, 2); } |
| 95 | + (int, int) LocalFunction3() { return ( 1, 2); } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | +"; |
| 100 | + |
| 101 | + var fixedCode = @"using System.Collections.Generic; |
| 102 | +
|
| 103 | +namespace TestNamespace |
| 104 | +{ |
| 105 | + public class TestClass |
| 106 | + { |
| 107 | + public void TestMethod() |
| 108 | + { |
| 109 | + // Returns (leading spaces after keyword checked in SA1000, not SA1008) |
| 110 | + (int, int) LocalFunction1() { return ( 1, 2); } |
| 111 | + (int, int) LocalFunction2() { return (1, 2); } |
| 112 | + (int, int) LocalFunction3() { return ( 1, 2); } |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | +"; |
| 117 | + |
| 118 | + DiagnosticResult[] expectedDiagnostics = |
| 119 | + { |
| 120 | + // Returns |
| 121 | + this.CSharpDiagnostic().WithArguments("return", string.Empty, "followed").WithLocation(10, 43), |
| 122 | + this.CSharpDiagnostic().WithArguments("return", string.Empty, "followed").WithLocation(11, 43), |
| 123 | + }; |
| 124 | + |
| 125 | + await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false); |
| 126 | + await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 127 | + await this.VerifyCSharpFixAsync(testCode, fixedCode).ConfigureAwait(false); |
| 128 | + } |
74 | 129 | } |
75 | 130 | } |
0 commit comments