test_uuid.lua 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. --
  2. -- tests/base/test_uuid.lua
  3. -- Automated test suite for UUID generation.
  4. -- Copyright (c) 2008-2012 Jason Perkins and the Premake project
  5. --
  6. local suite = test.declare("os_uuid")
  7. --
  8. -- Setup and teardown
  9. --
  10. local builtin_print, result
  11. function suite.setup()
  12. builtin_print = print
  13. print = function(value)
  14. result = value
  15. end
  16. end
  17. function suite.teardown()
  18. print = builtin_print
  19. end
  20. --
  21. -- Make sure the return value looks like a UUID.
  22. --
  23. function suite.returnsValidUUID()
  24. local g = os.uuid()
  25. test.istrue(#g == 36)
  26. for i=1,36 do
  27. local ch = g:sub(i,i)
  28. test.istrue(ch:find("[ABCDEF0123456789-]"))
  29. end
  30. test.isequal("-", g:sub(9,9))
  31. test.isequal("-", g:sub(14,14))
  32. test.isequal("-", g:sub(19,19))
  33. test.isequal("-", g:sub(24,24))
  34. end
  35. --
  36. -- Make sure the value returned is deterministic if a name is provided.
  37. --
  38. function suite.isDeterministic_onName()
  39. test.isequal("885E8F4B-F43D-0EE7-FD55-99BD69B47448", os.uuid("MyValue"))
  40. end