commit 397c9174cb8683ae894beafc97eac23e8aa5a760 (tree)
parent eb4028bf30bca7036c6bdc65feb321b163e84ecd
Author: Andrew Kelley <andrew@ziglang.org>
Date: Sat, 20 Jul 2024 01:05:59 -0700
fix std.fmt.hex
Diffstat:
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig
@@ -2722,7 +2722,7 @@ test "recursive format function" {
pub const hex_charset = "0123456789abcdef";
/// Converts an unsigned integer of any multiple of u8 to an array of lowercase
-/// hex bytes.
+/// hex bytes, little endian.
pub fn hex(x: anytype) [@sizeOf(@TypeOf(x)) * 2]u8 {
comptime assert(@typeInfo(@TypeOf(x)).Int.signedness == .unsigned);
var result: [@sizeOf(@TypeOf(x)) * 2]u8 = undefined;
@@ -2739,17 +2739,11 @@ test hex {
{
const x = hex(@as(u32, 0xdeadbeef));
try std.testing.expect(x.len == 8);
- switch (builtin.cpu.arch.endian()) {
- .little => try std.testing.expectEqualStrings("efbeadde", &x),
- .big => try std.testing.expectEqualStrings("deadbeef", &x),
- }
+ try std.testing.expectEqualStrings("efbeadde", &x);
}
{
const s = "[" ++ hex(@as(u64, 0x12345678_abcdef00)) ++ "]";
try std.testing.expect(s.len == 18);
- switch (builtin.cpu.arch.endian()) {
- .little => try std.testing.expectEqualStrings("[00efcdab78563412]", s),
- .big => try std.testing.expectEqualStrings("[12345678abcdef00]", s),
- }
+ try std.testing.expectEqualStrings("[00efcdab78563412]", s);
}
}