robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

bfredlMerge pull request #41212 from bfredl/unmagic8a0eb8f10b

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