neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

072_undo_file_spec.lua (2559B)


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