setpos_spec.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local setpos = helpers.funcs.setpos
  3. local getpos = helpers.funcs.getpos
  4. local insert = helpers.insert
  5. local clear = helpers.clear
  6. local command = helpers.command
  7. local eval = helpers.eval
  8. local eq = helpers.eq
  9. local exc_exec = helpers.exc_exec
  10. describe('setpos() function', function()
  11. before_each(function()
  12. clear()
  13. insert([[
  14. First line of text
  15. Second line of text
  16. Third line of text]])
  17. command('new')
  18. insert([[
  19. Line of text 1
  20. Line of text 2
  21. Line of text 3]])
  22. end)
  23. it('can set the current cursor position', function()
  24. setpos(".", {0, 2, 1, 0})
  25. eq(getpos("."), {0, 2, 1, 0})
  26. setpos(".", {2, 1, 1, 0})
  27. eq(getpos("."), {0, 1, 1, 0})
  28. local ret = exc_exec('call setpos(".", [1, 1, 1, 0])')
  29. eq(0, ret)
  30. end)
  31. it('can set lowercase marks in the current buffer', function()
  32. setpos("'d", {0, 2, 1, 0})
  33. eq(getpos("'d"), {0, 2, 1, 0})
  34. command('undo')
  35. command('call setpos("\'d", [2, 3, 1, 0])')
  36. eq(getpos("'d"), {0, 3, 1, 0})
  37. end)
  38. it('can set lowercase marks in other buffers', function()
  39. local retval = setpos("'d", {1, 2, 1, 0})
  40. eq(0, retval)
  41. setpos("'d", {1, 2, 1, 0})
  42. eq(getpos("'d"), {0, 0, 0, 0})
  43. command('wincmd w')
  44. eq(eval('bufnr("%")'), 1)
  45. eq(getpos("'d"), {0, 2, 1, 0})
  46. end)
  47. it("fails when setting a mark in a buffer that doesn't exist", function()
  48. local retval = setpos("'d", {3, 2, 1, 0})
  49. eq(-1, retval)
  50. eq(getpos("'d"), {0, 0, 0, 0})
  51. retval = setpos("'D", {3, 2, 1, 0})
  52. eq(-1, retval)
  53. eq(getpos("'D"), {0, 0, 0, 0})
  54. end)
  55. it('can set uppercase marks', function()
  56. setpos("'D", {2, 2, 3, 0})
  57. eq(getpos("'D"), {2, 2, 3, 0})
  58. -- Can set a mark in another buffer
  59. setpos("'D", {1, 2, 2, 0})
  60. eq(getpos("'D"), {1, 2, 2, 0})
  61. end)
  62. end)