jump_spec.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear = helpers.clear
  3. local command = helpers.command
  4. local eq = helpers.eq
  5. local funcs = helpers.funcs
  6. local feed = helpers.feed
  7. local exec_capture = helpers.exec_capture
  8. local write_file = helpers.write_file
  9. describe('jumplist', function()
  10. local fname1 = 'Xtest-functional-normal-jump'
  11. local fname2 = fname1..'2'
  12. before_each(clear)
  13. after_each(function()
  14. os.remove(fname1)
  15. os.remove(fname2)
  16. end)
  17. it('does not add a new entry on startup', function()
  18. eq('\n jump line col file/text\n>', funcs.execute('jumps'))
  19. end)
  20. it('does not require two <C-O> strokes to jump back', function()
  21. write_file(fname1, 'first file contents')
  22. write_file(fname2, 'second file contents')
  23. command('args '..fname1..' '..fname2)
  24. local buf1 = funcs.bufnr(fname1)
  25. local buf2 = funcs.bufnr(fname2)
  26. command('next')
  27. feed('<C-O>')
  28. eq(buf1, funcs.bufnr('%'))
  29. command('first')
  30. command('snext')
  31. feed('<C-O>')
  32. eq(buf1, funcs.bufnr('%'))
  33. feed('<C-I>')
  34. eq(buf2, funcs.bufnr('%'))
  35. feed('<C-O>')
  36. eq(buf1, funcs.bufnr('%'))
  37. command('drop '..fname2)
  38. feed('<C-O>')
  39. eq(buf1, funcs.bufnr('%'))
  40. end)
  41. end)
  42. describe("jumpoptions=stack behaves like 'tagstack'", function()
  43. before_each(function()
  44. clear()
  45. feed(':clearjumps<cr>')
  46. -- Add lines so that we have locations to jump to.
  47. for i = 1,101,1
  48. do
  49. feed('iLine ' .. i .. '<cr><esc>')
  50. end
  51. -- Jump around to add some locations to the jump list.
  52. feed('0gg')
  53. feed('10gg')
  54. feed('20gg')
  55. feed('30gg')
  56. feed('40gg')
  57. feed('50gg')
  58. feed(':set jumpoptions=stack<cr>')
  59. end)
  60. after_each(function()
  61. feed('set jumpoptions=')
  62. end)
  63. it('discards the tail when navigating from the middle', function()
  64. feed('<C-O>')
  65. feed('<C-O>')
  66. eq( ''
  67. .. ' jump line col file/text\n'
  68. .. ' 4 102 0 \n'
  69. .. ' 3 1 0 Line 1\n'
  70. .. ' 2 10 0 Line 10\n'
  71. .. ' 1 20 0 Line 20\n'
  72. .. '> 0 30 0 Line 30\n'
  73. .. ' 1 40 0 Line 40\n'
  74. .. ' 2 50 0 Line 50',
  75. exec_capture('jumps'))
  76. feed('90gg')
  77. eq( ''
  78. .. ' jump line col file/text\n'
  79. .. ' 5 102 0 \n'
  80. .. ' 4 1 0 Line 1\n'
  81. .. ' 3 10 0 Line 10\n'
  82. .. ' 2 20 0 Line 20\n'
  83. .. ' 1 30 0 Line 30\n'
  84. .. '>',
  85. exec_capture('jumps'))
  86. end)
  87. it('does not add the same location twice adjacently', function()
  88. feed('60gg')
  89. feed('60gg')
  90. eq( ''
  91. .. ' jump line col file/text\n'
  92. .. ' 7 102 0 \n'
  93. .. ' 6 1 0 Line 1\n'
  94. .. ' 5 10 0 Line 10\n'
  95. .. ' 4 20 0 Line 20\n'
  96. .. ' 3 30 0 Line 30\n'
  97. .. ' 2 40 0 Line 40\n'
  98. .. ' 1 50 0 Line 50\n'
  99. .. '>',
  100. exec_capture('jumps'))
  101. end)
  102. it('does add the same location twice nonadjacently', function()
  103. feed('10gg')
  104. feed('20gg')
  105. eq( ''
  106. .. ' jump line col file/text\n'
  107. .. ' 8 102 0 \n'
  108. .. ' 7 1 0 Line 1\n'
  109. .. ' 6 10 0 Line 10\n'
  110. .. ' 5 20 0 Line 20\n'
  111. .. ' 4 30 0 Line 30\n'
  112. .. ' 3 40 0 Line 40\n'
  113. .. ' 2 50 0 Line 50\n'
  114. .. ' 1 10 0 Line 10\n'
  115. .. '>',
  116. exec_capture('jumps'))
  117. end)
  118. end)