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
|
2017-04-10 11:37:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- string.escapepattern() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.escapepattern_escapes()
|
|
|
|
test.isequal("boost_filesystem%-vc140%.1%.61%.0%.0", string.escapepattern("boost_filesystem-vc140.1.61.0.0"))
|
|
|
|
test.isequal("footage/down/temp/cars_%[100%]_upper/cars_%[100%]_upper%.exr", string.escapepattern("footage/down/temp/cars_[100]_upper/cars_[100]_upper.exr"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.escapepattern_doesntEscape()
|
|
|
|
local s = '<something foo="bar" />'
|
|
|
|
test.isequal(s, s:escapepattern())
|
|
|
|
|
|
|
|
s = 'lorem ipsum dolor sit amet'
|
|
|
|
test.isequal(s, s:escapepattern())
|
|
|
|
|
|
|
|
s = 'forward/slashes/foo/bar'
|
|
|
|
test.isequal(s, s:escapepattern())
|
|
|
|
|
|
|
|
s = '\\back\\slashes'
|
|
|
|
test.isequal(s, s:escapepattern())
|
|
|
|
|
|
|
|
s = 'new\nlines'
|
|
|
|
test.isequal(s, s:escapepattern())
|
|
|
|
end
|