test_table.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --
  2. -- tests/base/test_table.lua
  3. -- Automated test suite for the new table functions.
  4. -- Copyright (c) 2008-2010 Jason Perkins and the Premake project
  5. --
  6. T.table = { }
  7. local suite = T.table
  8. --
  9. -- table.contains() tests
  10. --
  11. function suite.contains_OnContained()
  12. t = { "one", "two", "three" }
  13. test.istrue( table.contains(t, "two") )
  14. end
  15. function suite.contains_OnNotContained()
  16. t = { "one", "two", "three" }
  17. test.isfalse( table.contains(t, "four") )
  18. end
  19. --
  20. -- table.flatten() tests
  21. --
  22. function suite.flatten_OnMixedValues()
  23. t = { "a", { "b", "c" }, "d" }
  24. test.isequal({ "a", "b", "c", "d" }, table.flatten(t))
  25. end
  26. --
  27. -- table.implode() tests
  28. --
  29. function suite.implode()
  30. t = { "one", "two", "three", "four" }
  31. test.isequal("[one], [two], [three], [four]", table.implode(t, "[", "]", ", "))
  32. end
  33. --
  34. -- table.isempty() tests
  35. --
  36. function suite.isempty_ReturnsTrueOnEmpty()
  37. test.istrue(table.isempty({}))
  38. end
  39. function suite.isempty_ReturnsFalseOnNotEmpty()
  40. test.isfalse(table.isempty({ 1 }))
  41. end
  42. function suite.isempty_ReturnsFalseOnNotEmptyMap()
  43. test.isfalse(table.isempty({ name = 'premake' }))
  44. end
  45. function suite.isempty_ReturnsFalseOnNotEmptyMapWithFalseKey()
  46. test.isfalse(table.isempty({ [false] = 0 }))
  47. end