Skip to content

Commit

Permalink
update final test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Oct 7, 2024
1 parent c146060 commit 733d413
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions spec/uuid_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,20 @@ describe("Testing uuid library", function()
end)

it("tests the hwaddr parameter" , function()
assert.has_error(function() uuid("12345678901") end) -- too short
assert.has_error(function() uuid("123a4::xxyy;;590") end) -- too short after clean
assert.has_error(function() uuid(true) end) -- not a string
assert.has_error(function() uuid(123) end) -- not a string
assert.has_no.error(function() uuid("abcdefabcdef") end) -- hex only
assert.same('00000000-0000-4000-8000-abcdefabcdef', uuid("abcdefabcdef"))
assert.has_no.error(function() uuid("123456789012") end) -- right size
assert.same('00000000-0000-4000-8000-123456789012', uuid("123456789012"))
assert.has_no.error(function() uuid("1234567890123") end) -- oversize
assert.same('00000000-0000-4000-8000-123456789012', uuid("1234567890123"))
assert.has_error(function() uuid.new("12345678901") end) -- too short
assert.has_error(function() uuid.new("123a4::xxyy;;590") end) -- too short after clean
assert.has_error(function() uuid.new(true) end) -- not a string
assert.has_error(function() uuid.new(123) end) -- not a string
assert.has_no.error(function() uuid.new("abcdefabcdef") end) -- hex only
assert.same('00000000-0000-4000-8000-abcdefabcdef', uuid.new("abcdefabcdef"))
assert.has_no.error(function() uuid.new("123456789012") end) -- right size
assert.same('00000000-0000-4000-8000-123456789012', uuid.new("123456789012"))
assert.has_no.error(function() uuid.new("1234567890123") end) -- oversize
assert.same('00000000-0000-4000-8000-123456789012', uuid.new("1234567890123"))
end)

it("tests uuid.seed() using luasocket gettime() if available, os.time() if unavailable", function()
-- create a fake socket module with a spy.
local ls = { gettime = spy.new(function() return 123.123 end) }
package.loaded["socket"] = ls
uuid.seed()
package.loaded["socket"] = nil
assert.spy(ls.gettime).was.called(1)

-- do again with os.time()
local ot = os.time
os.time = spy.new(os.time) -- luacheck: ignore
uuid.seed()
assert.spy(os.time).was.called(1)
os.time = ot -- luacheck: ignore
end)

it("tests uuid.randomseed() to properly limit the provided value", function()
local bitsize = 32
assert.are.equal(12345, uuid.randomseed(12345))
assert.are.equal(12345, uuid.randomseed(12345 + 2^bitsize))
pending("uuid.v4()", function()
-- TODO: implement
end)

end)

0 comments on commit 733d413

Please sign in to comment.