authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-22 00:20:14-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-22 00:20:14-05:00
log23bebdbcd51ac426f829713ce278b86ccaeb97f4
tree4fe1b3b1dde7723a012fe485f069202bed9772b9
parent56cc2e2b24f50975591de02e8a556eee4ac45bf7

IR: port some tests


5 files changed, 67 insertions(+), 57 deletions(-)

test/cases3/fn.zig created+28
...@@ -0,0 +1,28 @@
1fn params() {
2 @setFnTest(this);
3
4 assert(testParamsAdd(22, 11) == 33);
5}
6fn testParamsAdd(a: i32, b: i32) -> i32 {
7 a + b
8}
9
10
11fn localVariables() {
12 @setFnTest(this);
13
14 testLocVars(2);
15}
16fn testLocVars(b: i32) {
17 const a: i32 = 1;
18 if (a + b != 3) @unreachable();
19}
20
21
22
23
24// TODO const assert = @import("std").debug.assert;
25fn assert(ok: bool) {
26 if (!ok)
27 @unreachable();
28}
test/cases3/if.zig created+26
...@@ -0,0 +1,26 @@
1fn ifStatements() {
2 @setFnTest(this);
3
4 shouldBeEqual(1, 1);
5 firstEqlThird(2, 1, 2);
6}
7fn shouldBeEqual(a: i32, b: i32) {
8 if (a != b) {
9 @unreachable();
10 } else {
11 return;
12 }
13}
14fn firstEqlThird(a: i32, b: i32, c: i32) {
15 if (a == b) {
16 @unreachable();
17 } else if (b == c) {
18 @unreachable();
19 } else if (a == c) {
20 return;
21 } else {
22 @unreachable();
23 }
24}
25
26
test/cases3/misc.zig+8
...@@ -130,6 +130,14 @@ fn ReturnStringFromFunction() {...@@ -130,6 +130,14 @@ fn ReturnStringFromFunction() {
130 assert(memeql(first4KeysOfHomeRow(), "aoeu"));130 assert(memeql(first4KeysOfHomeRow(), "aoeu"));
131}131}
132132
133fn boolLiterals() {
134 @setFnTest(this);
135
136 assert(true);
137 assert(!false);
138}
139
140
133// TODO import from std.str141// TODO import from std.str
134pub fn memeql(a: []const u8, b: []const u8) -> bool {142pub fn memeql(a: []const u8, b: []const u8) -> bool {
135 sliceEql(u8, a, b)143 sliceEql(u8, a, b)
test/self_hosted.zig+3-57
...@@ -17,68 +17,14 @@ const test_this = @import("cases/this.zig");...@@ -17,68 +17,14 @@ const test_this = @import("cases/this.zig");
1717
1818
1919
20
21fn ifStatements() {
22 @setFnTest(this, true);
23
24 shouldBeEqual(1, 1);
25 firstEqlThird(2, 1, 2);
26}
27fn shouldBeEqual(a: i32, b: i32) {
28 if (a != b) {
29 @unreachable();
30 } else {
31 return;
32 }
33}
34fn firstEqlThird(a: i32, b: i32, c: i32) {
35 if (a == b) {
36 @unreachable();
37 } else if (b == c) {
38 @unreachable();
39 } else if (a == c) {
40 return;
41 } else {
42 @unreachable();
43 }
44}
45
46
47fn params() {
48 @setFnTest(this, true);
49
50 assert(testParamsAdd(22, 11) == 33);
51}
52fn testParamsAdd(a: i32, b: i32) -> i32 {
53 a + b
54}
55
56
57fn localVariables() {
58 @setFnTest(this, true);
59
60 testLocVars(2);
61}
62fn testLocVars(b: i32) {
63 const a: i32 = 1;
64 if (a + b != 3) @unreachable();
65}
66
67fn boolLiterals() {
68 @setFnTest(this, true);
69
70 assert(true);
71 assert(!false);
72}
73
74fn voidParameters() {20fn voidParameters() {
75 @setFnTest(this, true);21 @setFnTest(this);
7622
77 voidFun(1, void{}, 2, {});23 voidFun(1, void{}, 2, {});
78}24}
79fn voidFun(a : i32, b : void, c : i32, d : void) {25fn voidFun(a: i32, b: void, c: i32, d: void) {
80 const v = b;26 const v = b;
81 const vv : void = if (a == 1) {v} else {};27 const vv: void = if (a == 1) {v} else {};
82 assert(a + c == 3);28 assert(a + c == 3);
83 return vv;29 return vv;
84}30}
test/self_hosted3.zig+2
...@@ -4,9 +4,11 @@ const test_defer = @import("cases3/defer.zig");...@@ -4,9 +4,11 @@ const test_defer = @import("cases3/defer.zig");
4const test_enum = @import("cases3/enum.zig");4const test_enum = @import("cases3/enum.zig");
5const test_error = @import("cases3/error.zig");5const test_error = @import("cases3/error.zig");
6const test_eval = @import("cases3/eval.zig");6const test_eval = @import("cases3/eval.zig");
7const test_fn = @import("cases3/fn.zig");
7const test_for = @import("cases3/for.zig");8const test_for = @import("cases3/for.zig");
8const test_generics = @import("cases3/generics.zig");9const test_generics = @import("cases3/generics.zig");
9const test_goto = @import("cases3/goto.zig");10const test_goto = @import("cases3/goto.zig");
11const test_if = @import("cases3/if.zig");
10const test_import = @import("cases3/import.zig");12const test_import = @import("cases3/import.zig");
11const test_math = @import("cases3/math.zig");13const test_math = @import("cases3/math.zig");
12const test_misc = @import("cases3/misc.zig");14const test_misc = @import("cases3/misc.zig");