2023-12-04 15:32:39 -07:00
|
|
|
local helpers = require('test.unit.helpers')(after_each)
|
2019-03-01 19:13:00 -07:00
|
|
|
local itp = helpers.gen_itp(it)
|
|
|
|
|
|
|
|
local to_cstr = helpers.to_cstr
|
2023-12-04 15:32:39 -07:00
|
|
|
local eq = helpers.eq
|
2019-03-01 19:13:00 -07:00
|
|
|
|
2023-12-04 15:32:39 -07:00
|
|
|
local search = helpers.cimport('./src/nvim/search.h')
|
2022-05-20 02:54:39 -07:00
|
|
|
local globals = helpers.cimport('./src/nvim/globals.h')
|
|
|
|
local ffi = helpers.ffi
|
2019-03-01 19:13:00 -07:00
|
|
|
|
|
|
|
itp('pat_has_uppercase', function()
|
|
|
|
-- works on empty string
|
2023-12-04 15:32:39 -07:00
|
|
|
eq(false, search.pat_has_uppercase(to_cstr('')))
|
2019-03-01 19:13:00 -07:00
|
|
|
|
|
|
|
-- works with utf uppercase
|
2023-12-04 15:32:39 -07:00
|
|
|
eq(false, search.pat_has_uppercase(to_cstr('ä')))
|
|
|
|
eq(true, search.pat_has_uppercase(to_cstr('Ä')))
|
|
|
|
eq(true, search.pat_has_uppercase(to_cstr('äaÅ')))
|
2019-03-01 19:13:00 -07:00
|
|
|
|
|
|
|
-- works when pat ends with backslash
|
2023-12-04 15:32:39 -07:00
|
|
|
eq(false, search.pat_has_uppercase(to_cstr('\\')))
|
|
|
|
eq(false, search.pat_has_uppercase(to_cstr('ab$\\')))
|
2019-03-01 19:13:00 -07:00
|
|
|
|
|
|
|
-- skips escaped characters
|
2023-12-04 15:32:39 -07:00
|
|
|
eq(false, search.pat_has_uppercase(to_cstr('\\Ab')))
|
|
|
|
eq(true, search.pat_has_uppercase(to_cstr('\\AU')))
|
2019-03-01 19:13:00 -07:00
|
|
|
|
|
|
|
-- skips _X escaped characters
|
2023-12-04 15:32:39 -07:00
|
|
|
eq(false, search.pat_has_uppercase(to_cstr('\\_Ab')))
|
|
|
|
eq(true, search.pat_has_uppercase(to_cstr('\\_AU')))
|
2019-03-01 19:13:00 -07:00
|
|
|
|
|
|
|
-- skips %X escaped characters
|
2023-12-04 15:32:39 -07:00
|
|
|
eq(false, search.pat_has_uppercase(to_cstr('aa\\%Ab')))
|
|
|
|
eq(true, search.pat_has_uppercase(to_cstr('aab\\%AU')))
|
2019-03-01 19:13:00 -07:00
|
|
|
end)
|
2022-05-20 02:54:39 -07:00
|
|
|
|
|
|
|
describe('search_regcomp', function()
|
2023-12-04 15:32:39 -07:00
|
|
|
local search_regcomp = function(pat, pat_save, pat_use, options)
|
|
|
|
local regmatch = ffi.new('regmmatch_T')
|
2022-12-23 16:55:03 -07:00
|
|
|
local fail = search.search_regcomp(to_cstr(pat), nil, pat_save, pat_use, options, regmatch)
|
2022-05-20 02:54:39 -07:00
|
|
|
return fail, regmatch
|
|
|
|
end
|
|
|
|
|
|
|
|
local get_search_pat = function()
|
|
|
|
return helpers.internalize(search.get_search_pat())
|
|
|
|
end
|
|
|
|
|
2023-12-04 15:32:39 -07:00
|
|
|
itp('accepts regexp pattern with invalid utf', function()
|
2022-05-20 02:54:39 -07:00
|
|
|
--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')
|
2022-06-13 05:20:34 -07:00
|
|
|
globals.cmdmod.cmod_flags = globals.CMOD_KEEPPATTERNS
|
2023-12-04 15:32:39 -07:00
|
|
|
local fail = search_regcomp('a\192', 0, 0, 0)
|
2022-05-20 02:54:39 -07:00
|
|
|
eq(1, fail)
|
2023-12-04 15:32:39 -07:00
|
|
|
eq('\192a', get_search_pat())
|
2022-05-20 02:54:39 -07:00
|
|
|
end)
|
|
|
|
end)
|