setpos_spec.lua 1.8 KB

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