refactor: move reverse_text to strings.c as it's a string operation

Also add tests for reverse_text.

Co-authored-by: Kalle Ranki <kalle.ranki@gmail.com>
This commit is contained in:
Dundar Goc
2022-05-20 11:54:39 +02:00
parent 1d160a76ec
commit 1a0de90068
4 changed files with 80 additions and 25 deletions

View File

@@ -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)