| author | |
| committer | |
| log | 8dc45bc50523d9fa58a937f525b9dc8f7569af0b |
| tree | e5eae8644ae53052dc93c0967d78e69f70e5c936 |
| parent | ba8af0f1e281fc7e56a8f4eb6f3974efc6ed043d |
12 files changed, 106 insertions(+), 143 deletions(-)
test/cases/maybe_return.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | const assert = @import("std").debug.assert; | ||
| 2 | |||
| 3 | fn maybeReturn() { | ||
| 4 | @setFnTest(this, true); | ||
| 5 | |||
| 6 | assert(??foo(1235)); | ||
| 7 | assert(if (const _ ?= foo(null)) false else true); | ||
| 8 | assert(!??foo(1234)); | ||
| 9 | } | ||
| 10 | |||
| 11 | // TODO test static eval maybe return | ||
| 12 | fn foo(x: ?i32) -> ?bool { | ||
| 13 | @setFnStaticEval(this, false); | ||
| 14 | |||
| 15 | const value = ?return x; | ||
| 16 | return value > 1234; | ||
| 17 | } | ||
test/cases/return_type_type.zig deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | const assert = @import("std").debug.assert; | ||
| 2 | |||
| 3 | pub fn List(inline T: type) -> type { | ||
| 4 | SmallList(T, 8) | ||
| 5 | } | ||
| 6 | |||
| 7 | pub struct SmallList(inline T: type, inline STATIC_SIZE: usize) { | ||
| 8 | items: []T, | ||
| 9 | length: usize, | ||
| 10 | prealloc_items: [STATIC_SIZE]T, | ||
| 11 | } | ||
| 12 | |||
| 13 | fn functionWithReturnTypeType() { | ||
| 14 | @setFnTest(this, true); | ||
| 15 | |||
| 16 | var list: List(i32) = undefined; | ||
| 17 | var list2: List(i32) = undefined; | ||
| 18 | list.length = 10; | ||
| 19 | list2.length = 10; | ||
| 20 | assert(list.prealloc_items.len == 8); | ||
| 21 | assert(list2.prealloc_items.len == 8); | ||
| 22 | } | ||
test/cases/sizeof_and_typeof.zig deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | const assert = @import("std").debug.assert; | ||
| 2 | |||
| 3 | fn sizeofAndTypeOf() { | ||
| 4 | @setFnTest(this, true); | ||
| 5 | |||
| 6 | const y: @typeOf(x) = 120; | ||
| 7 | assert(@sizeOf(@typeOf(y)) == 2); | ||
| 8 | } | ||
| 9 | const x: u16 = 13; | ||
| 10 | const z: @typeOf(x) = 19; | ||
test/cases/var_params.zig deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | const assert = @import("std").debug.assert; | ||
| 2 | |||
| 3 | fn varParams() { | ||
| 4 | @setFnTest(this, true); | ||
| 5 | |||
| 6 | assert(max_i32(12, 34) == 34); | ||
| 7 | assert(max_f64(1.2, 3.4) == 3.4); | ||
| 8 | |||
| 9 | assert(max_i32_noeval(12, 34) == 34); | ||
| 10 | assert(max_f64_noeval(1.2, 3.4) == 3.4); | ||
| 11 | } | ||
| 12 | |||
| 13 | fn max(a: var, b: var) -> @typeOf(a) { | ||
| 14 | if (a > b) a else b | ||
| 15 | } | ||
| 16 | |||
| 17 | fn max_i32(a: i32, b: i32) -> i32 { | ||
| 18 | max(a, b) | ||
| 19 | } | ||
| 20 | |||
| 21 | fn max_f64(a: f64, b: f64) -> f64 { | ||
| 22 | max(a, b) | ||
| 23 | } | ||
| 24 | |||
| 25 | fn max_i32_noeval(a: i32, b: i32) -> i32 { | ||
| 26 | @setFnStaticEval(this, false); | ||
| 27 | |||
| 28 | max(a, b) | ||
| 29 | } | ||
| 30 | |||
| 31 | fn max_f64_noeval(a: f64, b: f64) -> f64 { | ||
| 32 | @setFnStaticEval(this, false); | ||
| 33 | |||
| 34 | max(a, b) | ||
| 35 | } | ||
test/cases3/eval.zig+19| ... | @@ -52,6 +52,25 @@ const statically_added_number = staticAdd(1, 2); | ... | @@ -52,6 +52,25 @@ const statically_added_number = staticAdd(1, 2); |
| 52 | fn staticAdd(a: i32, b: i32) -> i32 { a + b } | 52 | fn staticAdd(a: i32, b: i32) -> i32 { a + b } |
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | fn constExprEvalOnSingleExprBlocks() { | ||
| 56 | @setFnTest(this); | ||
| 57 | |||
| 58 | assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | ||
| 59 | } | ||
| 60 | |||
| 61 | fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 { | ||
| 62 | const literal = 3; | ||
| 63 | |||
| 64 | const result = if (b) { | ||
| 65 | literal | ||
| 66 | } else { | ||
| 67 | x | ||
| 68 | }; | ||
| 69 | |||
| 70 | return result; | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 55 | 74 | ||
| 56 | 75 | ||
| 57 | 76 |
test/cases3/fn.zig+13| ... | @@ -73,6 +73,19 @@ fn @"weird function name"() { | ... | @@ -73,6 +73,19 @@ fn @"weird function name"() { |
| 73 | @setFnTest(this); | 73 | @setFnTest(this); |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | fn implicitCastFnUnreachableReturn() { | ||
| 77 | @setFnTest(this); | ||
| 78 | |||
| 79 | wantsFnWithVoid(fnWithUnreachable); | ||
| 80 | } | ||
| 81 | |||
| 82 | fn wantsFnWithVoid(f: fn()) { } | ||
| 83 | |||
| 84 | fn fnWithUnreachable() -> unreachable { | ||
| 85 | @unreachable() | ||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 76 | 89 | ||
| 77 | // TODO const assert = @import("std").debug.assert; | 90 | // TODO const assert = @import("std").debug.assert; |
| 78 | fn assert(ok: bool) { | 91 | fn assert(ok: bool) { |
test/cases3/generics.zig+24| ... | @@ -64,6 +64,30 @@ fn max_f64(a: f64, b: f64) -> f64 { | ... | @@ -64,6 +64,30 @@ fn max_f64(a: f64, b: f64) -> f64 { |
| 64 | max_var(a, b) | 64 | max_var(a, b) |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | |||
| 68 | pub fn List(inline T: type) -> type { | ||
| 69 | SmallList(T, 8) | ||
| 70 | } | ||
| 71 | |||
| 72 | pub fn SmallList(inline T: type, inline STATIC_SIZE: usize) -> type { | ||
| 73 | struct { | ||
| 74 | items: []T, | ||
| 75 | length: usize, | ||
| 76 | prealloc_items: [STATIC_SIZE]T, | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | fn functionWithReturnTypeType() { | ||
| 81 | @setFnTest(this); | ||
| 82 | |||
| 83 | var list: List(i32) = undefined; | ||
| 84 | var list2: List(i32) = undefined; | ||
| 85 | list.length = 10; | ||
| 86 | list2.length = 10; | ||
| 87 | assert(list.prealloc_items.len == 8); | ||
| 88 | assert(list2.prealloc_items.len == 8); | ||
| 89 | } | ||
| 90 | |||
| 67 | // TODO const assert = @import("std").debug.assert; | 91 | // TODO const assert = @import("std").debug.assert; |
| 68 | fn assert(ok: bool) { | 92 | fn assert(ok: bool) { |
| 69 | if (!ok) | 93 | if (!ok) |
test/cases3/misc.zig+12| ... | @@ -230,6 +230,18 @@ fn stringEscapes() { | ... | @@ -230,6 +230,18 @@ fn stringEscapes() { |
| 230 | assert(memeql("\u1234\u0069", "\xe1\x88\xb4\x69")); | 230 | assert(memeql("\u1234\u0069", "\xe1\x88\xb4\x69")); |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | fn multilineString() { | ||
| 234 | @setFnTest(this); | ||
| 235 | |||
| 236 | const s1 = | ||
| 237 | \\one | ||
| 238 | \\two) | ||
| 239 | \\three | ||
| 240 | ; | ||
| 241 | const s2 = "one\ntwo)\nthree"; | ||
| 242 | assert(memeql(s1, s2)); | ||
| 243 | } | ||
| 244 | |||
| 233 | 245 | ||
| 234 | // TODO import from std.str | 246 | // TODO import from std.str |
| 235 | pub fn memeql(a: []const u8, b: []const u8) -> bool { | 247 | pub fn memeql(a: []const u8, b: []const u8) -> bool { |
test/cases3/null.zig+21| ... | @@ -38,6 +38,27 @@ fn assignToIfVarPtr() { | ... | @@ -38,6 +38,27 @@ fn assignToIfVarPtr() { |
| 38 | assert(??maybe_bool == false); | 38 | assert(??maybe_bool == false); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | fn rhsMaybeUnwrapReturn() { | ||
| 42 | @setFnTest(this); | ||
| 43 | |||
| 44 | const x: ?bool = true; | ||
| 45 | const y = x ?? return; | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | fn maybeReturn() { | ||
| 50 | @setFnTest(this); | ||
| 51 | |||
| 52 | assert(??foo(1235)); | ||
| 53 | assert(if (const _ ?= foo(null)) false else true); | ||
| 54 | assert(!??foo(1234)); | ||
| 55 | } | ||
| 56 | |||
| 57 | // TODO test static eval maybe return | ||
| 58 | fn foo(x: ?i32) -> ?bool { | ||
| 59 | const value = ?return x; | ||
| 60 | return value > 1234; | ||
| 61 | } | ||
| 41 | 62 | ||
| 42 | // TODO const assert = @import("std").debug.assert; | 63 | // TODO const assert = @import("std").debug.assert; |
| 43 | fn assert(ok: bool) { | 64 | fn assert(ok: bool) { |
test/cases3/sizeof_and_typeof.zig created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | fn sizeofAndTypeOf() { | ||
| 2 | @setFnTest(this); | ||
| 3 | |||
| 4 | const y: @typeOf(x) = 120; | ||
| 5 | assert(@sizeOf(@typeOf(y)) == 2); | ||
| 6 | } | ||
| 7 | const x: u16 = 13; | ||
| 8 | const z: @typeOf(x) = 19; | ||
| 9 | |||
| 10 | // TODO const assert = @import("std").debug.assert; | ||
| 11 | fn assert(ok: bool) { | ||
| 12 | if (!ok) | ||
| 13 | @unreachable(); | ||
| 14 | } | ||
test/self_hosted.zig+1-58| ... | @@ -2,36 +2,10 @@ const std = @import("std"); | ... | @@ -2,36 +2,10 @@ 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_return_type_type = @import("cases/return_type_type.zig"); | ||
| 6 | const test_sizeof_and_typeof = @import("cases/sizeof_and_typeof.zig"); | ||
| 7 | const test_maybe_return = @import("cases/maybe_return.zig"); | ||
| 8 | const test_var_params = @import("cases/var_params.zig"); | ||
| 9 | const test_const_slice_child = @import("cases/const_slice_child.zig"); | 5 | const test_const_slice_child = @import("cases/const_slice_child.zig"); |
| 10 | const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig"); | 6 | const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig"); |
| 11 | const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig"); | 7 | const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig"); |
| 12 | const test_enum_with_members = @import("cases/enum_with_members.zig"); | 8 | const test_enum_with_members = @import("cases/enum_with_members.zig"); |
| 13 | const test_struct_contains_slice_of_itself = @import("cases/struct_contains_slice_of_itself.zig"); | ||
| 14 | |||
| 15 | |||
| 16 | fn rhsMaybeUnwrapReturn() { | ||
| 17 | @setFnTest(this, true); | ||
| 18 | |||
| 19 | const x = ?true; | ||
| 20 | const y = x ?? return; | ||
| 21 | } | ||
| 22 | |||
| 23 | |||
| 24 | fn implicitCastFnUnreachableReturn() { | ||
| 25 | @setFnTest(this, true); | ||
| 26 | |||
| 27 | wantsFnWithVoid(fnWithUnreachable); | ||
| 28 | } | ||
| 29 | |||
| 30 | fn wantsFnWithVoid(f: fn()) { } | ||
| 31 | |||
| 32 | fn fnWithUnreachable() -> unreachable { | ||
| 33 | @unreachable() | ||
| 34 | } | ||
| 35 | 9 | ||
| 36 | 10 | ||
| 37 | fn explicitCastMaybePointers() { | 11 | fn explicitCastMaybePointers() { |
| ... | @@ -42,39 +16,8 @@ fn explicitCastMaybePointers() { | ... | @@ -42,39 +16,8 @@ fn explicitCastMaybePointers() { |
| 42 | } | 16 | } |
| 43 | 17 | ||
| 44 | 18 | ||
| 45 | fn constExprEvalOnSingleExprBlocks() { | ||
| 46 | @setFnTest(this, true); | ||
| 47 | |||
| 48 | assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3); | ||
| 49 | } | ||
| 50 | |||
| 51 | fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 { | ||
| 52 | const literal = 3; | ||
| 53 | |||
| 54 | const result = if (b) { | ||
| 55 | literal | ||
| 56 | } else { | ||
| 57 | x | ||
| 58 | }; | ||
| 59 | |||
| 60 | return result; | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | fn multilineString() { | ||
| 65 | @setFnTest(this, true); | ||
| 66 | |||
| 67 | const s1 = | ||
| 68 | \\one | ||
| 69 | \\two) | ||
| 70 | \\three | ||
| 71 | ; | ||
| 72 | const s2 = "one\ntwo)\nthree"; | ||
| 73 | assert(str.eql(s1, s2)); | ||
| 74 | } | ||
| 75 | |||
| 76 | fn multilineCString() { | 19 | fn multilineCString() { |
| 77 | @setFnTest(this, true); | 20 | @setFnTest(this); |
| 78 | 21 | ||
| 79 | const s1 = | 22 | const s1 = |
| 80 | c\\one | 23 | c\\one |
test/self_hosted3.zig+2-1| ... | @@ -16,8 +16,9 @@ const test_import = @import("cases3/import.zig"); | ... | @@ -16,8 +16,9 @@ const test_import = @import("cases3/import.zig"); |
| 16 | const test_math = @import("cases3/math.zig"); | 16 | const test_math = @import("cases3/math.zig"); |
| 17 | const test_misc = @import("cases3/misc.zig"); | 17 | const test_misc = @import("cases3/misc.zig"); |
| 18 | const test_null = @import("cases3/null.zig"); | 18 | const test_null = @import("cases3/null.zig"); |
| 19 | const test_sizeof_and_typeof = @import("cases3/sizeof_and_typeof.zig"); | ||
| 19 | const test_struct = @import("cases3/struct.zig"); | 20 | const test_struct = @import("cases3/struct.zig"); |
| 21 | const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig"); | ||
| 20 | const test_switch = @import("cases3/switch.zig"); | 22 | const test_switch = @import("cases3/switch.zig"); |
| 21 | const test_this = @import("cases3/this.zig"); | 23 | const test_this = @import("cases3/this.zig"); |
| 22 | const test_while = @import("cases3/while.zig"); | 24 | const test_while = @import("cases3/while.zig"); |
| 23 | const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig"); |