undo_spec.lua 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear = helpers.clear
  3. local command = helpers.command
  4. local expect = helpers.expect
  5. local feed = helpers.feed
  6. local insert = helpers.insert
  7. describe('u CTRL-R g- g+', function()
  8. before_each(clear)
  9. local function create_history(num_steps)
  10. if num_steps == 0 then return end
  11. insert('1')
  12. if num_steps == 1 then return end
  13. feed('o2<esc>')
  14. feed('o3<esc>')
  15. feed('u')
  16. if num_steps == 2 then return end
  17. feed('o4<esc>')
  18. if num_steps == 3 then return end
  19. feed('u')
  20. end
  21. local function undo_and_redo(hist_pos, undo, redo, expect_str)
  22. command('enew!')
  23. create_history(hist_pos)
  24. local cur_contents = helpers.curbuf_contents()
  25. feed(undo)
  26. expect(expect_str)
  27. feed(redo)
  28. expect(cur_contents)
  29. end
  30. -- TODO Look for message saying 'Already at oldest change'
  31. it('does nothing when no changes have happened', function()
  32. undo_and_redo(0, 'u', '<C-r>', '')
  33. undo_and_redo(0, 'g-', 'g+', '')
  34. end)
  35. it('undoes a change when at a leaf', function()
  36. undo_and_redo(1, 'u', '<C-r>', '')
  37. undo_and_redo(1, 'g-', 'g+', '')
  38. end)
  39. it('undoes a change when in a non-leaf', function()
  40. undo_and_redo(2, 'u', '<C-r>', '1')
  41. undo_and_redo(2, 'g-', 'g+', '1')
  42. end)
  43. it('undoes properly around a branch point', function()
  44. undo_and_redo(3, 'u', '<C-r>', [[
  45. 1
  46. 2]])
  47. undo_and_redo(3, 'g-', 'g+', [[
  48. 1
  49. 2
  50. 3]])
  51. end)
  52. it('can find the previous sequence after undoing to a branch', function()
  53. undo_and_redo(4, 'u', '<C-r>', '1')
  54. undo_and_redo(4, 'g-', 'g+', '1')
  55. end)
  56. end)