Skip to content

Commit 19a52ed

Browse files
committed
Add SA1000 tests for extension foreach
1 parent 87297d4 commit 19a52ed

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/SpacingRules/SA1000CSharp9UnitTests.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4-
#nullable disable
5-
64
namespace StyleCop.Analyzers.Test.CSharp9.SpacingRules
75
{
6+
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.CodeAnalysis.Testing;
109
using StyleCop.Analyzers.Test.CSharp8.SpacingRules;
@@ -67,5 +66,42 @@ public async Task TestOrBeforeRelationalPatternAsync()
6766
var expected = Diagnostic().WithArguments("or", string.Empty, "followed").WithLocation(0);
6867
await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false);
6968
}
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+
}
70106
}
71107
}

0 commit comments

Comments
 (0)