authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-01 23:27:38-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-01 23:27:38-07:00
logb465037a65dd6a31c5865086ec4392a1d3a372bc
tree1c95f588e43e777e2dc77038cc29ff6ab3fde26c
parenteba153f88f0bdb36a654bd2cb794d2ead9d4e398

move some behavior tests to the "passing for stage2" section


3 files changed, 76 insertions(+), 92 deletions(-)

test/behavior/basic.zig+65
...@@ -18,3 +18,68 @@ test "truncate" {...@@ -18,3 +18,68 @@ test "truncate" {
18fn testTruncate(x: u32) u8 {18fn testTruncate(x: u32) u8 {
19 return @truncate(u8, x);19 return @truncate(u8, x);
20}20}
21
22const g1: i32 = 1233 + 1;
23var g2: i32 = 0;
24
25test "global variables" {
26 try expect(g2 == 0);
27 g2 = g1;
28 try expect(g2 == 1234);
29}
30
31test "comptime keyword on expressions" {
32 const x: i32 = comptime x: {
33 break :x 1 + 2 + 3;
34 };
35 try expect(x == comptime 6);
36}
37
38test "type equality" {
39 try expect(*const u8 != *u8);
40}
41
42test "pointer dereferencing" {
43 var x = @as(i32, 3);
44 const y = &x;
45
46 y.* += 1;
47
48 try expect(x == 4);
49 try expect(y.* == 4);
50}
51
52test "const expression eval handling of variables" {
53 var x = true;
54 while (x) {
55 x = false;
56 }
57}
58
59test "character literals" {
60 try expect('\'' == single_quote);
61}
62const single_quote = '\'';
63
64test "non const ptr to aliased type" {
65 const int = i32;
66 try expect(?*int == ?*i32);
67}
68
69test "cold function" {
70 thisIsAColdFn();
71 comptime thisIsAColdFn();
72}
73
74fn thisIsAColdFn() void {
75 @setCold(true);
76}
77
78test "unicode escape in character literal" {
79 var a: u24 = '\u{01f4a9}';
80 try expect(a == 128169);
81}
82
83test "unicode character in character literal" {
84 try expect('💩' == 128169);
85}
test/behavior/misc.zig-92
...@@ -13,15 +13,6 @@ test "return string from function" {...@@ -13,15 +13,6 @@ test "return string from function" {
13 try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));13 try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
14}14}
1515
16const g1: i32 = 1233 + 1;
17var g2: i32 = 0;
18
19test "global variables" {
20 try expect(g2 == 0);
21 g2 = g1;
22 try expect(g2 == 1234);
23}
24
25test "memcpy and memset intrinsics" {16test "memcpy and memset intrinsics" {
26 var foo: [20]u8 = undefined;17 var foo: [20]u8 = undefined;
27 var bar: [20]u8 = undefined;18 var bar: [20]u8 = undefined;
...@@ -32,13 +23,6 @@ test "memcpy and memset intrinsics" {...@@ -32,13 +23,6 @@ test "memcpy and memset intrinsics" {
32 if (bar[11] != 'A') unreachable;23 if (bar[11] != 'A') unreachable;
33}24}
3425
35test "builtin static eval" {
36 const x: i32 = comptime x: {
37 break :x 1 + 2 + 3;
38 };
39 try expect(x == comptime 6);
40}
41
42test "slicing" {26test "slicing" {
43 var array: [20]i32 = undefined;27 var array: [20]i32 = undefined;
4428
...@@ -148,10 +132,6 @@ test "multiline C string" {...@@ -148,10 +132,6 @@ test "multiline C string" {
148 try expect(std.cstr.cmp(s1, s2) == 0);132 try expect(std.cstr.cmp(s1, s2) == 0);
149}133}
150134
151test "type equality" {
152 try expect(*const u8 != *u8);
153}
154
155const global_a: i32 = 1234;135const global_a: i32 = 1234;
156const global_b: *const i32 = &global_a;136const global_b: *const i32 = &global_a;
157const global_c: *const f32 = @ptrCast(*const f32, global_b);137const global_c: *const f32 = @ptrCast(*const f32, global_b);
...@@ -187,17 +167,6 @@ fn testCastUndefined(x: []const u8) void {...@@ -187,17 +167,6 @@ fn testCastUndefined(x: []const u8) void {
187 _ = x;167 _ = x;
188}168}
189169
190test "cast small unsigned to larger signed" {
191 try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
192 try expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
193}
194fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
195 return x;
196}
197fn castSmallUnsignedToLargerSigned2(x: u16) i64 {
198 return x;
199}
200
201test "implicit cast after unreachable" {170test "implicit cast after unreachable" {
202 try expect(outer() == 1234);171 try expect(outer() == 1234);
203}172}
...@@ -208,16 +177,6 @@ fn outer() i64 {...@@ -208,16 +177,6 @@ fn outer() i64 {
208 return inner();177 return inner();
209}178}
210179
211test "pointer dereferencing" {
212 var x = @as(i32, 3);
213 const y = &x;
214
215 y.* += 1;
216
217 try expect(x == 4);
218 try expect(y.* == 4);
219}
220
221test "call result of if else expression" {180test "call result of if else expression" {
222 try expect(mem.eql(u8, f2(true), "a"));181 try expect(mem.eql(u8, f2(true), "a"));
223 try expect(mem.eql(u8, f2(false), "b"));182 try expect(mem.eql(u8, f2(false), "b"));
...@@ -232,13 +191,6 @@ fn fB() []const u8 {...@@ -232,13 +191,6 @@ fn fB() []const u8 {
232 return "b";191 return "b";
233}192}
234193
235test "const expression eval handling of variables" {
236 var x = true;
237 while (x) {
238 x = false;
239 }
240}
241
242test "constant enum initialization with differing sizes" {194test "constant enum initialization with differing sizes" {
243 try test3_1(test3_foo);195 try test3_1(test3_foo);
244 try test3_2(test3_bar);196 try test3_2(test3_bar);
...@@ -277,11 +229,6 @@ fn test3_2(f: Test3Foo) !void {...@@ -277,11 +229,6 @@ fn test3_2(f: Test3Foo) !void {
277 }229 }
278}230}
279231
280test "character literals" {
281 try expect('\'' == single_quote);
282}
283const single_quote = '\'';
284
285test "take address of parameter" {232test "take address of parameter" {
286 try testTakeAddressOfParameter(12.34);233 try testTakeAddressOfParameter(12.34);
287}234}
...@@ -330,11 +277,6 @@ fn testPointerToVoidReturnType2() *const void {...@@ -330,11 +277,6 @@ fn testPointerToVoidReturnType2() *const void {
330 return &test_pointer_to_void_return_type_x;277 return &test_pointer_to_void_return_type_x;
331}278}
332279
333test "non const ptr to aliased type" {
334 const int = i32;
335 try expect(?*int == ?*i32);
336}
337
338test "array 2D const double ptr" {280test "array 2D const double ptr" {
339 const rect_2d_vertexes = [_][1]f32{281 const rect_2d_vertexes = [_][1]f32{
340 [_]f32{1.0},282 [_]f32{1.0},
...@@ -349,22 +291,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) !void {...@@ -349,22 +291,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) !void {
349 try expect(ptr2[1] == 2.0);291 try expect(ptr2[1] == 2.0);
350}292}
351293
352const AStruct = struct {
353 x: i32,
354};
355const AnEnum = enum {
356 One,
357 Two,
358};
359const AUnionEnum = union(enum) {
360 One: i32,
361 Two: void,
362};
363const AUnion = union {
364 One: void,
365 Two: void,
366};
367
368test "double implicit cast in same expression" {294test "double implicit cast in same expression" {
369 var x = @as(i32, @as(u16, nine()));295 var x = @as(i32, @as(u16, nine()));
370 try expect(x == 9);296 try expect(x == 9);
...@@ -440,15 +366,6 @@ test "function closes over local const" {...@@ -440,15 +366,6 @@ test "function closes over local const" {
440 try expect(x == 1);366 try expect(x == 1);
441}367}
442368
443test "cold function" {
444 thisIsAColdFn();
445 comptime thisIsAColdFn();
446}
447
448fn thisIsAColdFn() void {
449 @setCold(true);
450}
451
452const PackedStruct = packed struct {369const PackedStruct = packed struct {
453 a: u8,370 a: u8,
454 b: u8,371 b: u8,
...@@ -562,15 +479,6 @@ test "thread local variable" {...@@ -562,15 +479,6 @@ test "thread local variable" {
562 try expect(S.t == 1235);479 try expect(S.t == 1235);
563}480}
564481
565test "unicode escape in character literal" {
566 var a: u24 = '\u{01f4a9}';
567 try expect(a == 128169);
568}
569
570test "unicode character in character literal" {
571 try expect('💩' == 128169);
572}
573
574test "result location zero sized array inside struct field implicit cast to slice" {482test "result location zero sized array inside struct field implicit cast to slice" {
575 const E = struct {483 const E = struct {
576 entries: []u32,484 entries: []u32,
test/behavior/widening.zig+11
...@@ -37,3 +37,14 @@ test "float widening f16 to f128" {...@@ -37,3 +37,14 @@ test "float widening f16 to f128" {
37 var y: f128 = x;37 var y: f128 = x;
38 try expect(x == y);38 try expect(x == y);
39}39}
40
41test "cast small unsigned to larger signed" {
42 try expect(castSmallUnsignedToLargerSigned1(200) == @as(i16, 200));
43 try expect(castSmallUnsignedToLargerSigned2(9999) == @as(i64, 9999));
44}
45fn castSmallUnsignedToLargerSigned1(x: u8) i16 {
46 return x;
47}
48fn castSmallUnsignedToLargerSigned2(x: u16) i64 {
49 return x;
50}