Merge 0.10->trunk
[prosody.git] / tests / test_util_uuid.lua
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