Commit 2b5c7b1b8e

Andrew Kelley <superjoe30@gmail.com>
2016-12-26 00:31:57
IR: port more tests
1 parent f47dea2
test/cases/const_slice_child.zig โ†’ test/cases3/const_slice_child.zig
@@ -1,9 +1,7 @@
-const assert = @import("std").debug.assert;
-
 var argv: &&const u8 = undefined;
 
 fn constSliceChild() {
-    @setFnTest(this, true);
+    @setFnTest(this);
 
     const strs = ([]&const u8) {
         c"one",
@@ -15,8 +13,6 @@ fn constSliceChild() {
 }
 
 fn foo(args: [][]const u8) {
-    @setFnStaticEval(this, false);
-
     assert(args.len == 3);
     assert(streql(args[0], "one"));
     assert(streql(args[1], "two"));
@@ -24,9 +20,7 @@ fn foo(args: [][]const u8) {
 }
 
 fn bar(argc: usize) {
-    @setFnStaticEval(this, false);
-
-    var args: [argc][]u8 = undefined;
+    const args = @alloca([]u8, argc);
     for (args) |_, i| {
         const ptr = argv[i];
         args[i] = ptr[0...strlen(ptr)];
@@ -35,19 +29,21 @@ fn bar(argc: usize) {
 }
 
 fn strlen(ptr: &const u8) -> usize {
-    @setFnStaticEval(this, false);
-
     var count: usize = 0;
     while (ptr[count] != 0; count += 1) {}
     return count;
 }
 
 fn streql(a: []const u8, b: []const u8) -> bool {
-    @setFnStaticEval(this, false);
-
     if (a.len != b.len) return false;
     for (a) |item, index| {
         if (b[index] != item) return false;
     }
     return true;
 }
+
+// TODO const assert = @import("std").debug.assert;
+fn assert(ok: bool) {
+    if (!ok)
+        @unreachable();
+}
test/cases/switch_prong_err_enum.zig โ†’ test/cases3/switch_prong_err_enum.zig
@@ -1,5 +1,3 @@
-const assert = @import("std").debug.assert;
-
 var read_count: u64 = 0;
 
 fn readOnce() -> %u64 {
@@ -9,14 +7,12 @@ fn readOnce() -> %u64 {
 
 error InvalidDebugInfo;
 
-enum FormValue {
+const FormValue = enum {
     Address: u64,
     Other: bool,
-}
+};
 
 fn doThing(form_id: u64) -> %FormValue {
-    @setFnStaticEval(this, false);
-
     return switch (form_id) {
         17 => FormValue.Address { %return readOnce() },
         else => error.InvalidDebugInfo,
@@ -24,8 +20,14 @@ fn doThing(form_id: u64) -> %FormValue {
 }
 
 fn switchProngReturnsErrorEnum() {
-    @setFnTest(this, true);
+    @setFnTest(this);
 
     %%doThing(17);
     assert(read_count == 1);
 }
+
+// TODO const assert = @import("std").debug.assert;
+fn assert(ok: bool) {
+    if (!ok)
+        @unreachable();
+}
test/cases/switch_prong_implicit_cast.zig โ†’ test/cases3/switch_prong_implicit_cast.zig
@@ -1,15 +1,11 @@
-const assert = @import("std").debug.assert;
-
-enum FormValue {
+const FormValue = enum {
     One,
     Two: bool,
-}
+};
 
 error Whatever;
 
 fn foo(id: u64) -> %FormValue {
-    @setFnStaticEval(this, false);
-
     switch (id) {
         2 => FormValue.Two { true },
         1 => FormValue.One,
@@ -18,11 +14,17 @@ fn foo(id: u64) -> %FormValue {
 }
 
 fn switchProngImplicitCast() {
-    @setFnTest(this, true);
+    @setFnTest(this);
 
     const result = switch (%%foo(2)) {
-        One => false,
-        Two => |x| x,
+        FormValue.One => false,
+        FormValue.Two => |x| x,
     };
     assert(result);
 }
+
+// TODO const assert = @import("std").debug.assert;
+fn assert(ok: bool) {
+    if (!ok)
+        @unreachable();
+}
test/self_hosted.zig
@@ -2,9 +2,6 @@ const std = @import("std");
 const assert = std.debug.assert;
 const str = std.str;
 const cstr = std.cstr;
-const test_const_slice_child = @import("cases/const_slice_child.zig");
-const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig");
-const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig");
 const test_enum_with_members = @import("cases/enum_with_members.zig");
 
 
test/self_hosted3.zig
@@ -3,6 +3,7 @@ const test_array = @import("cases3/array.zig");
 const test_atomics = @import("cases3/atomics.zig");
 const test_bool = @import("cases3/bool.zig");
 const test_cast= @import("cases3/cast.zig");
+const test_const_slice_child = @import("cases3/const_slice_child.zig");
 const test_defer = @import("cases3/defer.zig");
 const test_enum = @import("cases3/enum.zig");
 const test_error = @import("cases3/error.zig");
@@ -20,5 +21,7 @@ const test_sizeof_and_typeof = @import("cases3/sizeof_and_typeof.zig");
 const test_struct = @import("cases3/struct.zig");
 const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig");
 const test_switch = @import("cases3/switch.zig");
+const test_switch_prong_err_enum = @import("cases3/switch_prong_err_enum.zig");
+const test_switch_prong_implicit_cast = @import("cases3/switch_prong_implicit_cast.zig");
 const test_this = @import("cases3/this.zig");
 const test_while = @import("cases3/while.zig");