mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-25 23:24:35 +00:00
tests: Add some uuid4 tests
This commit is contained in:
parent
3c959caa23
commit
4d8d69b729
@ -5,6 +5,7 @@ package.path = package.path .. ";../?.lua"
|
||||
|
||||
local assert = require("batteries.assert")
|
||||
local tablex = require("batteries.tablex")
|
||||
local uuid = require("batteries.uuid")
|
||||
|
||||
-- tablex {{{
|
||||
|
||||
@ -155,3 +156,26 @@ local function test_spairs()
|
||||
10, 8, 7
|
||||
}))
|
||||
end
|
||||
|
||||
local function test_uuid4()
|
||||
for i = 1, 100 do
|
||||
local id = uuid.uuid4()
|
||||
|
||||
-- right len
|
||||
assert(#id == 36)
|
||||
-- right amount of non hyphen characters
|
||||
assert(#id:gsub("-", "") == 32)
|
||||
|
||||
-- 15th char is always a 4
|
||||
assert(id:sub(15, 15) == "4")
|
||||
-- 20th char is always between 0x8 and 0xb
|
||||
local y = tonumber("0x" .. id:sub(20, 20))
|
||||
assert(y >= 0x8 and y <= 0xb)
|
||||
|
||||
-- everything is a valid 8 bit num
|
||||
for char in id:gsub("-", ""):gmatch(".") do
|
||||
local num = assert(tonumber("0x" .. char))
|
||||
assert(num >= 0 and num <= 0xf)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user