authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2022-01-03 02:04:20+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2022-01-03 02:09:54+01:00
log67449b659dc752b6cc6d9359637af687a4618609
tree8b69d615d0c9172ccce051c8b87e73deddf1c845
parent7f77d3d671dbfec11592d28cd51454aeefd07930

stage2: move some more tests


4 files changed, 70 insertions(+), 69 deletions(-)

test/behavior/type.zig+45
...@@ -57,3 +57,48 @@ test "Type.EnumLiteral" {...@@ -57,3 +57,48 @@ test "Type.EnumLiteral" {
57 @TypeOf(.Dummy),57 @TypeOf(.Dummy),
58 });58 });
59}59}
60
61test "Type.Pointer" {
62 try testTypes(&[_]type{
63 // One Value Pointer Types
64 *u8, *const u8,
65 *volatile u8, *const volatile u8,
66 *align(4) u8, *align(4) const u8,
67 *align(4) volatile u8, *align(4) const volatile u8,
68 *align(8) u8, *align(8) const u8,
69 *align(8) volatile u8, *align(8) const volatile u8,
70 *allowzero u8, *allowzero const u8,
71 *allowzero volatile u8, *allowzero const volatile u8,
72 *allowzero align(4) u8, *allowzero align(4) const u8,
73 *allowzero align(4) volatile u8, *allowzero align(4) const volatile u8,
74 // Many Values Pointer Types
75 [*]u8, [*]const u8,
76 [*]volatile u8, [*]const volatile u8,
77 [*]align(4) u8, [*]align(4) const u8,
78 [*]align(4) volatile u8, [*]align(4) const volatile u8,
79 [*]align(8) u8, [*]align(8) const u8,
80 [*]align(8) volatile u8, [*]align(8) const volatile u8,
81 [*]allowzero u8, [*]allowzero const u8,
82 [*]allowzero volatile u8, [*]allowzero const volatile u8,
83 [*]allowzero align(4) u8, [*]allowzero align(4) const u8,
84 [*]allowzero align(4) volatile u8, [*]allowzero align(4) const volatile u8,
85 // Slice Types
86 []u8, []const u8,
87 []volatile u8, []const volatile u8,
88 []align(4) u8, []align(4) const u8,
89 []align(4) volatile u8, []align(4) const volatile u8,
90 []align(8) u8, []align(8) const u8,
91 []align(8) volatile u8, []align(8) const volatile u8,
92 []allowzero u8, []allowzero const u8,
93 []allowzero volatile u8, []allowzero const volatile u8,
94 []allowzero align(4) u8, []allowzero align(4) const u8,
95 []allowzero align(4) volatile u8, []allowzero align(4) const volatile u8,
96 // C Pointer Types
97 [*c]u8, [*c]const u8,
98 [*c]volatile u8, [*c]const volatile u8,
99 [*c]align(4) u8, [*c]align(4) const u8,
100 [*c]align(4) volatile u8, [*c]align(4) const volatile u8,
101 [*c]align(8) u8, [*c]align(8) const u8,
102 [*c]align(8) volatile u8, [*c]align(8) const volatile u8,
103 });
104}
test/behavior/type_info.zig+23
...@@ -34,3 +34,26 @@ fn testOptional() !void {...@@ -34,3 +34,26 @@ fn testOptional() !void {
34 try expect(null_info == .Optional);34 try expect(null_info == .Optional);
35 try expect(null_info.Optional.child == void);35 try expect(null_info.Optional.child == void);
36}36}
37
38test "type info: C pointer type info" {
39 try testCPtr();
40 comptime try testCPtr();
41}
42
43fn testCPtr() !void {
44 const ptr_info = @typeInfo([*c]align(4) const i8);
45 try expect(ptr_info == .Pointer);
46 try expect(ptr_info.Pointer.size == .C);
47 try expect(ptr_info.Pointer.is_const);
48 try expect(!ptr_info.Pointer.is_volatile);
49 try expect(ptr_info.Pointer.alignment == 4);
50 try expect(ptr_info.Pointer.child == i8);
51}
52
53test "type info: value is correctly copied" {
54 comptime {
55 var ptrInfo = @typeInfo([]u32);
56 ptrInfo.Pointer.size = .One;
57 try expect(@typeInfo([]u32).Pointer.size == .Slice);
58 }
59}
test/behavior/type_info_stage1.zig+1-24
...@@ -68,21 +68,6 @@ fn testNullTerminatedPtr() !void {...@@ -68,21 +68,6 @@ fn testNullTerminatedPtr() !void {
68 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);68 try expect(@typeInfo([:0]u8).Pointer.sentinel != null);
69}69}
7070
71test "type info: C pointer type info" {
72 try testCPtr();
73 comptime try testCPtr();
74}
75
76fn testCPtr() !void {
77 const ptr_info = @typeInfo([*c]align(4) const i8);
78 try expect(ptr_info == .Pointer);
79 try expect(ptr_info.Pointer.size == .C);
80 try expect(ptr_info.Pointer.is_const);
81 try expect(!ptr_info.Pointer.is_volatile);
82 try expect(ptr_info.Pointer.alignment == 4);
83 try expect(ptr_info.Pointer.child == i8);
84}
85
86test "type info: slice type info" {71test "type info: slice type info" {
87 try testSlice();72 try testSlice();
88 comptime try testSlice();73 comptime try testSlice();
...@@ -395,7 +380,7 @@ test "@typeInfo does not force declarations into existence" {...@@ -395,7 +380,7 @@ test "@typeInfo does not force declarations into existence" {
395 comptime try expect(@typeInfo(S).Struct.fields.len == 1);380 comptime try expect(@typeInfo(S).Struct.fields.len == 1);
396}381}
397382
398test "defaut value for a var-typed field" {383test "default value for a var-typed field" {
399 const S = struct { x: anytype };384 const S = struct { x: anytype };
400 try expect(@typeInfo(S).Struct.fields[0].default_value == null);385 try expect(@typeInfo(S).Struct.fields[0].default_value == null);
401}386}
...@@ -413,14 +398,6 @@ test "type info for async frames" {...@@ -413,14 +398,6 @@ test "type info for async frames" {
413 }398 }
414}399}
415400
416test "type info: value is correctly copied" {
417 comptime {
418 var ptrInfo = @typeInfo([]u32);
419 ptrInfo.Pointer.size = .One;
420 try expect(@typeInfo([]u32).Pointer.size == .Slice);
421 }
422}
423
424test "Declarations are returned in declaration order" {401test "Declarations are returned in declaration order" {
425 const S = struct {402 const S = struct {
426 const a = 1;403 const a = 1;
test/behavior/type_stage1.zig+1-45
...@@ -17,51 +17,6 @@ test "Type.Float" {...@@ -17,51 +17,6 @@ test "Type.Float" {
17 try testTypes(&[_]type{ f16, f32, f64, f128 });17 try testTypes(&[_]type{ f16, f32, f64, f128 });
18}18}
1919
20test "Type.Pointer" {
21 try testTypes(&[_]type{
22 // One Value Pointer Types
23 *u8, *const u8,
24 *volatile u8, *const volatile u8,
25 *align(4) u8, *align(4) const u8,
26 *align(4) volatile u8, *align(4) const volatile u8,
27 *align(8) u8, *align(8) const u8,
28 *align(8) volatile u8, *align(8) const volatile u8,
29 *allowzero u8, *allowzero const u8,
30 *allowzero volatile u8, *allowzero const volatile u8,
31 *allowzero align(4) u8, *allowzero align(4) const u8,
32 *allowzero align(4) volatile u8, *allowzero align(4) const volatile u8,
33 // Many Values Pointer Types
34 [*]u8, [*]const u8,
35 [*]volatile u8, [*]const volatile u8,
36 [*]align(4) u8, [*]align(4) const u8,
37 [*]align(4) volatile u8, [*]align(4) const volatile u8,
38 [*]align(8) u8, [*]align(8) const u8,
39 [*]align(8) volatile u8, [*]align(8) const volatile u8,
40 [*]allowzero u8, [*]allowzero const u8,
41 [*]allowzero volatile u8, [*]allowzero const volatile u8,
42 [*]allowzero align(4) u8, [*]allowzero align(4) const u8,
43 [*]allowzero align(4) volatile u8, [*]allowzero align(4) const volatile u8,
44 // Slice Types
45 []u8, []const u8,
46 []volatile u8, []const volatile u8,
47 []align(4) u8, []align(4) const u8,
48 []align(4) volatile u8, []align(4) const volatile u8,
49 []align(8) u8, []align(8) const u8,
50 []align(8) volatile u8, []align(8) const volatile u8,
51 []allowzero u8, []allowzero const u8,
52 []allowzero volatile u8, []allowzero const volatile u8,
53 []allowzero align(4) u8, []allowzero align(4) const u8,
54 []allowzero align(4) volatile u8, []allowzero align(4) const volatile u8,
55 // C Pointer Types
56 [*c]u8, [*c]const u8,
57 [*c]volatile u8, [*c]const volatile u8,
58 [*c]align(4) u8, [*c]align(4) const u8,
59 [*c]align(4) volatile u8, [*c]align(4) const volatile u8,
60 [*c]align(8) u8, [*c]align(8) const u8,
61 [*c]align(8) volatile u8, [*c]align(8) const volatile u8,
62 });
63}
64
65test "Type.Array" {20test "Type.Array" {
66 try testing.expect([123]u8 == @Type(TypeInfo{21 try testing.expect([123]u8 == @Type(TypeInfo{
67 .Array = TypeInfo.Array{22 .Array = TypeInfo.Array{
...@@ -102,6 +57,7 @@ test "@Type create slice with null sentinel" {...@@ -102,6 +57,7 @@ test "@Type create slice with null sentinel" {
102 });57 });
103 try testing.expect(Slice == []align(8) const *i32);58 try testing.expect(Slice == []align(8) const *i32);
104}59}
60
105test "@Type picks up the sentinel value from TypeInfo" {61test "@Type picks up the sentinel value from TypeInfo" {
106 try testTypes(&[_]type{62 try testTypes(&[_]type{
107 [11:0]u8, [4:10]u8,63 [11:0]u8, [4:10]u8,