| author | |
| committer | |
| log | 2b5c7b1b8ed4d836d34b87c5fc847acd30566300 |
| tree | 8cacc962f858ee91a078e4a97f7742bc72eef0d6 |
| parent | f47dea2a2ee5e2351736fa416d82c1ed38bfe0f1 |
8 files changed, 115 insertions(+), 115 deletions(-)
test/cases/const_slice_child.zig deleted-53| ... | @@ -1,53 +0,0 @@ | ||
| 1 | const assert = @import("std").debug.assert; | ||
| 2 | |||
| 3 | var argv: &&const u8 = undefined; | ||
| 4 | |||
| 5 | fn constSliceChild() { | ||
| 6 | @setFnTest(this, true); | ||
| 7 | |||
| 8 | const strs = ([]&const u8) { | ||
| 9 | c"one", | ||
| 10 | c"two", | ||
| 11 | c"three", | ||
| 12 | }; | ||
| 13 | argv = &strs[0]; | ||
| 14 | bar(strs.len); | ||
| 15 | } | ||
| 16 | |||
| 17 | fn foo(args: [][]const u8) { | ||
| 18 | @setFnStaticEval(this, false); | ||
| 19 | |||
| 20 | assert(args.len == 3); | ||
| 21 | assert(streql(args[0], "one")); | ||
| 22 | assert(streql(args[1], "two")); | ||
| 23 | assert(streql(args[2], "three")); | ||
| 24 | } | ||
| 25 | |||
| 26 | fn bar(argc: usize) { | ||
| 27 | @setFnStaticEval(this, false); | ||
| 28 | |||
| 29 | var args: [argc][]u8 = undefined; | ||
| 30 | for (args) |_, i| { | ||
| 31 | const ptr = argv[i]; | ||
| 32 | args[i] = ptr[0...strlen(ptr)]; | ||
| 33 | } | ||
| 34 | foo(args); | ||
| 35 | } | ||
| 36 | |||
| 37 | fn strlen(ptr: &const u8) -> usize { | ||
| 38 | @setFnStaticEval(this, false); | ||
| 39 | |||
| 40 | var count: usize = 0; | ||
| 41 | while (ptr[count] != 0; count += 1) {} | ||
| 42 | return count; | ||
| 43 | } | ||
| 44 | |||
| 45 | fn streql(a: []const u8, b: []const u8) -> bool { | ||
| 46 | @setFnStaticEval(this, false); | ||
| 47 | |||
| 48 | if (a.len != b.len) return false; | ||
| 49 | for (a) |item, index| { | ||
| 50 | if (b[index] != item) return false; | ||
| 51 | } | ||
| 52 | return true; | ||
| 53 | } | ||
test/cases/switch_prong_err_enum.zig deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | const assert = @import("std").debug.assert; | ||
| 2 | |||
| 3 | var read_count: u64 = 0; | ||
| 4 | |||
| 5 | fn readOnce() -> %u64 { | ||
| 6 | read_count += 1; | ||
| 7 | return read_count; | ||
| 8 | } | ||
| 9 | |||
| 10 | error InvalidDebugInfo; | ||
| 11 | |||
| 12 | enum FormValue { | ||
| 13 | Address: u64, | ||
| 14 | Other: bool, | ||
| 15 | } | ||
| 16 | |||
| 17 | fn doThing(form_id: u64) -> %FormValue { | ||
| 18 | @setFnStaticEval(this, false); | ||
| 19 | |||
| 20 | return switch (form_id) { | ||
| 21 | 17 => FormValue.Address { %return readOnce() }, | ||
| 22 | else => error.InvalidDebugInfo, | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | fn switchProngReturnsErrorEnum() { | ||
| 27 | @setFnTest(this, true); | ||
| 28 | |||
| 29 | %%doThing(17); | ||
| 30 | assert(read_count == 1); | ||
| 31 | } | ||
test/cases/switch_prong_implicit_cast.zig deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | const assert = @import("std").debug.assert; | ||
| 2 | |||
| 3 | enum FormValue { | ||
| 4 | One, | ||
| 5 | Two: bool, | ||
| 6 | } | ||
| 7 | |||
| 8 | error Whatever; | ||
| 9 | |||
| 10 | fn foo(id: u64) -> %FormValue { | ||
| 11 | @setFnStaticEval(this, false); | ||
| 12 | |||
| 13 | switch (id) { | ||
| 14 | 2 => FormValue.Two { true }, | ||
| 15 | 1 => FormValue.One, | ||
| 16 | else => return error.Whatever, | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | fn switchProngImplicitCast() { | ||
| 21 | @setFnTest(this, true); | ||
| 22 | |||
| 23 | const result = switch (%%foo(2)) { | ||
| 24 | One => false, | ||
| 25 | Two => |x| x, | ||
| 26 | }; | ||
| 27 | assert(result); | ||
| 28 | } | ||
test/cases3/const_slice_child.zig created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | var argv: &&const u8 = undefined; | ||
| 2 | |||
| 3 | fn constSliceChild() { | ||
| 4 | @setFnTest(this); | ||
| 5 | |||
| 6 | const strs = ([]&const u8) { | ||
| 7 | c"one", | ||
| 8 | c"two", | ||
| 9 | c"three", | ||
| 10 | }; | ||
| 11 | argv = &strs[0]; | ||
| 12 | bar(strs.len); | ||
| 13 | } | ||
| 14 | |||
| 15 | fn foo(args: [][]const u8) { | ||
| 16 | assert(args.len == 3); | ||
| 17 | assert(streql(args[0], "one")); | ||
| 18 | assert(streql(args[1], "two")); | ||
| 19 | assert(streql(args[2], "three")); | ||
| 20 | } | ||
| 21 | |||
| 22 | fn bar(argc: usize) { | ||
| 23 | const args = @alloca([]u8, argc); | ||
| 24 | for (args) |_, i| { | ||
| 25 | const ptr = argv[i]; | ||
| 26 | args[i] = ptr[0...strlen(ptr)]; | ||
| 27 | } | ||
| 28 | foo(args); | ||
| 29 | } | ||
| 30 | |||
| 31 | fn strlen(ptr: &const u8) -> usize { | ||
| 32 | var count: usize = 0; | ||
| 33 | while (ptr[count] != 0; count += 1) {} | ||
| 34 | return count; | ||
| 35 | } | ||
| 36 | |||
| 37 | fn streql(a: []const u8, b: []const u8) -> bool { | ||
| 38 | if (a.len != b.len) return false; | ||
| 39 | for (a) |item, index| { | ||
| 40 | if (b[index] != item) return false; | ||
| 41 | } | ||
| 42 | return true; | ||
| 43 | } | ||
| 44 | |||
| 45 | // TODO const assert = @import("std").debug.assert; | ||
| 46 | fn assert(ok: bool) { | ||
| 47 | if (!ok) | ||
| 48 | @unreachable(); | ||
| 49 | } | ||
test/cases3/switch_prong_err_enum.zig created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | var read_count: u64 = 0; | ||
| 2 | |||
| 3 | fn readOnce() -> %u64 { | ||
| 4 | read_count += 1; | ||
| 5 | return read_count; | ||
| 6 | } | ||
| 7 | |||
| 8 | error InvalidDebugInfo; | ||
| 9 | |||
| 10 | const FormValue = enum { | ||
| 11 | Address: u64, | ||
| 12 | Other: bool, | ||
| 13 | }; | ||
| 14 | |||
| 15 | fn doThing(form_id: u64) -> %FormValue { | ||
| 16 | return switch (form_id) { | ||
| 17 | 17 => FormValue.Address { %return readOnce() }, | ||
| 18 | else => error.InvalidDebugInfo, | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | fn switchProngReturnsErrorEnum() { | ||
| 23 | @setFnTest(this); | ||
| 24 | |||
| 25 | %%doThing(17); | ||
| 26 | assert(read_count == 1); | ||
| 27 | } | ||
| 28 | |||
| 29 | // TODO const assert = @import("std").debug.assert; | ||
| 30 | fn assert(ok: bool) { | ||
| 31 | if (!ok) | ||
| 32 | @unreachable(); | ||
| 33 | } | ||
test/cases3/switch_prong_implicit_cast.zig created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | const FormValue = enum { | ||
| 2 | One, | ||
| 3 | Two: bool, | ||
| 4 | }; | ||
| 5 | |||
| 6 | error Whatever; | ||
| 7 | |||
| 8 | fn foo(id: u64) -> %FormValue { | ||
| 9 | switch (id) { | ||
| 10 | 2 => FormValue.Two { true }, | ||
| 11 | 1 => FormValue.One, | ||
| 12 | else => return error.Whatever, | ||
| 13 | } | ||
| 14 | } | ||
| 15 | |||
| 16 | fn switchProngImplicitCast() { | ||
| 17 | @setFnTest(this); | ||
| 18 | |||
| 19 | const result = switch (%%foo(2)) { | ||
| 20 | FormValue.One => false, | ||
| 21 | FormValue.Two => |x| x, | ||
| 22 | }; | ||
| 23 | assert(result); | ||
| 24 | } | ||
| 25 | |||
| 26 | // TODO const assert = @import("std").debug.assert; | ||
| 27 | fn assert(ok: bool) { | ||
| 28 | if (!ok) | ||
| 29 | @unreachable(); | ||
| 30 | } | ||
test/self_hosted.zig-3| ... | @@ -2,9 +2,6 @@ const std = @import("std"); | ... | @@ -2,9 +2,6 @@ const std = @import("std"); |
| 2 | const assert = std.debug.assert; | 2 | const assert = std.debug.assert; |
| 3 | const str = std.str; | 3 | const str = std.str; |
| 4 | const cstr = std.cstr; | 4 | const cstr = std.cstr; |
| 5 | const test_const_slice_child = @import("cases/const_slice_child.zig"); | ||
| 6 | const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig"); | ||
| 7 | const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig"); | ||
| 8 | const test_enum_with_members = @import("cases/enum_with_members.zig"); | 5 | const test_enum_with_members = @import("cases/enum_with_members.zig"); |
| 9 | 6 | ||
| 10 | 7 |
test/self_hosted3.zig+3| ... | @@ -3,6 +3,7 @@ const test_array = @import("cases3/array.zig"); | ... | @@ -3,6 +3,7 @@ const test_array = @import("cases3/array.zig"); |
| 3 | const test_atomics = @import("cases3/atomics.zig"); | 3 | const test_atomics = @import("cases3/atomics.zig"); |
| 4 | const test_bool = @import("cases3/bool.zig"); | 4 | const test_bool = @import("cases3/bool.zig"); |
| 5 | const test_cast= @import("cases3/cast.zig"); | 5 | const test_cast= @import("cases3/cast.zig"); |
| 6 | const test_const_slice_child = @import("cases3/const_slice_child.zig"); | ||
| 6 | const test_defer = @import("cases3/defer.zig"); | 7 | const test_defer = @import("cases3/defer.zig"); |
| 7 | const test_enum = @import("cases3/enum.zig"); | 8 | const test_enum = @import("cases3/enum.zig"); |
| 8 | const test_error = @import("cases3/error.zig"); | 9 | const test_error = @import("cases3/error.zig"); |
| ... | @@ -20,5 +21,7 @@ const test_sizeof_and_typeof = @import("cases3/sizeof_and_typeof.zig"); | ... | @@ -20,5 +21,7 @@ const test_sizeof_and_typeof = @import("cases3/sizeof_and_typeof.zig"); |
| 20 | const test_struct = @import("cases3/struct.zig"); | 21 | const test_struct = @import("cases3/struct.zig"); |
| 21 | const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig"); | 22 | const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig"); |
| 22 | const test_switch = @import("cases3/switch.zig"); | 23 | const test_switch = @import("cases3/switch.zig"); |
| 24 | const test_switch_prong_err_enum = @import("cases3/switch_prong_err_enum.zig"); | ||
| 25 | const test_switch_prong_implicit_cast = @import("cases3/switch_prong_implicit_cast.zig"); | ||
| 23 | const test_this = @import("cases3/this.zig"); | 26 | const test_this = @import("cases3/this.zig"); |
| 24 | const test_while = @import("cases3/while.zig"); | 27 | const test_while = @import("cases3/while.zig"); |