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" {
1818fn testTruncate(x: u32) u8 {
1919 return @truncate(u8, x);
2020}
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" {
1313 try expect(mem.eql(u8, first4KeysOfHomeRow(), "aoeu"));
1414}
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
2516test "memcpy and memset intrinsics" {
2617 var foo: [20]u8 = undefined;
2718 var bar: [20]u8 = undefined;
......@@ -32,13 +23,6 @@ test "memcpy and memset intrinsics" {
3223 if (bar[11] != 'A') unreachable;
3324}
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
4226test "slicing" {
4327 var array: [20]i32 = undefined;
4428
......@@ -148,10 +132,6 @@ test "multiline C string" {
148132 try expect(std.cstr.cmp(s1, s2) == 0);
149133}
150134
151test "type equality" {
152 try expect(*const u8 != *u8);
153}
154
155135const global_a: i32 = 1234;
156136const global_b: *const i32 = &global_a;
157137const global_c: *const f32 = @ptrCast(*const f32, global_b);
......@@ -187,17 +167,6 @@ fn testCastUndefined(x: []const u8) void {
187167 _ = x;
188168}
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
201170test "implicit cast after unreachable" {
202171 try expect(outer() == 1234);
203172}
......@@ -208,16 +177,6 @@ fn outer() i64 {
208177 return inner();
209178}
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
221180test "call result of if else expression" {
222181 try expect(mem.eql(u8, f2(true), "a"));
223182 try expect(mem.eql(u8, f2(false), "b"));
......@@ -232,13 +191,6 @@ fn fB() []const u8 {
232191 return "b";
233192}
234193
235test "const expression eval handling of variables" {
236 var x = true;
237 while (x) {
238 x = false;
239 }
240}
241
242194test "constant enum initialization with differing sizes" {
243195 try test3_1(test3_foo);
244196 try test3_2(test3_bar);
......@@ -277,11 +229,6 @@ fn test3_2(f: Test3Foo) !void {
277229 }
278230}
279231
280test "character literals" {
281 try expect('\'' == single_quote);
282}
283const single_quote = '\'';
284
285232test "take address of parameter" {
286233 try testTakeAddressOfParameter(12.34);
287234}
......@@ -330,11 +277,6 @@ fn testPointerToVoidReturnType2() *const void {
330277 return &test_pointer_to_void_return_type_x;
331278}
332279
333test "non const ptr to aliased type" {
334 const int = i32;
335 try expect(?*int == ?*i32);
336}
337
338280test "array 2D const double ptr" {
339281 const rect_2d_vertexes = [_][1]f32{
340282 [_]f32{1.0},
......@@ -349,22 +291,6 @@ fn testArray2DConstDoublePtr(ptr: *const f32) !void {
349291 try expect(ptr2[1] == 2.0);
350292}
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
368294test "double implicit cast in same expression" {
369295 var x = @as(i32, @as(u16, nine()));
370296 try expect(x == 9);
......@@ -440,15 +366,6 @@ test "function closes over local const" {
440366 try expect(x == 1);
441367}
442368
443test "cold function" {
444 thisIsAColdFn();
445 comptime thisIsAColdFn();
446}
447
448fn thisIsAColdFn() void {
449 @setCold(true);
450}
451
452369const PackedStruct = packed struct {
453370 a: u8,
454371 b: u8,
......@@ -562,15 +479,6 @@ test "thread local variable" {
562479 try expect(S.t == 1235);
563480}
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
574482test "result location zero sized array inside struct field implicit cast to slice" {
575483 const E = struct {
576484 entries: []u32,
test/behavior/widening.zig+11
......@@ -37,3 +37,14 @@ test "float widening f16 to f128" {
3737 var y: f128 = x;
3838 try expect(x == y);
3939}
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}