forked from zompinc/sync-method-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deconstruct and fully qualified types in async foreach
- Loading branch information
1 parent
28761db
commit 1b0b438
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
namespace Generator.Tests; | ||
|
||
public class ForEachTests | ||
{ | ||
[Fact] | ||
public Task AsyncForEachQualified() => """ | ||
[CreateSyncVersion] | ||
async Task<int> SumAsync(IAsyncEnumerable<int?> enumerable) | ||
{ | ||
int sum = 0; | ||
await foreach (int? i in enumerable) | ||
{ | ||
if (i.HasValue) | ||
{ | ||
sum += i.Value; | ||
} | ||
} | ||
return sum; | ||
} | ||
""".Verify(); | ||
|
||
[Fact] | ||
public Task AsyncForEachDeconstruct() => """ | ||
[CreateSyncVersion] | ||
async Task<int> SumAsync(IAsyncEnumerable<(int a, int b)> enumerable) | ||
{ | ||
int sum = 0; | ||
await foreach (var (a, b) in enumerable) | ||
{ | ||
sum += a + b; | ||
} | ||
return sum; | ||
} | ||
""".Verify(); | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Generator.Tests/Snapshots/ForEachTests.AsyncForEachDeconstruct#SumAsync.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//HintName: Test.Class.SumAsync.g.cs | ||
int Sum(global::System.Collections.Generic.IEnumerable<(int a, int b)> enumerable) | ||
{ | ||
int sum = 0; | ||
|
||
foreach (var (a, b) in enumerable) | ||
{ | ||
sum += a + b; | ||
} | ||
|
||
return sum; | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/Generator.Tests/Snapshots/ForEachTests.AsyncForEachQualified#SumAsync.g.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//HintName: Test.Class.SumAsync.g.cs | ||
int Sum(global::System.Collections.Generic.IEnumerable<int?> enumerable) | ||
{ | ||
int sum = 0; | ||
|
||
foreach (int? i in enumerable) | ||
{ | ||
if (i.HasValue) | ||
{ | ||
sum += i.Value; | ||
} | ||
} | ||
|
||
return sum; | ||
} |