| ... | ... | @@ -13,7 +13,7 @@ test "type info: tag type, void info" { |
| 13 | 13 | fn testBasic() void { |
| 14 | 14 | expect(@TagType(TypeInfo) == TypeId); |
| 15 | 15 | const void_info = @typeInfo(void); |
| 16 | | expect(@as(TypeId, void_info) == TypeId.Void); |
| 16 | expect(void_info == TypeId.Void); |
| 17 | 17 | expect(void_info.Void == {}); |
| 18 | 18 | } |
| 19 | 19 | |
| ... | ... | @@ -24,12 +24,12 @@ test "type info: integer, floating point type info" { |
| 24 | 24 | |
| 25 | 25 | fn testIntFloat() void { |
| 26 | 26 | const u8_info = @typeInfo(u8); |
| 27 | | expect(@as(TypeId, u8_info) == TypeId.Int); |
| 27 | expect(u8_info == .Int); |
| 28 | 28 | expect(!u8_info.Int.is_signed); |
| 29 | 29 | expect(u8_info.Int.bits == 8); |
| 30 | 30 | |
| 31 | 31 | const f64_info = @typeInfo(f64); |
| 32 | | expect(@as(TypeId, f64_info) == TypeId.Float); |
| 32 | expect(f64_info == .Float); |
| 33 | 33 | expect(f64_info.Float.bits == 64); |
| 34 | 34 | } |
| 35 | 35 | |
| ... | ... | @@ -40,7 +40,7 @@ test "type info: pointer type info" { |
| 40 | 40 | |
| 41 | 41 | fn testPointer() void { |
| 42 | 42 | const u32_ptr_info = @typeInfo(*u32); |
| 43 | | expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer); |
| 43 | expect(u32_ptr_info == .Pointer); |
| 44 | 44 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.One); |
| 45 | 45 | expect(u32_ptr_info.Pointer.is_const == false); |
| 46 | 46 | expect(u32_ptr_info.Pointer.is_volatile == false); |
| ... | ... | @@ -56,7 +56,7 @@ test "type info: unknown length pointer type info" { |
| 56 | 56 | |
| 57 | 57 | fn testUnknownLenPtr() void { |
| 58 | 58 | const u32_ptr_info = @typeInfo([*]const volatile f64); |
| 59 | | expect(@as(TypeId, u32_ptr_info) == TypeId.Pointer); |
| 59 | expect(u32_ptr_info == .Pointer); |
| 60 | 60 | expect(u32_ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); |
| 61 | 61 | expect(u32_ptr_info.Pointer.is_const == true); |
| 62 | 62 | expect(u32_ptr_info.Pointer.is_volatile == true); |
| ... | ... | @@ -72,7 +72,7 @@ test "type info: null terminated pointer type info" { |
| 72 | 72 | |
| 73 | 73 | fn testNullTerminatedPtr() void { |
| 74 | 74 | const ptr_info = @typeInfo([*:0]u8); |
| 75 | | expect(@as(TypeId, ptr_info) == TypeId.Pointer); |
| 75 | expect(ptr_info == .Pointer); |
| 76 | 76 | expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.Many); |
| 77 | 77 | expect(ptr_info.Pointer.is_const == false); |
| 78 | 78 | expect(ptr_info.Pointer.is_volatile == false); |
| ... | ... | @@ -91,8 +91,8 @@ test "type info: C pointer type info" { |
| 91 | 91 | |
| 92 | 92 | fn testCPtr() void { |
| 93 | 93 | const ptr_info = @typeInfo([*c]align(4) const i8); |
| 94 | | expect(@as(TypeId, ptr_info) == TypeId.Pointer); |
| 95 | | expect(ptr_info.Pointer.size == TypeInfo.Pointer.Size.C); |
| 94 | expect(ptr_info == .Pointer); |
| 95 | expect(ptr_info.Pointer.size == .C); |
| 96 | 96 | expect(ptr_info.Pointer.is_const); |
| 97 | 97 | expect(!ptr_info.Pointer.is_volatile); |
| 98 | 98 | expect(ptr_info.Pointer.alignment == 4); |
| ... | ... | @@ -106,8 +106,8 @@ test "type info: slice type info" { |
| 106 | 106 | |
| 107 | 107 | fn testSlice() void { |
| 108 | 108 | const u32_slice_info = @typeInfo([]u32); |
| 109 | | expect(@as(TypeId, u32_slice_info) == TypeId.Pointer); |
| 110 | | expect(u32_slice_info.Pointer.size == TypeInfo.Pointer.Size.Slice); |
| 109 | expect(u32_slice_info == .Pointer); |
| 110 | expect(u32_slice_info.Pointer.size == .Slice); |
| 111 | 111 | expect(u32_slice_info.Pointer.is_const == false); |
| 112 | 112 | expect(u32_slice_info.Pointer.is_volatile == false); |
| 113 | 113 | expect(u32_slice_info.Pointer.alignment == 4); |
| ... | ... | @@ -121,7 +121,7 @@ test "type info: array type info" { |
| 121 | 121 | |
| 122 | 122 | fn testArray() void { |
| 123 | 123 | const arr_info = @typeInfo([42]bool); |
| 124 | | expect(@as(TypeId, arr_info) == TypeId.Array); |
| 124 | expect(arr_info == .Array); |
| 125 | 125 | expect(arr_info.Array.len == 42); |
| 126 | 126 | expect(arr_info.Array.child == bool); |
| 127 | 127 | } |
| ... | ... | @@ -133,7 +133,7 @@ test "type info: optional type info" { |
| 133 | 133 | |
| 134 | 134 | fn testOptional() void { |
| 135 | 135 | const null_info = @typeInfo(?void); |
| 136 | | expect(@as(TypeId, null_info) == TypeId.Optional); |
| 136 | expect(null_info == .Optional); |
| 137 | 137 | expect(null_info.Optional.child == void); |
| 138 | 138 | } |
| 139 | 139 | |
| ... | ... | @@ -150,18 +150,18 @@ fn testErrorSet() void { |
| 150 | 150 | }; |
| 151 | 151 | |
| 152 | 152 | const error_set_info = @typeInfo(TestErrorSet); |
| 153 | | expect(@as(TypeId, error_set_info) == TypeId.ErrorSet); |
| 153 | expect(error_set_info == .ErrorSet); |
| 154 | 154 | expect(error_set_info.ErrorSet.?.len == 3); |
| 155 | 155 | expect(mem.eql(u8, error_set_info.ErrorSet.?[0].name, "First")); |
| 156 | 156 | expect(error_set_info.ErrorSet.?[2].value == @errorToInt(TestErrorSet.Third)); |
| 157 | 157 | |
| 158 | 158 | const error_union_info = @typeInfo(TestErrorSet!usize); |
| 159 | | expect(@as(TypeId, error_union_info) == TypeId.ErrorUnion); |
| 159 | expect(error_union_info == .ErrorUnion); |
| 160 | 160 | expect(error_union_info.ErrorUnion.error_set == TestErrorSet); |
| 161 | 161 | expect(error_union_info.ErrorUnion.payload == usize); |
| 162 | 162 | |
| 163 | 163 | const global_info = @typeInfo(anyerror); |
| 164 | | expect(@as(TypeId, global_info) == TypeId.ErrorSet); |
| 164 | expect(global_info == .ErrorSet); |
| 165 | 165 | expect(global_info.ErrorSet == null); |
| 166 | 166 | } |
| 167 | 167 | |
| ... | ... | @@ -179,8 +179,8 @@ fn testEnum() void { |
| 179 | 179 | }; |
| 180 | 180 | |
| 181 | 181 | const os_info = @typeInfo(Os); |
| 182 | | expect(@as(TypeId, os_info) == TypeId.Enum); |
| 183 | | expect(os_info.Enum.layout == TypeInfo.ContainerLayout.Auto); |
| 182 | expect(os_info == .Enum); |
| 183 | expect(os_info.Enum.layout == .Auto); |
| 184 | 184 | expect(os_info.Enum.fields.len == 4); |
| 185 | 185 | expect(mem.eql(u8, os_info.Enum.fields[1].name, "Macos")); |
| 186 | 186 | expect(os_info.Enum.fields[3].value == 3); |
| ... | ... | @@ -195,8 +195,8 @@ test "type info: union info" { |
| 195 | 195 | |
| 196 | 196 | fn testUnion() void { |
| 197 | 197 | const typeinfo_info = @typeInfo(TypeInfo); |
| 198 | | expect(@as(TypeId, typeinfo_info) == TypeId.Union); |
| 199 | | expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); |
| 198 | expect(typeinfo_info == .Union); |
| 199 | expect(typeinfo_info.Union.layout == .Auto); |
| 200 | 200 | expect(typeinfo_info.Union.tag_type.? == TypeId); |
| 201 | 201 | expect(typeinfo_info.Union.fields.len == 25); |
| 202 | 202 | expect(typeinfo_info.Union.fields[4].enum_field != null); |
| ... | ... | @@ -210,9 +210,9 @@ fn testUnion() void { |
| 210 | 210 | }; |
| 211 | 211 | |
| 212 | 212 | const notag_union_info = @typeInfo(TestNoTagUnion); |
| 213 | | expect(@as(TypeId, notag_union_info) == TypeId.Union); |
| 213 | expect(notag_union_info == .Union); |
| 214 | 214 | expect(notag_union_info.Union.tag_type == null); |
| 215 | | expect(notag_union_info.Union.layout == TypeInfo.ContainerLayout.Auto); |
| 215 | expect(notag_union_info.Union.layout == .Auto); |
| 216 | 216 | expect(notag_union_info.Union.fields.len == 2); |
| 217 | 217 | expect(notag_union_info.Union.fields[0].enum_field == null); |
| 218 | 218 | expect(notag_union_info.Union.fields[1].field_type == u32); |
| ... | ... | @@ -222,7 +222,7 @@ fn testUnion() void { |
| 222 | 222 | }; |
| 223 | 223 | |
| 224 | 224 | const extern_union_info = @typeInfo(TestExternUnion); |
| 225 | | expect(extern_union_info.Union.layout == TypeInfo.ContainerLayout.Extern); |
| 225 | expect(extern_union_info.Union.layout == .Extern); |
| 226 | 226 | expect(extern_union_info.Union.tag_type == null); |
| 227 | 227 | expect(extern_union_info.Union.fields[0].enum_field == null); |
| 228 | 228 | expect(extern_union_info.Union.fields[0].field_type == *c_void); |
| ... | ... | @@ -235,8 +235,8 @@ test "type info: struct info" { |
| 235 | 235 | |
| 236 | 236 | fn testStruct() void { |
| 237 | 237 | const struct_info = @typeInfo(TestStruct); |
| 238 | | expect(@as(TypeId, struct_info) == TypeId.Struct); |
| 239 | | expect(struct_info.Struct.layout == TypeInfo.ContainerLayout.Packed); |
| 238 | expect(struct_info == .Struct); |
| 239 | expect(struct_info.Struct.layout == .Packed); |
| 240 | 240 | expect(struct_info.Struct.fields.len == 4); |
| 241 | 241 | expect(struct_info.Struct.fields[1].offset == null); |
| 242 | 242 | expect(struct_info.Struct.fields[2].field_type == *TestStruct); |
| ... | ... | @@ -268,22 +268,20 @@ test "type info: function type info" { |
| 268 | 268 | |
| 269 | 269 | fn testFunction() void { |
| 270 | 270 | const fn_info = @typeInfo(@TypeOf(foo)); |
| 271 | | expect(@as(TypeId, fn_info) == TypeId.Fn); |
| 272 | | expect(fn_info.Fn.calling_convention == .Unspecified); |
| 273 | | expect(fn_info.Fn.is_generic); |
| 271 | expect(fn_info == .Fn); |
| 272 | expect(fn_info.Fn.calling_convention == .C); |
| 273 | expect(!fn_info.Fn.is_generic); |
| 274 | 274 | expect(fn_info.Fn.args.len == 2); |
| 275 | 275 | expect(fn_info.Fn.is_var_args); |
| 276 | | expect(fn_info.Fn.return_type == null); |
| 276 | expect(fn_info.Fn.return_type.? == usize); |
| 277 | 277 | |
| 278 | 278 | const test_instance: TestStruct = undefined; |
| 279 | 279 | const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo)); |
| 280 | | expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn); |
| 280 | expect(bound_fn_info == .BoundFn); |
| 281 | 281 | expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | | fn foo(comptime a: usize, b: bool, args: ...) usize { |
| 285 | | return 0; |
| 286 | | } |
| 284 | extern fn foo(a: usize, b: bool, args: ...) usize; |
| 287 | 285 | |
| 288 | 286 | test "typeInfo with comptime parameter in struct fn def" { |
| 289 | 287 | const S = struct { |
| ... | ... | @@ -299,7 +297,7 @@ test "type info: vectors" { |
| 299 | 297 | |
| 300 | 298 | fn testVector() void { |
| 301 | 299 | const vec_info = @typeInfo(@Vector(4, i32)); |
| 302 | | expect(@as(TypeId, vec_info) == TypeId.Vector); |
| 300 | expect(vec_info == .Vector); |
| 303 | 301 | expect(vec_info.Vector.len == 4); |
| 304 | 302 | expect(vec_info.Vector.child == i32); |
| 305 | 303 | } |
| ... | ... | @@ -312,13 +310,13 @@ test "type info: anyframe and anyframe->T" { |
| 312 | 310 | fn testAnyFrame() void { |
| 313 | 311 | { |
| 314 | 312 | const anyframe_info = @typeInfo(anyframe->i32); |
| 315 | | expect(@as(TypeId, anyframe_info) == .AnyFrame); |
| 313 | expect(anyframe_info == .AnyFrame); |
| 316 | 314 | expect(anyframe_info.AnyFrame.child.? == i32); |
| 317 | 315 | } |
| 318 | 316 | |
| 319 | 317 | { |
| 320 | 318 | const anyframe_info = @typeInfo(anyframe); |
| 321 | | expect(@as(TypeId, anyframe_info) == .AnyFrame); |
| 319 | expect(anyframe_info == .AnyFrame); |
| 322 | 320 | expect(anyframe_info.AnyFrame.child == null); |
| 323 | 321 | } |
| 324 | 322 | } |