test_string.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --
  2. -- tests/test_string.lua
  3. -- Automated test suite for the new string functions.
  4. -- Copyright (c) 2008 Jason Perkins and the Premake project
  5. --
  6. T.string = { }
  7. --
  8. -- string.endswith() tests
  9. --
  10. function T.string.endswith_ReturnsTrue_OnMatch()
  11. test.istrue(string.endswith("Abcdef", "def"))
  12. end
  13. function T.string.endswith_ReturnsFalse_OnMismatch()
  14. test.isfalse(string.endswith("Abcedf", "efg"))
  15. end
  16. function T.string.endswith_ReturnsFalse_OnLongerNeedle()
  17. test.isfalse(string.endswith("Abc", "Abcdef"))
  18. end
  19. function T.string.endswith_ReturnsFalse_OnNilHaystack()
  20. test.isfalse(string.endswith(nil, "ghi"))
  21. end
  22. function T.string.endswith_ReturnsFalse_OnNilNeedle()
  23. test.isfalse(string.endswith("Abc", nil))
  24. end
  25. function T.string.endswith_ReturnsTrue_OnExactMatch()
  26. test.istrue(string.endswith("/", "/"))
  27. end
  28. --
  29. -- string.explode() tests
  30. --
  31. function T.string.explode_ReturnsParts_OnValidCall()
  32. test.isequal({"aaa","bbb","ccc"}, string.explode("aaa/bbb/ccc", "/", true))
  33. end
  34. --
  35. -- string.startswith() tests
  36. --
  37. function T.string.startswith_OnMatch()
  38. test.istrue(string.startswith("Abcdef", "Abc"))
  39. end
  40. function T.string.startswith_OnMismatch()
  41. test.isfalse(string.startswith("Abcdef", "ghi"))
  42. end
  43. function T.string.startswith_OnLongerNeedle()
  44. test.isfalse(string.startswith("Abc", "Abcdef"))
  45. end
  46. function T.string.startswith_OnEmptyHaystack()
  47. test.isfalse(string.startswith("", "Abc"))
  48. end
  49. function T.string.startswith_OnEmptyNeedle()
  50. test.istrue(string.startswith("Abcdef", ""))
  51. end