aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/search_spec.lua24
-rw-r--r--test/unit/strings_spec.lua35
2 files changed, 59 insertions, 0 deletions
diff --git a/test/unit/search_spec.lua b/test/unit/search_spec.lua
index 3c2d485e0e..ef5a0cb831 100644
--- a/test/unit/search_spec.lua
+++ b/test/unit/search_spec.lua
@@ -5,6 +5,8 @@ local to_cstr = helpers.to_cstr
local eq = helpers.eq
local search = helpers.cimport("./src/nvim/search.h")
+local globals = helpers.cimport('./src/nvim/globals.h')
+local ffi = helpers.ffi
itp('pat_has_uppercase', function()
-- works on empty string
@@ -31,3 +33,25 @@ itp('pat_has_uppercase', function()
eq(false, search.pat_has_uppercase(to_cstr("aa\\%Ab")))
eq(true, search.pat_has_uppercase(to_cstr("aab\\%AU")))
end)
+
+describe('search_regcomp', function()
+ local search_regcomp = function(pat, pat_save, pat_use, options )
+ local regmatch = ffi.new("regmmatch_T")
+ local fail = search.search_regcomp(to_cstr(pat), pat_save, pat_use, options, regmatch)
+ return fail, regmatch
+ end
+
+ local get_search_pat = function()
+ return helpers.internalize(search.get_search_pat())
+ end
+
+ itp("accepts regexp pattern with invalid utf", function()
+ --crafted to call reverse_text with invalid utf
+ globals.curwin.w_onebuf_opt.wo_rl = 1
+ globals.curwin.w_onebuf_opt.wo_rlc = to_cstr('s')
+ globals.cmdmod.keeppatterns = 1
+ local fail = search_regcomp("a\192", 0,0,0)
+ eq(1, fail)
+ eq("\192a", get_search_pat())
+ end)
+end)
diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua
index e085ac749d..b2c839f25c 100644
--- a/test/unit/strings_spec.lua
+++ b/test/unit/strings_spec.lua
@@ -150,3 +150,38 @@ describe('strcase_save()' , function()
eq("a", strcase_save("\xc1\x81", false))
end)
end)
+
+describe("reverse_text", function()
+ local reverse_text = function(str)
+ return helpers.internalize(strings.reverse_text(to_cstr(str)))
+ end
+
+ itp("handles empty string", function()
+ eq("", reverse_text(""))
+ end)
+
+ itp("handles simple cases", function()
+ eq("a", reverse_text("a"))
+ eq("ba", reverse_text("ab"))
+ end)
+
+ itp("handles multibyte characters", function()
+ eq("bα", reverse_text("αb"))
+ eq("Yötön yö", reverse_text("öy nötöY"))
+ end)
+
+ itp("handles combining chars", function()
+ local utf8_COMBINING_RING_ABOVE = "\204\138"
+ local utf8_COMBINING_RING_BELOW = "\204\165"
+ eq("bba" .. utf8_COMBINING_RING_ABOVE .. utf8_COMBINING_RING_BELOW .. "aa",
+ reverse_text("aaa" .. utf8_COMBINING_RING_ABOVE .. utf8_COMBINING_RING_BELOW .. "bb"))
+ end)
+
+ itp("treats invalid utf as separate characters", function()
+ eq("\192ba", reverse_text("ab\192"))
+ end)
+
+ itp("treats an incomplete utf continuation sequence as valid", function()
+ eq("\194ba", reverse_text("ab\194"))
+ end)
+end)