Commit 23bebdbcd5
Changed files (5)
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();
+}
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();
+ }
+}
+
+
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)
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;
}
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");