2024-04-09 04:26:16 -07:00
|
|
|
local t = require('test.unit.testutil')
|
2024-04-08 02:03:20 -07:00
|
|
|
local itp = t.gen_itp(it)
|
2019-03-01 19:13:00 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local to_cstr = t.to_cstr
|
|
|
|
local eq = t.eq
|
2019-03-01 19:13:00 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local search = t.cimport('./src/nvim/search.h')
|
|
|
|
local globals = t.cimport('./src/nvim/globals.h')
|
|
|
|
local ffi = t.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()
|
2024-05-20 15:22:23 -07:00
|
|
|
local search_regcomp = function(pat, patlen, pat_save, pat_use, options)
|
2023-12-04 15:32:39 -07:00
|
|
|
local regmatch = ffi.new('regmmatch_T')
|
2024-05-20 15:22:23 -07:00
|
|
|
local fail =
|
|
|
|
search.search_regcomp(to_cstr(pat), patlen, nil, pat_save, pat_use, options, regmatch)
|
2022-05-20 02:54:39 -07:00
|
|
|
return fail, regmatch
|
|
|
|
end
|
|
|
|
|
|
|
|
local get_search_pat = function()
|
2024-04-08 02:03:20 -07:00
|
|
|
return t.internalize(search.get_search_pat())
|
2022-05-20 02:54:39 -07:00
|
|
|
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
|
2024-05-20 15:22:23 -07:00
|
|
|
local fail = search_regcomp('a\192', 2, 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)
|