stage2: move some more tests
This commit is contained in:
@@ -57,3 +57,48 @@ test "Type.EnumLiteral" {
|
||||
@TypeOf(.Dummy),
|
||||
});
|
||||
}
|
||||
|
||||
test "Type.Pointer" {
|
||||
try testTypes(&[_]type{
|
||||
// One Value Pointer Types
|
||||
*u8, *const u8,
|
||||
*volatile u8, *const volatile u8,
|
||||
*align(4) u8, *align(4) const u8,
|
||||
*align(4) volatile u8, *align(4) const volatile u8,
|
||||
*align(8) u8, *align(8) const u8,
|
||||
*align(8) volatile u8, *align(8) const volatile u8,
|
||||
*allowzero u8, *allowzero const u8,
|
||||
*allowzero volatile u8, *allowzero const volatile u8,
|
||||
*allowzero align(4) u8, *allowzero align(4) const u8,
|
||||
*allowzero align(4) volatile u8, *allowzero align(4) const volatile u8,
|
||||
// Many Values Pointer Types
|
||||
[*]u8, [*]const u8,
|
||||
[*]volatile u8, [*]const volatile u8,
|
||||
[*]align(4) u8, [*]align(4) const u8,
|
||||
[*]align(4) volatile u8, [*]align(4) const volatile u8,
|
||||
[*]align(8) u8, [*]align(8) const u8,
|
||||
[*]align(8) volatile u8, [*]align(8) const volatile u8,
|
||||
[*]allowzero u8, [*]allowzero const u8,
|
||||
[*]allowzero volatile u8, [*]allowzero const volatile u8,
|
||||
[*]allowzero align(4) u8, [*]allowzero align(4) const u8,
|
||||
[*]allowzero align(4) volatile u8, [*]allowzero align(4) const volatile u8,
|
||||
// Slice Types
|
||||
[]u8, []const u8,
|
||||
[]volatile u8, []const volatile u8,
|
||||
[]align(4) u8, []align(4) const u8,
|
||||
[]align(4) volatile u8, []align(4) const volatile u8,
|
||||
[]align(8) u8, []align(8) const u8,
|
||||
[]align(8) volatile u8, []align(8) const volatile u8,
|
||||
[]allowzero u8, []allowzero const u8,
|
||||
[]allowzero volatile u8, []allowzero const volatile u8,
|
||||
[]allowzero align(4) u8, []allowzero align(4) const u8,
|
||||
[]allowzero align(4) volatile u8, []allowzero align(4) const volatile u8,
|
||||
// C Pointer Types
|
||||
[*c]u8, [*c]const u8,
|
||||
[*c]volatile u8, [*c]const volatile u8,
|
||||
[*c]align(4) u8, [*c]align(4) const u8,
|
||||
[*c]align(4) volatile u8, [*c]align(4) const volatile u8,
|
||||
[*c]align(8) u8, [*c]align(8) const u8,
|
||||
[*c]align(8) volatile u8, [*c]align(8) const volatile u8,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -34,3 +34,26 @@ fn testOptional() !void {
|
||||
try expect(null_info == .Optional);
|
||||
try expect(null_info.Optional.child == void);
|
||||
}
|
||||
|
||||
test "type info: C pointer type info" {
|
||||
try testCPtr();
|
||||
comptime try testCPtr();
|
||||
}
|
||||
|
||||
fn testCPtr() !void {
|
||||
const ptr_info = @typeInfo([*c]align(4) const i8);
|
||||
try expect(ptr_info == .Pointer);
|
||||
try expect(ptr_info.Pointer.size == .C);
|
||||
try expect(ptr_info.Pointer.is_const);
|
||||
try expect(!ptr_info.Pointer.is_volatile);
|
||||
try expect(ptr_info.Pointer.alignment == 4);
|
||||
try expect(ptr_info.Pointer.child == i8);
|
||||
}
|
||||
|
||||
test "type info: value is correctly copied" {
|
||||
comptime {
|
||||
var ptrInfo = @typeInfo([]u32);
|
||||
ptrInfo.Pointer.size = .One;
|
||||
try expect(@typeInfo([]u32).Pointer.size == .Slice);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,21 +68,6 @@ fn testNullTerminatedPtr() !void {
|
||||
try expect(@typeInfo([:0]u8).Pointer.sentinel != null);
|
||||
}
|
||||
|
||||
test "type info: C pointer type info" {
|
||||
try testCPtr();
|
||||
comptime try testCPtr();
|
||||
}
|
||||
|
||||
fn testCPtr() !void {
|
||||
const ptr_info = @typeInfo([*c]align(4) const i8);
|
||||
try expect(ptr_info == .Pointer);
|
||||
try expect(ptr_info.Pointer.size == .C);
|
||||
try expect(ptr_info.Pointer.is_const);
|
||||
try expect(!ptr_info.Pointer.is_volatile);
|
||||
try expect(ptr_info.Pointer.alignment == 4);
|
||||
try expect(ptr_info.Pointer.child == i8);
|
||||
}
|
||||
|
||||
test "type info: slice type info" {
|
||||
try testSlice();
|
||||
comptime try testSlice();
|
||||
@@ -395,7 +380,7 @@ test "@typeInfo does not force declarations into existence" {
|
||||
comptime try expect(@typeInfo(S).Struct.fields.len == 1);
|
||||
}
|
||||
|
||||
test "defaut value for a var-typed field" {
|
||||
test "default value for a var-typed field" {
|
||||
const S = struct { x: anytype };
|
||||
try expect(@typeInfo(S).Struct.fields[0].default_value == null);
|
||||
}
|
||||
@@ -413,14 +398,6 @@ test "type info for async frames" {
|
||||
}
|
||||
}
|
||||
|
||||
test "type info: value is correctly copied" {
|
||||
comptime {
|
||||
var ptrInfo = @typeInfo([]u32);
|
||||
ptrInfo.Pointer.size = .One;
|
||||
try expect(@typeInfo([]u32).Pointer.size == .Slice);
|
||||
}
|
||||
}
|
||||
|
||||
test "Declarations are returned in declaration order" {
|
||||
const S = struct {
|
||||
const a = 1;
|
||||
|
||||
@@ -17,51 +17,6 @@ test "Type.Float" {
|
||||
try testTypes(&[_]type{ f16, f32, f64, f128 });
|
||||
}
|
||||
|
||||
test "Type.Pointer" {
|
||||
try testTypes(&[_]type{
|
||||
// One Value Pointer Types
|
||||
*u8, *const u8,
|
||||
*volatile u8, *const volatile u8,
|
||||
*align(4) u8, *align(4) const u8,
|
||||
*align(4) volatile u8, *align(4) const volatile u8,
|
||||
*align(8) u8, *align(8) const u8,
|
||||
*align(8) volatile u8, *align(8) const volatile u8,
|
||||
*allowzero u8, *allowzero const u8,
|
||||
*allowzero volatile u8, *allowzero const volatile u8,
|
||||
*allowzero align(4) u8, *allowzero align(4) const u8,
|
||||
*allowzero align(4) volatile u8, *allowzero align(4) const volatile u8,
|
||||
// Many Values Pointer Types
|
||||
[*]u8, [*]const u8,
|
||||
[*]volatile u8, [*]const volatile u8,
|
||||
[*]align(4) u8, [*]align(4) const u8,
|
||||
[*]align(4) volatile u8, [*]align(4) const volatile u8,
|
||||
[*]align(8) u8, [*]align(8) const u8,
|
||||
[*]align(8) volatile u8, [*]align(8) const volatile u8,
|
||||
[*]allowzero u8, [*]allowzero const u8,
|
||||
[*]allowzero volatile u8, [*]allowzero const volatile u8,
|
||||
[*]allowzero align(4) u8, [*]allowzero align(4) const u8,
|
||||
[*]allowzero align(4) volatile u8, [*]allowzero align(4) const volatile u8,
|
||||
// Slice Types
|
||||
[]u8, []const u8,
|
||||
[]volatile u8, []const volatile u8,
|
||||
[]align(4) u8, []align(4) const u8,
|
||||
[]align(4) volatile u8, []align(4) const volatile u8,
|
||||
[]align(8) u8, []align(8) const u8,
|
||||
[]align(8) volatile u8, []align(8) const volatile u8,
|
||||
[]allowzero u8, []allowzero const u8,
|
||||
[]allowzero volatile u8, []allowzero const volatile u8,
|
||||
[]allowzero align(4) u8, []allowzero align(4) const u8,
|
||||
[]allowzero align(4) volatile u8, []allowzero align(4) const volatile u8,
|
||||
// C Pointer Types
|
||||
[*c]u8, [*c]const u8,
|
||||
[*c]volatile u8, [*c]const volatile u8,
|
||||
[*c]align(4) u8, [*c]align(4) const u8,
|
||||
[*c]align(4) volatile u8, [*c]align(4) const volatile u8,
|
||||
[*c]align(8) u8, [*c]align(8) const u8,
|
||||
[*c]align(8) volatile u8, [*c]align(8) const volatile u8,
|
||||
});
|
||||
}
|
||||
|
||||
test "Type.Array" {
|
||||
try testing.expect([123]u8 == @Type(TypeInfo{
|
||||
.Array = TypeInfo.Array{
|
||||
@@ -102,6 +57,7 @@ test "@Type create slice with null sentinel" {
|
||||
});
|
||||
try testing.expect(Slice == []align(8) const *i32);
|
||||
}
|
||||
|
||||
test "@Type picks up the sentinel value from TypeInfo" {
|
||||
try testTypes(&[_]type{
|
||||
[11:0]u8, [4:10]u8,
|
||||
|
||||
Reference in New Issue
Block a user