From 23bebdbcd51ac426f829713ce278b86ccaeb97f4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 22 Dec 2016 00:20:14 -0500 Subject: [PATCH] IR: port some tests --- test/cases3/fn.zig | 28 ++++++++++++++++++++ test/cases3/if.zig | 26 +++++++++++++++++++ test/cases3/misc.zig | 8 ++++++ test/self_hosted.zig | 60 +++---------------------------------------- test/self_hosted3.zig | 2 ++ 5 files changed, 67 insertions(+), 57 deletions(-) create mode 100644 test/cases3/fn.zig create mode 100644 test/cases3/if.zig diff --git a/test/cases3/fn.zig b/test/cases3/fn.zig new file mode 100644 index 0000000000..f0a8d3dcc5 --- /dev/null +++ b/test/cases3/fn.zig @@ -0,0 +1,28 @@ +fn params() { + @setFnTest(this); + + assert(testParamsAdd(22, 11) == 33); +} +fn testParamsAdd(a: i32, b: i32) -> i32 { + a + b +} + + +fn localVariables() { + @setFnTest(this); + + testLocVars(2); +} +fn testLocVars(b: i32) { + const a: i32 = 1; + if (a + b != 3) @unreachable(); +} + + + + +// TODO const assert = @import("std").debug.assert; +fn assert(ok: bool) { + if (!ok) + @unreachable(); +} diff --git a/test/cases3/if.zig b/test/cases3/if.zig new file mode 100644 index 0000000000..cfc2062d8d --- /dev/null +++ b/test/cases3/if.zig @@ -0,0 +1,26 @@ +fn ifStatements() { + @setFnTest(this); + + shouldBeEqual(1, 1); + firstEqlThird(2, 1, 2); +} +fn shouldBeEqual(a: i32, b: i32) { + if (a != b) { + @unreachable(); + } else { + return; + } +} +fn firstEqlThird(a: i32, b: i32, c: i32) { + if (a == b) { + @unreachable(); + } else if (b == c) { + @unreachable(); + } else if (a == c) { + return; + } else { + @unreachable(); + } +} + + diff --git a/test/cases3/misc.zig b/test/cases3/misc.zig index 35dac78019..d17cfb647a 100644 --- a/test/cases3/misc.zig +++ b/test/cases3/misc.zig @@ -130,6 +130,14 @@ fn ReturnStringFromFunction() { assert(memeql(first4KeysOfHomeRow(), "aoeu")); } +fn boolLiterals() { + @setFnTest(this); + + assert(true); + assert(!false); +} + + // TODO import from std.str pub fn memeql(a: []const u8, b: []const u8) -> bool { sliceEql(u8, a, b) diff --git a/test/self_hosted.zig b/test/self_hosted.zig index c987d53a11..3b71d9fc0a 100644 --- a/test/self_hosted.zig +++ b/test/self_hosted.zig @@ -17,68 +17,14 @@ const test_this = @import("cases/this.zig"); - -fn ifStatements() { - @setFnTest(this, true); - - shouldBeEqual(1, 1); - firstEqlThird(2, 1, 2); -} -fn shouldBeEqual(a: i32, b: i32) { - if (a != b) { - @unreachable(); - } else { - return; - } -} -fn firstEqlThird(a: i32, b: i32, c: i32) { - if (a == b) { - @unreachable(); - } else if (b == c) { - @unreachable(); - } else if (a == c) { - return; - } else { - @unreachable(); - } -} - - -fn params() { - @setFnTest(this, true); - - assert(testParamsAdd(22, 11) == 33); -} -fn testParamsAdd(a: i32, b: i32) -> i32 { - a + b -} - - -fn localVariables() { - @setFnTest(this, true); - - testLocVars(2); -} -fn testLocVars(b: i32) { - const a: i32 = 1; - if (a + b != 3) @unreachable(); -} - -fn boolLiterals() { - @setFnTest(this, true); - - assert(true); - assert(!false); -} - fn voidParameters() { - @setFnTest(this, true); + @setFnTest(this); voidFun(1, void{}, 2, {}); } -fn voidFun(a : i32, b : void, c : i32, d : void) { +fn voidFun(a: i32, b: void, c: i32, d: void) { const v = b; - const vv : void = if (a == 1) {v} else {}; + const vv: void = if (a == 1) {v} else {}; assert(a + c == 3); return vv; } diff --git a/test/self_hosted3.zig b/test/self_hosted3.zig index ec7dfb0c73..c2bf9ca8b6 100644 --- a/test/self_hosted3.zig +++ b/test/self_hosted3.zig @@ -4,9 +4,11 @@ const test_defer = @import("cases3/defer.zig"); const test_enum = @import("cases3/enum.zig"); const test_error = @import("cases3/error.zig"); const test_eval = @import("cases3/eval.zig"); +const test_fn = @import("cases3/fn.zig"); const test_for = @import("cases3/for.zig"); const test_generics = @import("cases3/generics.zig"); const test_goto = @import("cases3/goto.zig"); +const test_if = @import("cases3/if.zig"); const test_import = @import("cases3/import.zig"); const test_math = @import("cases3/math.zig"); const test_misc = @import("cases3/misc.zig");