search_spec.lua 1.9 KB

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