Skip to content

Commit a4273dd

Browse files
committed
Update SA1000 for asynchronous streams
1 parent b72b3f7 commit a4273dd

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/SpacingRules/SA1000CSharp8UnitTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,42 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp8.SpacingRules
55
{
6+
using System.Threading.Tasks;
7+
using Microsoft.CodeAnalysis.Testing;
68
using StyleCop.Analyzers.Test.CSharp7.SpacingRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
11+
StyleCop.Analyzers.SpacingRules.SA1000KeywordsMustBeSpacedCorrectly,
12+
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;
713

814
public partial class SA1000CSharp8UnitTests : SA1000CSharp7UnitTests
915
{
16+
[Fact]
17+
[WorkItem(3007, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3007")]
18+
public async Task TestAwaitForEachMissingSpaceAsync()
19+
{
20+
string statementWithoutSpace = @"await {|#0:foreach|}(var value in GetValues())
21+
{
22+
_ = value;
23+
}
24+
25+
async IAsyncEnumerable<int> GetValues()
26+
{
27+
yield return 1;
28+
}";
29+
string statementWithSpace = @"await foreach (var value in GetValues())
30+
{
31+
_ = value;
32+
}
33+
34+
async IAsyncEnumerable<int> GetValues()
35+
{
36+
yield return 1;
37+
}";
38+
39+
DiagnosticResult expected = Diagnostic().WithArguments("foreach", string.Empty, "followed").WithLocation(0);
40+
41+
await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace, returnType: "Task", asyncMethod: true).ConfigureAwait(false);
42+
}
1043
}
1144
}

0 commit comments

Comments
 (0)