search_spec.lua (1897B)
1 local t = require('test.unit.testutil') 2 local itp = t.gen_itp(it) 3 4 local to_cstr = t.to_cstr 5 local eq = t.eq 6 7 local search = t.cimport('./src/nvim/search.h') 8 local globals = t.cimport('./src/nvim/globals.h') 9 local ffi = t.ffi 10 11 itp('pat_has_uppercase', function() 12 -- works on empty string 13 eq(false, search.pat_has_uppercase(to_cstr(''))) 14 15 -- works with utf uppercase 16 eq(false, search.pat_has_uppercase(to_cstr('ä'))) 17 eq(true, search.pat_has_uppercase(to_cstr('Ä'))) 18 eq(true, search.pat_has_uppercase(to_cstr('äaÅ'))) 19 20 -- works when pat ends with backslash 21 eq(false, search.pat_has_uppercase(to_cstr('\\'))) 22 eq(false, search.pat_has_uppercase(to_cstr('ab$\\'))) 23 24 -- skips escaped characters 25 eq(false, search.pat_has_uppercase(to_cstr('\\Ab'))) 26 eq(true, search.pat_has_uppercase(to_cstr('\\AU'))) 27 28 -- skips _X escaped characters 29 eq(false, search.pat_has_uppercase(to_cstr('\\_Ab'))) 30 eq(true, search.pat_has_uppercase(to_cstr('\\_AU'))) 31 32 -- skips %X escaped characters 33 eq(false, search.pat_has_uppercase(to_cstr('aa\\%Ab'))) 34 eq(true, search.pat_has_uppercase(to_cstr('aab\\%AU'))) 35 end) 36 37 describe('search_regcomp', function() 38 local search_regcomp = function(pat, patlen, pat_save, pat_use, options) 39 local regmatch = ffi.new('regmmatch_T') 40 local fail = 41 search.search_regcomp(to_cstr(pat), patlen, nil, pat_save, pat_use, options, regmatch) 42 return fail, regmatch 43 end 44 45 local get_search_pat = function() 46 return t.internalize(search.get_search_pat()) 47 end 48 49 itp('accepts regexp pattern with invalid utf', function() 50 --crafted to call reverse_text with invalid utf 51 globals.curwin.w_onebuf_opt.wo_rl = 1 52 globals.curwin.w_onebuf_opt.wo_rlc = to_cstr('s') 53 globals.cmdmod.cmod_flags = globals.CMOD_KEEPPATTERNS 54 local fail = search_regcomp('a\192', 2, 0, 0, 0) 55 eq(1, fail) 56 eq('\192a', get_search_pat()) 57 end) 58 end)