| ... | ... | @@ -18,7 +18,7 @@ pub fn multiTrait(comptime traits: anytype) TraitFn { |
| 18 | 18 | return Closure.trait; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | | test "std.meta.trait.multiTrait" { |
| 21 | test "multiTrait" { |
| 22 | 22 | const Vector2 = struct { |
| 23 | 23 | const MyType = @This(); |
| 24 | 24 | |
| ... | ... | @@ -54,7 +54,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn { |
| 54 | 54 | return Closure.trait; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | | test "std.meta.trait.hasFn" { |
| 57 | test "hasFn" { |
| 58 | 58 | const TestStruct = struct { |
| 59 | 59 | pub fn useless() void {} |
| 60 | 60 | }; |
| ... | ... | @@ -84,7 +84,7 @@ pub fn hasField(comptime name: []const u8) TraitFn { |
| 84 | 84 | return Closure.trait; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | | test "std.meta.trait.hasField" { |
| 87 | test "hasField" { |
| 88 | 88 | const TestStruct = struct { |
| 89 | 89 | value: u32, |
| 90 | 90 | }; |
| ... | ... | @@ -105,7 +105,7 @@ pub fn is(comptime id: std.builtin.TypeId) TraitFn { |
| 105 | 105 | return Closure.trait; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | | test "std.meta.trait.is" { |
| 108 | test "is" { |
| 109 | 109 | try testing.expect(is(.Int)(u8)); |
| 110 | 110 | try testing.expect(!is(.Int)(f32)); |
| 111 | 111 | try testing.expect(is(.Pointer)(*u8)); |
| ... | ... | @@ -123,7 +123,7 @@ pub fn isPtrTo(comptime id: std.builtin.TypeId) TraitFn { |
| 123 | 123 | return Closure.trait; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | | test "std.meta.trait.isPtrTo" { |
| 126 | test "isPtrTo" { |
| 127 | 127 | try testing.expect(!isPtrTo(.Struct)(struct {})); |
| 128 | 128 | try testing.expect(isPtrTo(.Struct)(*struct {})); |
| 129 | 129 | try testing.expect(!isPtrTo(.Struct)(**struct {})); |
| ... | ... | @@ -139,7 +139,7 @@ pub fn isSliceOf(comptime id: std.builtin.TypeId) TraitFn { |
| 139 | 139 | return Closure.trait; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | | test "std.meta.trait.isSliceOf" { |
| 142 | test "isSliceOf" { |
| 143 | 143 | try testing.expect(!isSliceOf(.Struct)(struct {})); |
| 144 | 144 | try testing.expect(isSliceOf(.Struct)([]struct {})); |
| 145 | 145 | try testing.expect(!isSliceOf(.Struct)([][]struct {})); |
| ... | ... | @@ -159,7 +159,7 @@ pub fn isExtern(comptime T: type) bool { |
| 159 | 159 | }; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | | test "std.meta.trait.isExtern" { |
| 162 | test "isExtern" { |
| 163 | 163 | const TestExStruct = extern struct {}; |
| 164 | 164 | const TestStruct = struct {}; |
| 165 | 165 | |
| ... | ... | @@ -177,7 +177,7 @@ pub fn isPacked(comptime T: type) bool { |
| 177 | 177 | }; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | | test "std.meta.trait.isPacked" { |
| 180 | test "isPacked" { |
| 181 | 181 | const TestPStruct = packed struct {}; |
| 182 | 182 | const TestStruct = struct {}; |
| 183 | 183 | |
| ... | ... | @@ -222,7 +222,7 @@ pub fn isSingleItemPtr(comptime T: type) bool { |
| 222 | 222 | return false; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | | test "std.meta.trait.isSingleItemPtr" { |
| 225 | test "isSingleItemPtr" { |
| 226 | 226 | const array = [_]u8{0} ** 10; |
| 227 | 227 | comptime try testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); |
| 228 | 228 | comptime try testing.expect(!isSingleItemPtr(@TypeOf(array))); |
| ... | ... | @@ -237,7 +237,7 @@ pub fn isManyItemPtr(comptime T: type) bool { |
| 237 | 237 | return false; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | | test "std.meta.trait.isManyItemPtr" { |
| 240 | test "isManyItemPtr" { |
| 241 | 241 | const array = [_]u8{0} ** 10; |
| 242 | 242 | const mip = @ptrCast([*]const u8, &array[0]); |
| 243 | 243 | try testing.expect(isManyItemPtr(@TypeOf(mip))); |
| ... | ... | @@ -252,7 +252,7 @@ pub fn isSlice(comptime T: type) bool { |
| 252 | 252 | return false; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | | test "std.meta.trait.isSlice" { |
| 255 | test "isSlice" { |
| 256 | 256 | const array = [_]u8{0} ** 10; |
| 257 | 257 | var runtime_zero: usize = 0; |
| 258 | 258 | try testing.expect(isSlice(@TypeOf(array[runtime_zero..]))); |
| ... | ... | @@ -270,7 +270,7 @@ pub fn isIndexable(comptime T: type) bool { |
| 270 | 270 | return comptime is(.Array)(T) or is(.Vector)(T) or isTuple(T); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | | test "std.meta.trait.isIndexable" { |
| 273 | test "isIndexable" { |
| 274 | 274 | const array = [_]u8{0} ** 10; |
| 275 | 275 | const slice = @as([]const u8, &array); |
| 276 | 276 | const vector: meta.Vector(2, u32) = [_]u32{0} ** 2; |
| ... | ... | @@ -291,7 +291,7 @@ pub fn isNumber(comptime T: type) bool { |
| 291 | 291 | }; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | | test "std.meta.trait.isNumber" { |
| 294 | test "isNumber" { |
| 295 | 295 | const NotANumber = struct { |
| 296 | 296 | number: u8, |
| 297 | 297 | }; |
| ... | ... | @@ -342,7 +342,7 @@ pub fn isConstPtr(comptime T: type) bool { |
| 342 | 342 | return @typeInfo(T).Pointer.is_const; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | | test "std.meta.trait.isConstPtr" { |
| 345 | test "isConstPtr" { |
| 346 | 346 | var t = @as(u8, 0); |
| 347 | 347 | const c = @as(u8, 0); |
| 348 | 348 | try testing.expect(isConstPtr(*const @TypeOf(t))); |
| ... | ... | @@ -358,7 +358,7 @@ pub fn isContainer(comptime T: type) bool { |
| 358 | 358 | }; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | | test "std.meta.trait.isContainer" { |
| 361 | test "isContainer" { |
| 362 | 362 | const TestStruct = struct {}; |
| 363 | 363 | const TestUnion = union { |
| 364 | 364 | a: void, |
| ... | ... | @@ -380,7 +380,7 @@ pub fn isTuple(comptime T: type) bool { |
| 380 | 380 | return is(.Struct)(T) and @typeInfo(T).Struct.is_tuple; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | | test "std.meta.trait.isTuple" { |
| 383 | test "isTuple" { |
| 384 | 384 | const t1 = struct {}; |
| 385 | 385 | const t2 = .{ .a = 0 }; |
| 386 | 386 | const t3 = .{ 1, 2, 3 }; |
| ... | ... | @@ -429,7 +429,7 @@ pub fn isZigString(comptime T: type) bool { |
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | | test "std.meta.trait.isZigString" { |
| 432 | test "isZigString" { |
| 433 | 433 | try testing.expect(isZigString([]const u8)); |
| 434 | 434 | try testing.expect(isZigString([]u8)); |
| 435 | 435 | try testing.expect(isZigString([:0]const u8)); |
| ... | ... | @@ -475,7 +475,7 @@ pub fn hasDecls(comptime T: type, comptime names: anytype) bool { |
| 475 | 475 | return true; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | | test "std.meta.trait.hasDecls" { |
| 478 | test "hasDecls" { |
| 479 | 479 | const TestStruct1 = struct {}; |
| 480 | 480 | const TestStruct2 = struct { |
| 481 | 481 | pub var a: u32 = undefined; |
| ... | ... | @@ -501,7 +501,7 @@ pub fn hasFields(comptime T: type, comptime names: anytype) bool { |
| 501 | 501 | return true; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | | test "std.meta.trait.hasFields" { |
| 504 | test "hasFields" { |
| 505 | 505 | const TestStruct1 = struct {}; |
| 506 | 506 | const TestStruct2 = struct { |
| 507 | 507 | a: u32, |
| ... | ... | @@ -527,7 +527,7 @@ pub fn hasFunctions(comptime T: type, comptime names: anytype) bool { |
| 527 | 527 | return true; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | | test "std.meta.trait.hasFunctions" { |
| 530 | test "hasFunctions" { |
| 531 | 531 | const TestStruct1 = struct {}; |
| 532 | 532 | const TestStruct2 = struct { |
| 533 | 533 | pub fn a() void {} |
| ... | ... | @@ -557,9 +557,7 @@ pub fn hasUniqueRepresentation(comptime T: type) bool { |
| 557 | 557 | |
| 558 | 558 | .Bool => return false, |
| 559 | 559 | |
| 560 | | // The padding bits are undefined. |
| 561 | | .Int => |info| return (info.bits % 8) == 0 and |
| 562 | | (info.bits == 0 or std.math.isPowerOfTwo(info.bits)), |
| 560 | .Int => |info| return @sizeOf(T) * 8 == info.bits, |
| 563 | 561 | |
| 564 | 562 | .Pointer => |info| return info.size != .Slice, |
| 565 | 563 | |
| ... | ... | @@ -577,11 +575,12 @@ pub fn hasUniqueRepresentation(comptime T: type) bool { |
| 577 | 575 | return @sizeOf(T) == sum_size; |
| 578 | 576 | }, |
| 579 | 577 | |
| 580 | | .Vector => |info| return comptime hasUniqueRepresentation(info.child) and @sizeOf(T) == @sizeOf(info.child) * info.len, |
| 578 | .Vector => |info| return comptime hasUniqueRepresentation(info.child) and |
| 579 | @sizeOf(T) == @sizeOf(info.child) * info.len, |
| 581 | 580 | } |
| 582 | 581 | } |
| 583 | 582 | |
| 584 | | test "std.meta.trait.hasUniqueRepresentation" { |
| 583 | test "hasUniqueRepresentation" { |
| 585 | 584 | const TestStruct1 = struct { |
| 586 | 585 | a: u32, |
| 587 | 586 | b: u32, |
| ... | ... | @@ -650,5 +649,4 @@ test "std.meta.trait.hasUniqueRepresentation" { |
| 650 | 649 | try testing.expect(!hasUniqueRepresentation([]const u8)); |
| 651 | 650 | |
| 652 | 651 | try testing.expect(hasUniqueRepresentation(@Vector(4, u16))); |
| 653 | | try testing.expect(!hasUniqueRepresentation(@Vector(3, u16))); |
| 654 | 652 | } |