File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import time
22import rand
33
4+ fn validate_separators (uuid string ) {
5+ assert uuid[8 ] == `-`
6+ assert uuid[13 ] == `-`
7+ assert uuid[18 ] == `-`
8+ assert uuid[23 ] == `-`
9+ assert uuid.len == 36
10+ }
11+
412// uuid_v4:
513fn test_rand_uuid_v4 () {
614 uuid1 := rand.uuid_v4 ()
715 uuid2 := rand.uuid_v4 ()
816 uuid3 := rand.uuid_v4 ()
17+ validate_separators (uuid1 )
18+ validate_separators (uuid2 )
19+ validate_separators (uuid3 )
920 assert uuid1 != uuid2
1021 assert uuid1 != uuid3
1122 assert uuid2 != uuid3
12- assert uuid1 .len == 36
13- assert uuid2 .len == 36
14- assert uuid3 .len == 36
1523 for i in 0 .. 1000 {
1624 x := rand.uuid_v4 ()
1725 // check the version field is always 4:
1826 assert x[14 ] == `4`
1927 // and the clock_seq_hi_and_reserved field is valid too:
2028 assert x[19 ] in [`8` , `9` , `a` , `b` ]
29+ validate_separators (x)
2130 }
2231}
2332
@@ -26,18 +35,19 @@ fn test_rand_uuid_v7() {
2635 uuid1 := rand.uuid_v7 ()
2736 uuid2 := rand.uuid_v7 ()
2837 uuid3 := rand.uuid_v7 ()
38+ validate_separators (uuid1 )
39+ validate_separators (uuid2 )
40+ validate_separators (uuid3 )
2941 assert uuid1 != uuid2
3042 assert uuid1 != uuid3
3143 assert uuid2 != uuid3
32- assert uuid1 .len == 36
33- assert uuid2 .len == 36
34- assert uuid3 .len == 36
3544 for i in 0 .. 1000 {
3645 x := rand.uuid_v7 ()
3746 // check the version field is always 7:
3847 assert x[14 ] == `7`
3948 // and variant field is always 0b10:
4049 assert x[19 ] in [`8` , `9` , `a` , `b` ]
50+ validate_separators (x)
4151 }
4252}
4353
You can’t perform that action at this time.
0 commit comments