| ... | @@ -974,6 +974,43 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -974,6 +974,43 @@ pub fn addCases(ctx: *TestContext) !void { |
| 974 | , | 974 | , |
| 975 | "hello\nhello\nhello\nhello\nhello\n", | 975 | "hello\nhello\nhello\nhello\nhello\n", |
| 976 | ); | 976 | ); |
| | 977 | |
| | 978 | // comptime switch |
| | 979 | |
| | 980 | // Basic for loop |
| | 981 | case.addCompareOutput( |
| | 982 | \\pub export fn _start() noreturn { |
| | 983 | \\ assert(foo() == 1); |
| | 984 | \\ exit(); |
| | 985 | \\} |
| | 986 | \\ |
| | 987 | \\fn foo() u32 { |
| | 988 | \\ const a: comptime_int = 1; |
| | 989 | \\ var b: u32 = 0; |
| | 990 | \\ switch (a) { |
| | 991 | \\ 1 => b = 1, |
| | 992 | \\ 2 => b = 2, |
| | 993 | \\ else => unreachable, |
| | 994 | \\ } |
| | 995 | \\ return b; |
| | 996 | \\} |
| | 997 | \\ |
| | 998 | \\pub fn assert(ok: bool) void { |
| | 999 | \\ if (!ok) unreachable; // assertion failure |
| | 1000 | \\} |
| | 1001 | \\ |
| | 1002 | \\fn exit() noreturn { |
| | 1003 | \\ asm volatile ("syscall" |
| | 1004 | \\ : |
| | 1005 | \\ : [number] "{rax}" (231), |
| | 1006 | \\ [arg1] "{rdi}" (0) |
| | 1007 | \\ : "rcx", "r11", "memory" |
| | 1008 | \\ ); |
| | 1009 | \\ unreachable; |
| | 1010 | \\} |
| | 1011 | , |
| | 1012 | "", |
| | 1013 | ); |
| 977 | } | 1014 | } |
| 978 | | 1015 | |
| 979 | { | 1016 | { |