|
1 | 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. |
2 | 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. |
3 | 3 |
|
4 | | -#nullable disable |
5 | | - |
6 | 4 | namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules |
7 | 5 | { |
| 6 | + using System.Threading; |
8 | 7 | using System.Threading.Tasks; |
9 | 8 | using Microsoft.CodeAnalysis.Testing; |
10 | 9 | using StyleCop.Analyzers.Test.CSharp8.SpacingRules; |
@@ -67,5 +66,42 @@ public async Task TestOrBeforeRelationalPatternAsync() |
67 | 66 | var expected = Diagnostic().WithArguments("or", string.Empty, "followed").WithLocation(0); |
68 | 67 | await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false); |
69 | 68 | } |
| 69 | + |
| 70 | + [Fact] |
| 71 | + [WorkItem(3976, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3976")] |
| 72 | + public async Task TestForeachWithExtensionEnumeratorAsync() |
| 73 | + { |
| 74 | + var testCode = @" |
| 75 | +using System.Collections.Generic; |
| 76 | +
|
| 77 | +public class TestClass |
| 78 | +{ |
| 79 | + public void TestMethod() |
| 80 | + { |
| 81 | + foreach (var value in new ExtensionEnumerable()) |
| 82 | + { |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | +
|
| 87 | +public class ExtensionEnumerable |
| 88 | +{ |
| 89 | +} |
| 90 | +
|
| 91 | +public static class ExtensionEnumerableExtensions |
| 92 | +{ |
| 93 | + public static ExtensionEnumerator GetEnumerator(this ExtensionEnumerable value) => new(); |
| 94 | +} |
| 95 | +
|
| 96 | +public struct ExtensionEnumerator |
| 97 | +{ |
| 98 | + public int Current => 0; |
| 99 | +
|
| 100 | + public bool MoveNext() => false; |
| 101 | +} |
| 102 | +"; |
| 103 | + |
| 104 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 105 | + } |
70 | 106 | } |
71 | 107 | } |
0 commit comments