aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2020-10-31 09:39:28 +0200
committerGitHub <noreply@github.com>2020-10-31 09:39:28 +0200
commit7c8d9cfa40ab96aede2a7fe8ec9dce6f10bc910a (patch)
treebac19bf24748e7d63e3bbf86ca5b34c4cfa2c754 /test
parentbb6e39e274eb0a68bfb1029ab75d1791abeb2911 (diff)
parent22ec5e085914d9fd7b17a28a8d3ad01258f3ad03 (diff)
downloadzig-7c8d9cfa40ab96aede2a7fe8ec9dce6f10bc910a.tar.gz
zig-7c8d9cfa40ab96aede2a7fe8ec9dce6f10bc910a.zip
Merge pull request #6660 from Vexu/stage2
Stage2 switch and package imports
Diffstat (limited to 'test')
-rw-r--r--test/stage2/test.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/stage2/test.zig b/test/stage2/test.zig
index 7e1de126b6..51bde87ab0 100644
--- a/test/stage2/test.zig
+++ b/test/stage2/test.zig
@@ -974,6 +974,43 @@ pub fn addCases(ctx: *TestContext) !void {
,
"hello\nhello\nhello\nhello\nhello\n",
);
+
+ // comptime switch
+
+ // Basic for loop
+ case.addCompareOutput(
+ \\pub export fn _start() noreturn {
+ \\ assert(foo() == 1);
+ \\ exit();
+ \\}
+ \\
+ \\fn foo() u32 {
+ \\ const a: comptime_int = 1;
+ \\ var b: u32 = 0;
+ \\ switch (a) {
+ \\ 1 => b = 1,
+ \\ 2 => b = 2,
+ \\ else => unreachable,
+ \\ }
+ \\ return b;
+ \\}
+ \\
+ \\pub fn assert(ok: bool) void {
+ \\ if (!ok) unreachable; // assertion failure
+ \\}
+ \\
+ \\fn exit() noreturn {
+ \\ asm volatile ("syscall"
+ \\ :
+ \\ : [number] "{rax}" (231),
+ \\ [arg1] "{rdi}" (0)
+ \\ : "rcx", "r11", "memory"
+ \\ );
+ \\ unreachable;
+ \\}
+ ,
+ "",
+ );
}
{