robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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