Comparison

tests/test_util_uuid.lua @ 7073:31fa6770019c

tests: Add test for util.uuid (checks that the output format is correct)
author Kim Alvefur <zash@zash.se>
date Sun, 10 Jan 2016 03:35:00 +0100
child 7512:7a655ff689b1
comparison
equal deleted inserted replaced
7072:3121054e665f 7073:31fa6770019c
1 -- This tests the format, not the randomness
2
3 -- https://tools.ietf.org/html/rfc4122#section-4.4
4
5 local pattern = "^" .. table.concat({
6 string.rep("%x", 8),
7 string.rep("%x", 4),
8 "4" .. -- version
9 string.rep("%x", 3),
10 "[89ab]" .. -- reserved bits of 1 and 0
11 string.rep("%x", 3),
12 string.rep("%x", 12),
13 }, "%-") .. "$";
14
15 function generate(generate)
16 for i = 1, 100 do
17 assert_is(generate():match(pattern));
18 end
19 end
20
21 function seed(seed)
22 assert_equal(seed("random string here"), nil, "seed doesn't return anything");
23 end
24