authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-15 23:32:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-01-16 10:14:57-07:00
log0f3938e498624868a951423a0b1ca9749301130a
tree4fb0586ef92bbdfa92119c53839dcd51e0efa519
parentf19b5ecf4b99652cd385cfdfedfa826260174871

behavior tests: move tests around


3 files changed, 102 insertions(+), 100 deletions(-)

test/behavior.zig-1
...@@ -124,7 +124,6 @@ test {...@@ -124,7 +124,6 @@ test {
124 } else {124 } else {
125 // Tests that only pass for the stage1 backend.125 // Tests that only pass for the stage1 backend.
126 _ = @import("behavior/align_stage1.zig");126 _ = @import("behavior/align_stage1.zig");
127 _ = @import("behavior/array_stage1.zig");
128 if (builtin.os.tag != .wasi) {127 if (builtin.os.tag != .wasi) {
129 _ = @import("behavior/asm.zig");128 _ = @import("behavior/asm.zig");
130 _ = @import("behavior/async_fn.zig");129 _ = @import("behavior/async_fn.zig");
test/behavior/array_llvm.zig+102
...@@ -193,3 +193,105 @@ test "type deduction for array subscript expression" {...@@ -193,3 +193,105 @@ test "type deduction for array subscript expression" {
193 try S.doTheTest();193 try S.doTheTest();
194 comptime try S.doTheTest();194 comptime try S.doTheTest();
195}195}
196
197test "sentinel element count towards the ABI size calculation" {
198 if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
199
200 const S = struct {
201 fn doTheTest() !void {
202 const T = packed struct {
203 fill_pre: u8 = 0x55,
204 data: [0:0]u8 = undefined,
205 fill_post: u8 = 0xAA,
206 };
207 var x = T{};
208 var as_slice = mem.asBytes(&x);
209 try expect(@as(usize, 3) == as_slice.len);
210 try expect(@as(u8, 0x55) == as_slice[0]);
211 try expect(@as(u8, 0xAA) == as_slice[2]);
212 }
213 };
214
215 try S.doTheTest();
216 comptime try S.doTheTest();
217}
218
219test "zero-sized array with recursive type definition" {
220 if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
221
222 const U = struct {
223 fn foo(comptime T: type, comptime n: usize) type {
224 return struct {
225 s: [n]T,
226 x: usize = n,
227 };
228 }
229 };
230
231 const S = struct {
232 list: U.foo(@This(), 0),
233 };
234
235 var t: S = .{ .list = .{ .s = undefined } };
236 try expect(@as(usize, 0) == t.list.x);
237}
238
239test "type coercion of anon struct literal to array" {
240 if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
241
242 const S = struct {
243 const U = union {
244 a: u32,
245 b: bool,
246 c: []const u8,
247 };
248
249 fn doTheTest() !void {
250 var x1: u8 = 42;
251 const t1 = .{ x1, 56, 54 };
252 var arr1: [3]u8 = t1;
253 try expect(arr1[0] == 42);
254 try expect(arr1[1] == 56);
255 try expect(arr1[2] == 54);
256
257 var x2: U = .{ .a = 42 };
258 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
259 var arr2: [3]U = t2;
260 try expect(arr2[0].a == 42);
261 try expect(arr2[1].b == true);
262 try expect(mem.eql(u8, arr2[2].c, "hello"));
263 }
264 };
265 try S.doTheTest();
266 comptime try S.doTheTest();
267}
268
269test "type coercion of pointer to anon struct literal to pointer to array" {
270 if (@import("builtin").zig_backend == .stage2_llvm) return error.SkipZigTest; // TODO
271
272 const S = struct {
273 const U = union {
274 a: u32,
275 b: bool,
276 c: []const u8,
277 };
278
279 fn doTheTest() !void {
280 var x1: u8 = 42;
281 const t1 = &.{ x1, 56, 54 };
282 var arr1: *const [3]u8 = t1;
283 try expect(arr1[0] == 42);
284 try expect(arr1[1] == 56);
285 try expect(arr1[2] == 54);
286
287 var x2: U = .{ .a = 42 };
288 const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
289 var arr2: *const [3]U = t2;
290 try expect(arr2[0].a == 42);
291 try expect(arr2[1].b == true);
292 try expect(mem.eql(u8, arr2[2].c, "hello"));
293 }
294 };
295 try S.doTheTest();
296 comptime try S.doTheTest();
297}
test/behavior/array_stage1.zig deleted-99
...@@ -1,99 +0,0 @@
1const std = @import("std");
2const testing = std.testing;
3const mem = std.mem;
4const expect = testing.expect;
5const expectEqual = testing.expectEqual;
6
7test "sentinel element count towards the ABI size calculation" {
8 const S = struct {
9 fn doTheTest() !void {
10 const T = packed struct {
11 fill_pre: u8 = 0x55,
12 data: [0:0]u8 = undefined,
13 fill_post: u8 = 0xAA,
14 };
15 var x = T{};
16 var as_slice = mem.asBytes(&x);
17 try expect(@as(usize, 3) == as_slice.len);
18 try expect(@as(u8, 0x55) == as_slice[0]);
19 try expect(@as(u8, 0xAA) == as_slice[2]);
20 }
21 };
22
23 try S.doTheTest();
24 comptime try S.doTheTest();
25}
26
27test "zero-sized array with recursive type definition" {
28 const U = struct {
29 fn foo(comptime T: type, comptime n: usize) type {
30 return struct {
31 s: [n]T,
32 x: usize = n,
33 };
34 }
35 };
36
37 const S = struct {
38 list: U.foo(@This(), 0),
39 };
40
41 var t: S = .{ .list = .{ .s = undefined } };
42 try expect(@as(usize, 0) == t.list.x);
43}
44
45test "type coercion of anon struct literal to array" {
46 const S = struct {
47 const U = union {
48 a: u32,
49 b: bool,
50 c: []const u8,
51 };
52
53 fn doTheTest() !void {
54 var x1: u8 = 42;
55 const t1 = .{ x1, 56, 54 };
56 var arr1: [3]u8 = t1;
57 try expect(arr1[0] == 42);
58 try expect(arr1[1] == 56);
59 try expect(arr1[2] == 54);
60
61 var x2: U = .{ .a = 42 };
62 const t2 = .{ x2, .{ .b = true }, .{ .c = "hello" } };
63 var arr2: [3]U = t2;
64 try expect(arr2[0].a == 42);
65 try expect(arr2[1].b == true);
66 try expect(mem.eql(u8, arr2[2].c, "hello"));
67 }
68 };
69 try S.doTheTest();
70 comptime try S.doTheTest();
71}
72
73test "type coercion of pointer to anon struct literal to pointer to array" {
74 const S = struct {
75 const U = union {
76 a: u32,
77 b: bool,
78 c: []const u8,
79 };
80
81 fn doTheTest() !void {
82 var x1: u8 = 42;
83 const t1 = &.{ x1, 56, 54 };
84 var arr1: *const [3]u8 = t1;
85 try expect(arr1[0] == 42);
86 try expect(arr1[1] == 56);
87 try expect(arr1[2] == 54);
88
89 var x2: U = .{ .a = 42 };
90 const t2 = &.{ x2, .{ .b = true }, .{ .c = "hello" } };
91 var arr2: *const [3]U = t2;
92 try expect(arr2[0].a == 42);
93 try expect(arr2[1].b == true);
94 try expect(mem.eql(u8, arr2[2].c, "hello"));
95 }
96 };
97 try S.doTheTest();
98 comptime try S.doTheTest();
99}