| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const std = @import("std"); |
| 3 | const assert = std.debug.assert; |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | |
| 5 | 6 | test "@abs integers" { |
| ... | ... | @@ -48,6 +49,33 @@ fn testAbsIntegers() !void { |
| 48 | 49 | } |
| 49 | 50 | } |
| 50 | 51 | |
| 52 | test "@abs signed C ABI integers" { |
| 53 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 54 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 55 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 56 | if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO |
| 57 | |
| 58 | const S = struct { |
| 59 | fn doTheTest() !void { |
| 60 | try testOne(isize, usize); |
| 61 | try testOne(c_short, c_ushort); |
| 62 | try testOne(c_int, c_uint); |
| 63 | try testOne(c_long, c_ulong); |
| 64 | if (!builtin.cpu.arch.isSpirV()) try testOne(c_longlong, c_ulonglong); |
| 65 | } |
| 66 | fn testOne(comptime Signed: type, comptime Unsigned: type) !void { |
| 67 | var negative_one: Signed = undefined; |
| 68 | negative_one = -1; |
| 69 | const one = @abs(negative_one); |
| 70 | comptime assert(@TypeOf(one) == Unsigned); |
| 71 | try expect(one == 1); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | try S.doTheTest(); |
| 76 | try comptime S.doTheTest(); |
| 77 | } |
| 78 | |
| 51 | 79 | test "@abs unsigned integers" { |
| 52 | 80 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 53 | 81 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| ... | ... | @@ -87,6 +115,32 @@ fn testAbsUnsignedIntegers() !void { |
| 87 | 115 | } |
| 88 | 116 | } |
| 89 | 117 | |
| 118 | test "@abs unsigned C ABI integers" { |
| 119 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 120 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 121 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 122 | |
| 123 | const S = struct { |
| 124 | fn doTheTest() !void { |
| 125 | try testOne(usize); |
| 126 | try testOne(c_ushort); |
| 127 | try testOne(c_uint); |
| 128 | try testOne(c_ulong); |
| 129 | if (!builtin.cpu.arch.isSpirV()) try testOne(c_ulonglong); |
| 130 | } |
| 131 | fn testOne(comptime Unsigned: type) !void { |
| 132 | var one: Unsigned = undefined; |
| 133 | one = 1; |
| 134 | const still_one = @abs(one); |
| 135 | comptime assert(@TypeOf(still_one) == Unsigned); |
| 136 | try expect(still_one == 1); |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | try S.doTheTest(); |
| 141 | try comptime S.doTheTest(); |
| 142 | } |
| 143 | |
| 90 | 144 | test "@abs big int <= 128 bits" { |
| 91 | 145 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 92 | 146 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |