authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-22 10:09:53-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-22 10:10:04-05:00
log8dc45bc50523d9fa58a937f525b9dc8f7569af0b
treee5eae8644ae53052dc93c0967d78e69f70e5c936
parentba8af0f1e281fc7e56a8f4eb6f3974efc6ed043d

port more tests


12 files changed, 106 insertions(+), 143 deletions(-)

test/cases/maybe_return.zig deleted-17
......@@ -1,17 +0,0 @@
1const assert = @import("std").debug.assert;
2
3fn 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
12fn 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 @@
1const assert = @import("std").debug.assert;
2
3pub fn List(inline T: type) -> type {
4 SmallList(T, 8)
5}
6
7pub struct SmallList(inline T: type, inline STATIC_SIZE: usize) {
8 items: []T,
9 length: usize,
10 prealloc_items: [STATIC_SIZE]T,
11}
12
13fn 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 @@
1const assert = @import("std").debug.assert;
2
3fn sizeofAndTypeOf() {
4 @setFnTest(this, true);
5
6 const y: @typeOf(x) = 120;
7 assert(@sizeOf(@typeOf(y)) == 2);
8}
9const x: u16 = 13;
10const z: @typeOf(x) = 19;
test/cases/var_params.zig deleted-35
......@@ -1,35 +0,0 @@
1const assert = @import("std").debug.assert;
2
3fn 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
13fn max(a: var, b: var) -> @typeOf(a) {
14 if (a > b) a else b
15}
16
17fn max_i32(a: i32, b: i32) -> i32 {
18 max(a, b)
19}
20
21fn max_f64(a: f64, b: f64) -> f64 {
22 max(a, b)
23}
24
25fn max_i32_noeval(a: i32, b: i32) -> i32 {
26 @setFnStaticEval(this, false);
27
28 max(a, b)
29}
30
31fn 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);
5252fn staticAdd(a: i32, b: i32) -> i32 { a + b }
5353
5454
55fn constExprEvalOnSingleExprBlocks() {
56 @setFnTest(this);
57
58 assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
59}
60
61fn 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
5574
5675
5776
test/cases3/fn.zig+13
......@@ -73,6 +73,19 @@ fn @"weird function name"() {
7373 @setFnTest(this);
7474}
7575
76fn implicitCastFnUnreachableReturn() {
77 @setFnTest(this);
78
79 wantsFnWithVoid(fnWithUnreachable);
80}
81
82fn wantsFnWithVoid(f: fn()) { }
83
84fn fnWithUnreachable() -> unreachable {
85 @unreachable()
86}
87
88
7689
7790// TODO const assert = @import("std").debug.assert;
7891fn assert(ok: bool) {
test/cases3/generics.zig+24
......@@ -64,6 +64,30 @@ fn max_f64(a: f64, b: f64) -> f64 {
6464 max_var(a, b)
6565}
6666
67
68pub fn List(inline T: type) -> type {
69 SmallList(T, 8)
70}
71
72pub 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
80fn 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
6791// TODO const assert = @import("std").debug.assert;
6892fn assert(ok: bool) {
6993 if (!ok)
test/cases3/misc.zig+12
......@@ -230,6 +230,18 @@ fn stringEscapes() {
230230 assert(memeql("\u1234\u0069", "\xe1\x88\xb4\x69"));
231231}
232232
233fn 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
233245
234246// TODO import from std.str
235247pub fn memeql(a: []const u8, b: []const u8) -> bool {
test/cases3/null.zig+21
......@@ -38,6 +38,27 @@ fn assignToIfVarPtr() {
3838 assert(??maybe_bool == false);
3939}
4040
41fn rhsMaybeUnwrapReturn() {
42 @setFnTest(this);
43
44 const x: ?bool = true;
45 const y = x ?? return;
46}
47
48
49fn 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
58fn foo(x: ?i32) -> ?bool {
59 const value = ?return x;
60 return value > 1234;
61}
4162
4263// TODO const assert = @import("std").debug.assert;
4364fn assert(ok: bool) {
test/cases3/sizeof_and_typeof.zig created+14
......@@ -0,0 +1,14 @@
1fn sizeofAndTypeOf() {
2 @setFnTest(this);
3
4 const y: @typeOf(x) = 120;
5 assert(@sizeOf(@typeOf(y)) == 2);
6}
7const x: u16 = 13;
8const z: @typeOf(x) = 19;
9
10// TODO const assert = @import("std").debug.assert;
11fn assert(ok: bool) {
12 if (!ok)
13 @unreachable();
14}
test/self_hosted.zig+1-58
......@@ -2,36 +2,10 @@ const std = @import("std");
22const assert = std.debug.assert;
33const str = std.str;
44const cstr = std.cstr;
5const test_return_type_type = @import("cases/return_type_type.zig");
6const test_sizeof_and_typeof = @import("cases/sizeof_and_typeof.zig");
7const test_maybe_return = @import("cases/maybe_return.zig");
8const test_var_params = @import("cases/var_params.zig");
95const test_const_slice_child = @import("cases/const_slice_child.zig");
106const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig");
117const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig");
128const test_enum_with_members = @import("cases/enum_with_members.zig");
13const test_struct_contains_slice_of_itself = @import("cases/struct_contains_slice_of_itself.zig");
14
15
16fn rhsMaybeUnwrapReturn() {
17 @setFnTest(this, true);
18
19 const x = ?true;
20 const y = x ?? return;
21}
22
23
24fn implicitCastFnUnreachableReturn() {
25 @setFnTest(this, true);
26
27 wantsFnWithVoid(fnWithUnreachable);
28}
29
30fn wantsFnWithVoid(f: fn()) { }
31
32fn fnWithUnreachable() -> unreachable {
33 @unreachable()
34}
359
3610
3711fn explicitCastMaybePointers() {
......@@ -42,39 +16,8 @@ fn explicitCastMaybePointers() {
4216}
4317
4418
45fn constExprEvalOnSingleExprBlocks() {
46 @setFnTest(this, true);
47
48 assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
49}
50
51fn 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
64fn 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
7619fn multilineCString() {
77 @setFnTest(this, true);
20 @setFnTest(this);
7821
7922 const s1 =
8023 c\\one
test/self_hosted3.zig+2-1
......@@ -16,8 +16,9 @@ const test_import = @import("cases3/import.zig");
1616const test_math = @import("cases3/math.zig");
1717const test_misc = @import("cases3/misc.zig");
1818const test_null = @import("cases3/null.zig");
19const test_sizeof_and_typeof = @import("cases3/sizeof_and_typeof.zig");
1920const test_struct = @import("cases3/struct.zig");
21const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig");
2022const test_switch = @import("cases3/switch.zig");
2123const test_this = @import("cases3/this.zig");
2224const test_while = @import("cases3/while.zig");
23const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig");