search_spec.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. local helpers = require("test.unit.helpers")(after_each)
  2. local itp = helpers.gen_itp(it)
  3. local to_cstr = helpers.to_cstr
  4. local eq = helpers.eq
  5. local search = helpers.cimport("./src/nvim/search.h")
  6. local globals = helpers.cimport('./src/nvim/globals.h')
  7. local ffi = helpers.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, pat_save, pat_use, options )
  30. local regmatch = ffi.new("regmmatch_T")
  31. local fail = search.search_regcomp(to_cstr(pat), pat_save, pat_use, options, regmatch)
  32. return fail, regmatch
  33. end
  34. local get_search_pat = function()
  35. return helpers.internalize(search.get_search_pat())
  36. end
  37. itp("accepts regexp pattern with invalid utf", function()
  38. --crafted to call reverse_text with invalid utf
  39. globals.curwin.w_onebuf_opt.wo_rl = 1
  40. globals.curwin.w_onebuf_opt.wo_rlc = to_cstr('s')
  41. globals.cmdmod.cmod_flags = globals.CMOD_KEEPPATTERNS
  42. local fail = search_regcomp("a\192", 0,0,0)
  43. eq(1, fail)
  44. eq("\192a", get_search_pat())
  45. end)
  46. end)