diff --git a/test/cases/const_slice_child.zig b/test/cases/const_slice_child.zig deleted file mode 100644 index bd22ca6da8e2a43d2b5a81a4cdbbc5ba3ea49147..0000000000000000000000000000000000000000 --- a/test/cases/const_slice_child.zig +++ /dev/null @@ -1,53 +0,0 @@ -const assert = @import("std").debug.assert; - -var argv: &&const u8 = undefined; - -fn constSliceChild() { - @setFnTest(this, true); - - const strs = ([]&const u8) { - c"one", - c"two", - c"three", - }; - argv = &strs[0]; - bar(strs.len); -} - -fn foo(args: [][]const u8) { - @setFnStaticEval(this, false); - - assert(args.len == 3); - assert(streql(args[0], "one")); - assert(streql(args[1], "two")); - assert(streql(args[2], "three")); -} - -fn bar(argc: usize) { - @setFnStaticEval(this, false); - - var args: [argc][]u8 = undefined; - for (args) |_, i| { - const ptr = argv[i]; - args[i] = ptr[0...strlen(ptr)]; - } - foo(args); -} - -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; -} diff --git a/test/cases/switch_prong_err_enum.zig b/test/cases/switch_prong_err_enum.zig deleted file mode 100644 index fb7b2e2832f2a609dd0aec98c727e0699725392a..0000000000000000000000000000000000000000 --- a/test/cases/switch_prong_err_enum.zig +++ /dev/null @@ -1,31 +0,0 @@ -const assert = @import("std").debug.assert; - -var read_count: u64 = 0; - -fn readOnce() -> %u64 { - read_count += 1; - return read_count; -} - -error InvalidDebugInfo; - -enum FormValue { - 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, - } -} - -fn switchProngReturnsErrorEnum() { - @setFnTest(this, true); - - %%doThing(17); - assert(read_count == 1); -} diff --git a/test/cases/switch_prong_implicit_cast.zig b/test/cases/switch_prong_implicit_cast.zig deleted file mode 100644 index cc447660dab6d61b74d83af9af68cf7b00f7d80d..0000000000000000000000000000000000000000 --- a/test/cases/switch_prong_implicit_cast.zig +++ /dev/null @@ -1,28 +0,0 @@ -const assert = @import("std").debug.assert; - -enum FormValue { - One, - Two: bool, -} - -error Whatever; - -fn foo(id: u64) -> %FormValue { - @setFnStaticEval(this, false); - - switch (id) { - 2 => FormValue.Two { true }, - 1 => FormValue.One, - else => return error.Whatever, - } -} - -fn switchProngImplicitCast() { - @setFnTest(this, true); - - const result = switch (%%foo(2)) { - One => false, - Two => |x| x, - }; - assert(result); -} diff --git a/test/cases3/const_slice_child.zig b/test/cases3/const_slice_child.zig new file mode 100644 index 0000000000000000000000000000000000000000..afbb635f78e06cdac237a12bcb7ff371386337f3 --- /dev/null +++ b/test/cases3/const_slice_child.zig @@ -0,0 +1,49 @@ +var argv: &&const u8 = undefined; + +fn constSliceChild() { + @setFnTest(this); + + const strs = ([]&const u8) { + c"one", + c"two", + c"three", + }; + argv = &strs[0]; + bar(strs.len); +} + +fn foo(args: [][]const u8) { + assert(args.len == 3); + assert(streql(args[0], "one")); + assert(streql(args[1], "two")); + assert(streql(args[2], "three")); +} + +fn bar(argc: usize) { + const args = @alloca([]u8, argc); + for (args) |_, i| { + const ptr = argv[i]; + args[i] = ptr[0...strlen(ptr)]; + } + foo(args); +} + +fn strlen(ptr: &const u8) -> usize { + var count: usize = 0; + while (ptr[count] != 0; count += 1) {} + return count; +} + +fn streql(a: []const u8, b: []const u8) -> bool { + 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(); +} diff --git a/test/cases3/switch_prong_err_enum.zig b/test/cases3/switch_prong_err_enum.zig new file mode 100644 index 0000000000000000000000000000000000000000..ac721a6707610d1f2a19211f106b641ff8a03c96 --- /dev/null +++ b/test/cases3/switch_prong_err_enum.zig @@ -0,0 +1,33 @@ +var read_count: u64 = 0; + +fn readOnce() -> %u64 { + read_count += 1; + return read_count; +} + +error InvalidDebugInfo; + +const FormValue = enum { + Address: u64, + Other: bool, +}; + +fn doThing(form_id: u64) -> %FormValue { + return switch (form_id) { + 17 => FormValue.Address { %return readOnce() }, + else => error.InvalidDebugInfo, + } +} + +fn switchProngReturnsErrorEnum() { + @setFnTest(this); + + %%doThing(17); + assert(read_count == 1); +} + +// TODO const assert = @import("std").debug.assert; +fn assert(ok: bool) { + if (!ok) + @unreachable(); +} diff --git a/test/cases3/switch_prong_implicit_cast.zig b/test/cases3/switch_prong_implicit_cast.zig new file mode 100644 index 0000000000000000000000000000000000000000..b4e243d88df3723818d6703d1966a1c66926dfdc --- /dev/null +++ b/test/cases3/switch_prong_implicit_cast.zig @@ -0,0 +1,30 @@ +const FormValue = enum { + One, + Two: bool, +}; + +error Whatever; + +fn foo(id: u64) -> %FormValue { + switch (id) { + 2 => FormValue.Two { true }, + 1 => FormValue.One, + else => return error.Whatever, + } +} + +fn switchProngImplicitCast() { + @setFnTest(this); + + const result = switch (%%foo(2)) { + FormValue.One => false, + FormValue.Two => |x| x, + }; + assert(result); +} + +// TODO const assert = @import("std").debug.assert; +fn assert(ok: bool) { + if (!ok) + @unreachable(); +} diff --git a/test/self_hosted.zig b/test/self_hosted.zig index 77a5ed2d92f04956dbc4ad041e041001c19ab949..8ec3dab83336847e9e7e3564bd936fdf74ce1640 100644 --- a/test/self_hosted.zig +++ b/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"); diff --git a/test/self_hosted3.zig b/test/self_hosted3.zig index a7a5325e7685c0a2d437ce0d65e72b96894fd237..9a7331f2f82136e6aeb817401b378cf1b37e385f 100644 --- a/test/self_hosted3.zig +++ b/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");