From 0ac56e7f3aba39f96ec9ca3fa3b253c9654979cf Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Thu, 20 May 2021 19:59:37 +0200 Subject: [PATCH] Add test cases for switches --- test/stage2/wasm.zig | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/test/stage2/wasm.zig b/test/stage2/wasm.zig index 2b99ec5cb7..e62fcd3bac 100644 --- a/test/stage2/wasm.zig +++ b/test/stage2/wasm.zig @@ -474,4 +474,65 @@ pub fn addCases(ctx: *TestContext) !void { \\} , "30\n"); } + + { + var case = ctx.exe("wasm switch", wasi); + + case.addCompareOutput( + \\pub export fn _start() u32 { + \\ var val: u32 = 1; + \\ var a: u32 = switch (val) { + \\ 0, 1 => 2, + \\ 2 => 3, + \\ 3 => 4, + \\ else => 5, + \\ }; + \\ + \\ return a; + \\} + , "2\n"); + + case.addCompareOutput( + \\pub export fn _start() u32 { + \\ var val: u32 = 2; + \\ var a: u32 = switch (val) { + \\ 0, 1 => 2, + \\ 2 => 3, + \\ 3 => 4, + \\ else => 5, + \\ }; + \\ + \\ return a; + \\} + , "3\n"); + + case.addCompareOutput( + \\pub export fn _start() u32 { + \\ var val: u32 = 10; + \\ var a: u32 = switch (val) { + \\ 0, 1 => 2, + \\ 2 => 3, + \\ 3 => 4, + \\ else => 5, + \\ }; + \\ + \\ return a; + \\} + , "5\n"); + + case.addCompareOutput( + \\const MyEnum = enum { One, Two, Three }; + \\ + \\pub export fn _start() u32 { + \\ var val: MyEnum = .Two; + \\ var a: u32 = switch (val) { + \\ .One => 1, + \\ .Two => 2, + \\ .Three => 3, + \\ }; + \\ + \\ return a; + \\} + , "2\n"); + } }