Add tests for Uuid

This commit is contained in:
jaina heartles 2022-05-12 22:05:40 -07:00
parent 5353169250
commit d82d271a7f

View file

@ -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;