Add test cases for switches

This commit is contained in:
Luuk de Gram 2021-05-20 19:59:37 +02:00
parent f8d0501f50
commit 0ac56e7f3a
No known key found for this signature in database
GPG Key ID: A002B174963DBB7D

View File

@ -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");
}
}