2008-10-31 18:38:05 +00:00
|
|
|
--
|
|
|
|
-- tests/test_string.lua
|
|
|
|
-- Automated test suite for the new string functions.
|
|
|
|
-- Copyright (c) 2008 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
local suite = test.declare("string")
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- string.endswith() tests
|
|
|
|
--
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.endswith_ReturnsTrue_OnMatch()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.istrue(string.endswith("Abcdef", "def"))
|
|
|
|
end
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.endswith_ReturnsFalse_OnMismatch()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isfalse(string.endswith("Abcedf", "efg"))
|
|
|
|
end
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.endswith_ReturnsFalse_OnLongerNeedle()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isfalse(string.endswith("Abc", "Abcdef"))
|
|
|
|
end
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.endswith_ReturnsFalse_OnNilHaystack()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isfalse(string.endswith(nil, "ghi"))
|
|
|
|
end
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.endswith_ReturnsFalse_OnNilNeedle()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isfalse(string.endswith("Abc", nil))
|
|
|
|
end
|
2009-04-28 14:17:20 +00:00
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.endswith_ReturnsTrue_OnExactMatch()
|
2009-04-28 14:17:20 +00:00
|
|
|
test.istrue(string.endswith("/", "/"))
|
|
|
|
end
|
2008-10-31 18:38:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- string.explode() tests
|
|
|
|
--
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.explode_ReturnsParts_OnValidCall()
|
2008-10-31 18:38:05 +00:00
|
|
|
test.isequal({"aaa","bbb","ccc"}, string.explode("aaa/bbb/ccc", "/", true))
|
|
|
|
end
|
2008-11-13 00:54:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- string.startswith() tests
|
|
|
|
--
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.startswith_OnMatch()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.istrue(string.startswith("Abcdef", "Abc"))
|
|
|
|
end
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.startswith_OnMismatch()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.isfalse(string.startswith("Abcdef", "ghi"))
|
|
|
|
end
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.startswith_OnLongerNeedle()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.isfalse(string.startswith("Abc", "Abcdef"))
|
|
|
|
end
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.startswith_OnEmptyHaystack()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.isfalse(string.startswith("", "Abc"))
|
|
|
|
end
|
|
|
|
|
2016-05-12 23:56:04 +00:00
|
|
|
function suite.startswith_OnEmptyNeedle()
|
2008-11-13 00:54:41 +00:00
|
|
|
test.istrue(string.startswith("Abcdef", ""))
|
|
|
|
end
|