authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-25 18:31:57-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-25 18:36:45-05:00
log2b5c7b1b8ed4d836d34b87c5fc847acd30566300
tree8cacc962f858ee91a078e4a97f7742bc72eef0d6
parentf47dea2a2ee5e2351736fa416d82c1ed38bfe0f1

IR: port more tests


8 files changed, 115 insertions(+), 115 deletions(-)

test/cases/const_slice_child.zig deleted-53
......@@ -1,53 +0,0 @@
1const assert = @import("std").debug.assert;
2
3var argv: &&const u8 = undefined;
4
5fn constSliceChild() {
6 @setFnTest(this, true);
7
8 const strs = ([]&const u8) {
9 c"one",
10 c"two",
11 c"three",
12 };
13 argv = &strs[0];
14 bar(strs.len);
15}
16
17fn foo(args: [][]const u8) {
18 @setFnStaticEval(this, false);
19
20 assert(args.len == 3);
21 assert(streql(args[0], "one"));
22 assert(streql(args[1], "two"));
23 assert(streql(args[2], "three"));
24}
25
26fn bar(argc: usize) {
27 @setFnStaticEval(this, false);
28
29 var args: [argc][]u8 = undefined;
30 for (args) |_, i| {
31 const ptr = argv[i];
32 args[i] = ptr[0...strlen(ptr)];
33 }
34 foo(args);
35}
36
37fn strlen(ptr: &const u8) -> usize {
38 @setFnStaticEval(this, false);
39
40 var count: usize = 0;
41 while (ptr[count] != 0; count += 1) {}
42 return count;
43}
44
45fn streql(a: []const u8, b: []const u8) -> bool {
46 @setFnStaticEval(this, false);
47
48 if (a.len != b.len) return false;
49 for (a) |item, index| {
50 if (b[index] != item) return false;
51 }
52 return true;
53}
test/cases/switch_prong_err_enum.zig deleted-31
......@@ -1,31 +0,0 @@
1const assert = @import("std").debug.assert;
2
3var read_count: u64 = 0;
4
5fn readOnce() -> %u64 {
6 read_count += 1;
7 return read_count;
8}
9
10error InvalidDebugInfo;
11
12enum FormValue {
13 Address: u64,
14 Other: bool,
15}
16
17fn doThing(form_id: u64) -> %FormValue {
18 @setFnStaticEval(this, false);
19
20 return switch (form_id) {
21 17 => FormValue.Address { %return readOnce() },
22 else => error.InvalidDebugInfo,
23 }
24}
25
26fn switchProngReturnsErrorEnum() {
27 @setFnTest(this, true);
28
29 %%doThing(17);
30 assert(read_count == 1);
31}
test/cases/switch_prong_implicit_cast.zig deleted-28
......@@ -1,28 +0,0 @@
1const assert = @import("std").debug.assert;
2
3enum FormValue {
4 One,
5 Two: bool,
6}
7
8error Whatever;
9
10fn foo(id: u64) -> %FormValue {
11 @setFnStaticEval(this, false);
12
13 switch (id) {
14 2 => FormValue.Two { true },
15 1 => FormValue.One,
16 else => return error.Whatever,
17 }
18}
19
20fn switchProngImplicitCast() {
21 @setFnTest(this, true);
22
23 const result = switch (%%foo(2)) {
24 One => false,
25 Two => |x| x,
26 };
27 assert(result);
28}
test/cases3/const_slice_child.zig created+49
......@@ -0,0 +1,49 @@
1var argv: &&const u8 = undefined;
2
3fn constSliceChild() {
4 @setFnTest(this);
5
6 const strs = ([]&const u8) {
7 c"one",
8 c"two",
9 c"three",
10 };
11 argv = &strs[0];
12 bar(strs.len);
13}
14
15fn foo(args: [][]const u8) {
16 assert(args.len == 3);
17 assert(streql(args[0], "one"));
18 assert(streql(args[1], "two"));
19 assert(streql(args[2], "three"));
20}
21
22fn bar(argc: usize) {
23 const args = @alloca([]u8, argc);
24 for (args) |_, i| {
25 const ptr = argv[i];
26 args[i] = ptr[0...strlen(ptr)];
27 }
28 foo(args);
29}
30
31fn strlen(ptr: &const u8) -> usize {
32 var count: usize = 0;
33 while (ptr[count] != 0; count += 1) {}
34 return count;
35}
36
37fn streql(a: []const u8, b: []const u8) -> bool {
38 if (a.len != b.len) return false;
39 for (a) |item, index| {
40 if (b[index] != item) return false;
41 }
42 return true;
43}
44
45// TODO const assert = @import("std").debug.assert;
46fn assert(ok: bool) {
47 if (!ok)
48 @unreachable();
49}
test/cases3/switch_prong_err_enum.zig created+33
......@@ -0,0 +1,33 @@
1var read_count: u64 = 0;
2
3fn readOnce() -> %u64 {
4 read_count += 1;
5 return read_count;
6}
7
8error InvalidDebugInfo;
9
10const FormValue = enum {
11 Address: u64,
12 Other: bool,
13};
14
15fn doThing(form_id: u64) -> %FormValue {
16 return switch (form_id) {
17 17 => FormValue.Address { %return readOnce() },
18 else => error.InvalidDebugInfo,
19 }
20}
21
22fn switchProngReturnsErrorEnum() {
23 @setFnTest(this);
24
25 %%doThing(17);
26 assert(read_count == 1);
27}
28
29// TODO const assert = @import("std").debug.assert;
30fn assert(ok: bool) {
31 if (!ok)
32 @unreachable();
33}
test/cases3/switch_prong_implicit_cast.zig created+30
......@@ -0,0 +1,30 @@
1const FormValue = enum {
2 One,
3 Two: bool,
4};
5
6error Whatever;
7
8fn foo(id: u64) -> %FormValue {
9 switch (id) {
10 2 => FormValue.Two { true },
11 1 => FormValue.One,
12 else => return error.Whatever,
13 }
14}
15
16fn switchProngImplicitCast() {
17 @setFnTest(this);
18
19 const result = switch (%%foo(2)) {
20 FormValue.One => false,
21 FormValue.Two => |x| x,
22 };
23 assert(result);
24}
25
26// TODO const assert = @import("std").debug.assert;
27fn assert(ok: bool) {
28 if (!ok)
29 @unreachable();
30}
test/self_hosted.zig-3
......@@ -2,9 +2,6 @@ const std = @import("std");
22const assert = std.debug.assert;
33const str = std.str;
44const cstr = std.cstr;
5const test_const_slice_child = @import("cases/const_slice_child.zig");
6const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig");
7const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig");
85const test_enum_with_members = @import("cases/enum_with_members.zig");
96
107
test/self_hosted3.zig+3
......@@ -3,6 +3,7 @@ const test_array = @import("cases3/array.zig");
33const test_atomics = @import("cases3/atomics.zig");
44const test_bool = @import("cases3/bool.zig");
55const test_cast= @import("cases3/cast.zig");
6const test_const_slice_child = @import("cases3/const_slice_child.zig");
67const test_defer = @import("cases3/defer.zig");
78const test_enum = @import("cases3/enum.zig");
89const test_error = @import("cases3/error.zig");
......@@ -20,5 +21,7 @@ const test_sizeof_and_typeof = @import("cases3/sizeof_and_typeof.zig");
2021const test_struct = @import("cases3/struct.zig");
2122const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig");
2223const test_switch = @import("cases3/switch.zig");
24const test_switch_prong_err_enum = @import("cases3/switch_prong_err_enum.zig");
25const test_switch_prong_implicit_cast = @import("cases3/switch_prong_implicit_cast.zig");
2326const test_this = @import("cases3/this.zig");
2427const test_while = @import("cases3/while.zig");