restructure unit test to be easier to debug

This commit is contained in:
Andrew Kelley 2024-05-01 22:20:26 -07:00
parent 08cecc1c7e
commit 126c9a34af

View File

@ -288,31 +288,29 @@ test "string set bad base error" {
}
test "twos complement limit set" {
const test_types = [_]type{
u64,
i64,
u1,
i1,
u0,
i0,
u65,
i65,
};
try testTwosComplementLimit(u64);
try testTwosComplementLimit(i64);
try testTwosComplementLimit(u1);
try testTwosComplementLimit(i1);
try testTwosComplementLimit(u0);
try testTwosComplementLimit(i0);
try testTwosComplementLimit(u65);
try testTwosComplementLimit(i65);
}
inline for (test_types) |T| {
const int_info = @typeInfo(T).Int;
fn testTwosComplementLimit(comptime T: type) !void {
const int_info = @typeInfo(T).Int;
var a = try Managed.init(testing.allocator);
defer a.deinit();
var a = try Managed.init(testing.allocator);
defer a.deinit();
try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);
const max: T = maxInt(T);
try testing.expect(max == try a.to(T));
try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);
const max: T = maxInt(T);
try testing.expect(max == try a.to(T));
try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);
const min: T = minInt(T);
try testing.expect(min == try a.to(T));
}
try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);
const min: T = minInt(T);
try testing.expect(min == try a.to(T));
}
test "string to" {