diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modules/path/test.lua | 17 | ||||
| -rw-r--r-- | tests/modules/string/test.lua | 7 | ||||
| -rw-r--r-- | tests/modules/utf8/test.lua | 10 |
3 files changed, 34 insertions, 0 deletions
diff --git a/tests/modules/path/test.lua b/tests/modules/path/test.lua index f68a57e5f..57f7d06bc 100644 --- a/tests/modules/path/test.lua +++ b/tests/modules/path/test.lua @@ -34,6 +34,23 @@ function test_extension(t) t:are_equal(path.extension("\\home\\foo.so"), ".so") end +function test_filename(t) + t:are_equal(path.filename("foo"), "foo") + t:are_equal(path.filename("foo.so"), "foo.so") + t:are_equal(path.filename("/tmp/foo.so"), "foo.so") + t:are_equal(path.filename("c:\\tmp\\foo.so"), "foo.so") + t:are_equal(path.filename("/tmp/.."), "..") + t:are_equal(path.filename("/tmp/."), ".") + t:are_equal(path.filename("/"), "") + t:are_equal(path.filename(""), "") + + -- unicode + t:are_equal(path.filename("Unicode 测试/test.lua"), "test.lua") + t:are_equal(path.filename("Unicode 测试/foo/test.lua"), "test.lua") + t:are_equal(path.filename("测试/test.lua"), "test.lua") + t:are_equal(path.filename("测试\\test.lua"), "test.lua") +end + function test_directory(t) t:are_equal(path.directory(""), nil) t:are_equal(path.directory("."), nil) diff --git a/tests/modules/string/test.lua b/tests/modules/string/test.lua index 94b3c1a04..4b093de45 100644 --- a/tests/modules/string/test.lua +++ b/tests/modules/string/test.lua @@ -94,6 +94,13 @@ function test_lastof(t) t:are_equal(("/home/file.txt"):lastof('/', true), 6) t:are_equal(("/home/file.txt"):lastof('/home', true), 1) t:are_equal(("/home/file.txt"):lastof('[/\\]home'), 1) + + -- long string + local longstr = ("a"):rep(1000) .. "b" + t:are_equal(longstr:lastof("b"), 1001) + t:are_equal(longstr:lastof("a"), 1000) + t:are_equal(longstr:lastof("b", true), 1001) + t:are_equal(longstr:lastof("a", true), 1000) end function test_replace(t) diff --git a/tests/modules/utf8/test.lua b/tests/modules/utf8/test.lua index f7c8dbd2e..ddbd6b639 100644 --- a/tests/modules/utf8/test.lua +++ b/tests/modules/utf8/test.lua @@ -110,6 +110,16 @@ function test_lastof(t) t:are_equal(utf8.lastof("ABC", "A", true), 1) t:are_equal(utf8.lastof("ABC", "B", true), 2) t:are_equal(utf8.lastof("ABC", ".", true), nil) + t:are_equal(utf8.lastof("你好", "好", true), 2) + t:are_equal(utf8.lastof("C你好D", "好", true), 3) + t:are_equal(utf8.lastof("C你好D", "D", true), 4) + + -- long string + local longstr = ("你"):rep(1000) .. "好" + t:are_equal(utf8.lastof(longstr, "好"), 1001) + t:are_equal(utf8.lastof(longstr, "你"), 1000) + t:are_equal(utf8.lastof(longstr, "好", true), 1001) + t:are_equal(utf8.lastof(longstr, "你", true), 1000) -- pattern t:are_equal(utf8.lastof("ABC", "."), 3) |
