From 733d4130d52d44f2a6f8cbf72336c64e810237d1 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 7 Oct 2024 23:12:13 +0200 Subject: [PATCH] update final test cases --- spec/uuid_spec.lua | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/spec/uuid_spec.lua b/spec/uuid_spec.lua index 4b055fc..3c0ef30 100644 --- a/spec/uuid_spec.lua +++ b/spec/uuid_spec.lua @@ -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)