Add tests for Uuid
This commit is contained in:
parent
5353169250
commit
d82d271a7f
1 changed files with 38 additions and 0 deletions
38
src/util.zig
38
src/util.zig
|
@ -88,6 +88,44 @@ pub const Uuid = struct {
|
|||
}
|
||||
};
|
||||
|
||||
test "parse uuid" {
|
||||
try std.testing.expectEqual(
|
||||
Uuid.Nil,
|
||||
try Uuid.parse("00000000-0000-0000-0000-000000000000"),
|
||||
);
|
||||
|
||||
try std.testing.expectEqual(
|
||||
Uuid{
|
||||
.data = @bitCast([16]u8, @as(u128, 0x4ba7b74522ad_1da8_c242_d312_60515ff7)),
|
||||
},
|
||||
try Uuid.parse("f75f5160-12d3-42c2-a81d-ad2245b7a74b"),
|
||||
);
|
||||
}
|
||||
|
||||
test "format uuid" {
|
||||
var buf = [1]u8{0} ** 36;
|
||||
var fbs = std.io.fixedBufferStream(&buf);
|
||||
try Uuid.format(Uuid.Nil, "", .{}, fbs.writer());
|
||||
try std.testing.expectEqualStrings("00000000-0000-0000-0000-000000000000", &buf);
|
||||
|
||||
fbs.reset();
|
||||
try Uuid.format(Uuid{
|
||||
.data = @bitCast([16]u8, @as(u128, 0x4ba7b74522ad_1da8_c242_d312_60515ff7)),
|
||||
}, "", .{}, fbs.writer());
|
||||
try std.testing.expectEqualStrings("f75f5160-12d3-42c2-a81d-ad2245b7a74b", &buf);
|
||||
}
|
||||
|
||||
test "roundtrip random uuid" {
|
||||
const uuid = Uuid.randV4(getRandom());
|
||||
|
||||
var buf: [36]u8 = undefined;
|
||||
var fbs = std.io.fixedBufferStream(&buf);
|
||||
try Uuid.format(uuid, "", .{}, fbs.writer());
|
||||
|
||||
const parsed = try Uuid.parse(&buf);
|
||||
|
||||
try std.testing.expectEqual(uuid, parsed);
|
||||
}
|
||||
pub const ciutf8 = struct {
|
||||
const Hash = std.hash.Wyhash;
|
||||
const View = std.unicode.Utf8View;
|
||||
|
|
Loading…
Reference in a new issue