From 197dfb660a35825d0bb46f8ef69884d7ec00c410 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 21 Jan 2026 22:09:09 +0800 Subject: fix path.filename and lastof --- tests/modules/string/test.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/modules/string/test.lua') 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) -- cgit v1.3.1 From e36eec65251b48fb5188691e86006ea8266ebe9a Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 21 Jan 2026 22:09:14 +0800 Subject: format code --- tests/modules/string/test.lua | 2 +- tests/modules/utf8/test.lua | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/modules/string/test.lua') diff --git a/tests/modules/string/test.lua b/tests/modules/string/test.lua index 4b093de45..1ec4b52a1 100644 --- a/tests/modules/string/test.lua +++ b/tests/modules/string/test.lua @@ -94,7 +94,7 @@ 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) diff --git a/tests/modules/utf8/test.lua b/tests/modules/utf8/test.lua index ddbd6b639..e1fced3a0 100644 --- a/tests/modules/utf8/test.lua +++ b/tests/modules/utf8/test.lua @@ -70,7 +70,7 @@ function test_sub(t) t:are_equal(utf8.sub("你好", 1, 1), "你") t:are_equal(utf8.sub("你好", 2, 2), "好") t:are_equal(utf8.sub("你好", 1, 2), "你好") - + -- mixed t:are_equal(utf8.sub("A你好B", 2, 3), "你好") t:are_equal(utf8.sub("A你好B", 1, 3), "A你好") @@ -105,7 +105,7 @@ function test_lastof(t) t:are_equal(utf8.lastof("A你好A", "好"), 3) t:are_equal(utf8.lastof("ABC", "D"), nil) - + -- plain t:are_equal(utf8.lastof("ABC", "A", true), 1) t:are_equal(utf8.lastof("ABC", "B", true), 2) @@ -142,13 +142,13 @@ function test_find(t) -- UTF-8 pattern matching (byte-based) -- "你" is 3 bytes. "." matches first byte. t:are_equal({utf8.find("你好", ".")}, {1, 1}) - + -- "你好", "好" -> bytes 4-6. t:are_equal({utf8.find("你好", "好")}, {2, 2}) - + -- "你好", "..." (3 dots) -> matches 3 bytes (whole "你"). t:are_equal({utf8.find("你好", "...")}, {1, 1}) - + -- "A你好", "%w" -> matches "A". t:are_equal({utf8.find("A你好", "%w")}, {1, 1}) end -- cgit v1.3.1