From 880f2169b75e82176386cb1618b601988e802d6f Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 28 Apr 2025 10:05:02 +0300 Subject: [PATCH] rand: check the separators for the generated UUIDs in random_identifiers_test.v --- vlib/rand/random_identifiers_test.v | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/vlib/rand/random_identifiers_test.v b/vlib/rand/random_identifiers_test.v index dd63f38891..5a931531f7 100644 --- a/vlib/rand/random_identifiers_test.v +++ b/vlib/rand/random_identifiers_test.v @@ -1,23 +1,32 @@ import time import rand +fn validate_separators(uuid string) { + assert uuid[8] == `-` + assert uuid[13] == `-` + assert uuid[18] == `-` + assert uuid[23] == `-` + assert uuid.len == 36 +} + // uuid_v4: fn test_rand_uuid_v4() { uuid1 := rand.uuid_v4() uuid2 := rand.uuid_v4() uuid3 := rand.uuid_v4() + validate_separators(uuid1) + validate_separators(uuid2) + validate_separators(uuid3) assert uuid1 != uuid2 assert uuid1 != uuid3 assert uuid2 != uuid3 - assert uuid1.len == 36 - assert uuid2.len == 36 - assert uuid3.len == 36 for i in 0 .. 1000 { x := rand.uuid_v4() // check the version field is always 4: assert x[14] == `4` // and the clock_seq_hi_and_reserved field is valid too: assert x[19] in [`8`, `9`, `a`, `b`] + validate_separators(x) } } @@ -26,18 +35,19 @@ fn test_rand_uuid_v7() { uuid1 := rand.uuid_v7() uuid2 := rand.uuid_v7() uuid3 := rand.uuid_v7() + validate_separators(uuid1) + validate_separators(uuid2) + validate_separators(uuid3) assert uuid1 != uuid2 assert uuid1 != uuid3 assert uuid2 != uuid3 - assert uuid1.len == 36 - assert uuid2.len == 36 - assert uuid3.len == 36 for i in 0 .. 1000 { x := rand.uuid_v7() // check the version field is always 7: assert x[14] == `7` // and variant field is always 0b10: assert x[19] in [`8`, `9`, `a`, `b`] + validate_separators(x) } }