searchpos_spec.lua 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local call = helpers.call
  3. local clear = helpers.clear
  4. local command = helpers.command
  5. local eq = helpers.eq
  6. local eval = helpers.eval
  7. local insert = helpers.insert
  8. describe('searchpos', function()
  9. before_each(clear)
  10. it('is working', function()
  11. insert([[
  12. 1a3
  13. 123xyz]])
  14. call('cursor', 1, 1)
  15. eq({1, 1, 2}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]]))
  16. call('cursor', 1, 2)
  17. eq({2, 1, 1}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]]))
  18. command('set cpo-=c')
  19. call('cursor', 1, 2)
  20. eq({1, 2, 2}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]]))
  21. call('cursor', 1, 3)
  22. eq({1, 3, 1}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]]))
  23. -- Now with \zs, first match is in column 0, "a" is matched.
  24. call('cursor', 1, 3)
  25. eq({2, 4, 2}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcW')]]))
  26. -- With z flag start at cursor column, don't see the "a".
  27. call('cursor', 1, 3)
  28. eq({2, 4, 1}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}\zsxyz', 'pcWz')]]))
  29. end)
  30. end)