| ... | ... | @@ -0,0 +1,43 @@ |
| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn FlippedInt(comptime T: type) type { |
| 6 | var info = @typeInfo(T); |
| 7 | info.Int.signedness = switch (info.Int.signedness) { |
| 8 | .signed => .unsigned, |
| 9 | .unsigned => .signed, |
| 10 | }; |
| 11 | return @Type(info); |
| 12 | } |
| 13 | |
| 14 | test { |
| 15 | try std.testing.expect(FlippedInt(u1) == i1); |
| 16 | } |
| 17 | test { |
| 18 | try std.testing.expect(FlippedInt(u2) == i2); |
| 19 | } |
| 20 | test { |
| 21 | try std.testing.expect(FlippedInt(u3) == i3); |
| 22 | } |
| 23 | test { |
| 24 | try std.testing.expect(FlippedInt(u4) == i4); |
| 25 | } |
| 26 | test { |
| 27 | try std.testing.expect(FlippedInt(u5) == i5); |
| 28 | } |
| 29 | test { |
| 30 | try std.testing.expect(FlippedInt(i1) == u0); |
| 31 | } |
| 32 | test { |
| 33 | try std.testing.expect(FlippedInt(i2) == u1); |
| 34 | } |
| 35 | test { |
| 36 | try std.testing.expect(FlippedInt(i3) == u2); |
| 37 | } |
| 38 | test { |
| 39 | try std.testing.expect(FlippedInt(i4) == u3); |
| 40 | } |
| 41 | test { |
| 42 | try std.testing.expect(FlippedInt(i5) == u4); |
| 43 | } |