072_undo_file_spec.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. -- Tests for undo file.
  2. -- Since this script is sourced we need to explicitly break changes up in
  3. -- undo-able pieces. Do that by setting 'undolevels'.
  4. local helpers = require('test.functional.helpers')(after_each)
  5. local feed, insert = helpers.feed, helpers.insert
  6. local clear, feed_command, expect = helpers.clear, helpers.feed_command, helpers.expect
  7. describe('72', function()
  8. setup(clear)
  9. it('is working', function()
  10. insert([[
  11. 1111 -----
  12. 2222 -----
  13. 123456789]])
  14. -- Test 'undofile': first a simple one-line change.
  15. feed_command('set visualbell')
  16. feed_command('set ul=100 undofile undodir=. nomore')
  17. feed_command('e! Xtestfile')
  18. feed('ggdGithis is one line<esc>:set ul=100<cr>')
  19. feed_command('s/one/ONE/')
  20. feed_command('set ul=100')
  21. feed_command('w')
  22. feed_command('bwipe!')
  23. feed_command('e Xtestfile')
  24. feed('u:.w! test.out<cr>')
  25. -- Test 'undofile', change in original file fails check.
  26. feed_command('set noundofile')
  27. feed_command('e! Xtestfile')
  28. feed_command('s/line/Line/')
  29. feed_command('w')
  30. feed_command('set undofile')
  31. feed_command('bwipe!')
  32. feed_command('e Xtestfile')
  33. ---- TODO: this beeps.
  34. feed('u:.w >>test.out<cr>')
  35. -- Test 'undofile', add 10 lines, delete 6 lines, undo 3.
  36. feed_command('set undofile')
  37. feed('ggdGione<cr>')
  38. feed('two<cr>')
  39. feed('three<cr>')
  40. feed('four<cr>')
  41. feed('five<cr>')
  42. feed('six<cr>')
  43. feed('seven<cr>')
  44. feed('eight<cr>')
  45. feed('nine<cr>')
  46. feed('ten<esc>:set ul=100<cr>')
  47. feed('3Gdd:set ul=100<cr>')
  48. feed('dd:set ul=100<cr>')
  49. feed('dd:set ul=100<cr>')
  50. feed('dd:set ul=100<cr>')
  51. feed('dd:set ul=100<cr>')
  52. feed('dd:set ul=100<cr>')
  53. feed_command('w')
  54. feed_command('bwipe!')
  55. feed_command('e Xtestfile')
  56. feed('uuu:w >>test.out<cr>')
  57. -- Test that reading the undofiles when setting undofile works.
  58. feed_command('set noundofile ul=0')
  59. feed('i<cr>')
  60. feed('<esc>u:e! Xtestfile<cr>')
  61. feed_command('set undofile ul=100')
  62. feed('uuuuuu:w >>test.out<cr>')
  63. ---- Open the output to see if it meets the expections
  64. feed_command('e! test.out')
  65. -- Assert buffer contents.
  66. expect([[
  67. this is one line
  68. this is ONE Line
  69. one
  70. two
  71. six
  72. seven
  73. eight
  74. nine
  75. ten
  76. one
  77. two
  78. three
  79. four
  80. five
  81. six
  82. seven
  83. eight
  84. nine
  85. ten]])
  86. end)
  87. teardown(function()
  88. os.remove('Xtestfile')
  89. os.remove('test.out')
  90. os.remove('.Xtestfile.un~')
  91. end)
  92. end)