mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std.fmt: fix std-cases and perform round-trip check in ryu unit tests
This commit is contained in:
parent
2e60d4d064
commit
da4acf9a48
@ -784,6 +784,10 @@ fn formatFloatValue(
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
_ = &ryu128;
|
||||
}
|
||||
|
||||
pub const Case = enum { lower, upper };
|
||||
|
||||
fn formatSliceHexImpl(comptime case: Case) type {
|
||||
|
||||
@ -959,9 +959,23 @@ const POW5_INV_ERRORS: [154]u64 = .{
|
||||
// zig fmt: on
|
||||
|
||||
fn check(comptime T: type, value: T, comptime expected: []const u8) !void {
|
||||
const I = @Type(.{ .Int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });
|
||||
|
||||
var buf: [6000]u8 = undefined;
|
||||
const value_bits: I = @bitCast(value);
|
||||
const s = try format(&buf, value, .{});
|
||||
try std.testing.expectEqualStrings(expected, s);
|
||||
|
||||
if (@bitSizeOf(T) != 80) {
|
||||
const o = try std.fmt.parseFloat(T, s);
|
||||
const o_bits: I = @bitCast(o);
|
||||
|
||||
if (std.math.isNan(value)) {
|
||||
try std.testing.expect(std.math.isNan(o));
|
||||
} else {
|
||||
try std.testing.expectEqual(value_bits, o_bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "format f32" {
|
||||
|
||||
@ -2,7 +2,7 @@ const std = @import("std");
|
||||
|
||||
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
|
||||
_ = stack_trace;
|
||||
if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.20000004e+00, found 4.0e+00")) {
|
||||
if (std.mem.eql(u8, message, "sentinel mismatch: expected 1.2e0, found 4e0")) {
|
||||
std.process.exit(0);
|
||||
}
|
||||
std.process.exit(1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user