commit 9a0a378e2f957f6acf5fbb37818d1cc0e3a38d33 (tree) parent a4ac7980b4a37c3d9d36b63685c8a5867d4849f5 Author: Benjamin Feng <benjamin.feng@glassdoor.com> Date: Wed, 29 Jan 2020 00:34:46 -0600 Add test cases for suspend in while loops Diffstat:
| M | test/stage1/behavior/async_fn.zig | | | 36 | ++++++++++++++++++++++++++++++++++++ |
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig @@ -1182,6 +1182,42 @@ test "suspend in for loop" { S.doTheTest(); } +test "suspend in while loop" { + const S = struct { + var global_frame: ?anyframe = null; + + fn doTheTest() void { + _ = async atest(); + while (global_frame) |f| resume f; + } + + fn atest() void { + expect(optional(6) == 6); + expect(errunion(6) == 6); + } + fn optional(stuff: ?u32) u32 { + global_frame = @frame(); + defer global_frame = null; + while (stuff) |val| { + suspend; + return val; + } + return 0; + } + fn errunion(stuff: anyerror!u32) u32 { + global_frame = @frame(); + defer global_frame = null; + while (stuff) |val| { + suspend; + return val; + } else |err| { + return 0; + } + } + }; + S.doTheTest(); +} + test "correctly spill when returning the error union result of another async fn" { const S = struct { var global_frame: anyframe = undefined;