comparison src/testdir/test_undo.vim @ 14015:9709d783261f v8.1.0025

patch 8.1.0025: no test for the undofile() function commit https://github.com/vim/vim/commit/e5fa11186fde4a19e505eba403d3af8c61d11304 Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 26 18:46:30 2018 +0200 patch 8.1.0025: no test for the undofile() function Problem: No test for the undofile() function. Solution: Add test. (Dominique Pelle, closes https://github.com/vim/vim/issues/2958)
author Christian Brabandt <cb@256bit.org>
date Sat, 26 May 2018 19:00:05 +0200
parents 2941a86f8aaa
children 83a366325158
comparison
equal deleted inserted replaced
14014:9d29a6eff754 14015:9709d783261f
83 endfunc 83 endfunc
84 84
85 func FillBuffer() 85 func FillBuffer()
86 for i in range(1,13) 86 for i in range(1,13)
87 put=i 87 put=i
88 " Set 'undolevels' to split undo. 88 " Set 'undolevels' to split undo.
89 exe "setg ul=" . &g:ul 89 exe "setg ul=" . &g:ul
90 endfor 90 endfor
91 endfunc 91 endfunc
92 92
93 func Test_global_local_undolevels() 93 func Test_global_local_undolevels()
191 191
192 func Test_undolist() 192 func Test_undolist()
193 new 193 new
194 set ul=100 194 set ul=100
195 195
196 let a=execute('undolist') 196 let a = execute('undolist')
197 call assert_equal("\nNothing to undo", a) 197 call assert_equal("\nNothing to undo", a)
198 198
199 " 1 leaf (2 changes). 199 " 1 leaf (2 changes).
200 call feedkeys('achange1', 'xt') 200 call feedkeys('achange1', 'xt')
201 call feedkeys('achange2', 'xt') 201 call feedkeys('achange2', 'xt')
202 let a=execute('undolist') 202 let a = execute('undolist')
203 call assert_match("^\nnumber changes when *saved\n *2 *2 .*$", a) 203 call assert_match("^\nnumber changes when *saved\n *2 *2 .*$", a)
204 204
205 " 2 leaves. 205 " 2 leaves.
206 call feedkeys('u', 'xt') 206 call feedkeys('u', 'xt')
207 call feedkeys('achange3\<Esc>', 'xt') 207 call feedkeys('achange3\<Esc>', 'xt')
208 let a=execute('undolist') 208 let a = execute('undolist')
209 call assert_match("^\nnumber changes when *saved\n *2 *2 *.*\n *3 *2 .*$", a) 209 call assert_match("^\nnumber changes when *saved\n *2 *2 *.*\n *3 *2 .*$", a)
210 close! 210 close!
211 endfunc 211 endfunc
212 212
213 func Test_U_command() 213 func Test_U_command()
337 337
338 " Test for undo working properly when executing commands from a register. 338 " Test for undo working properly when executing commands from a register.
339 " Also test this in an empty buffer. 339 " Also test this in an empty buffer.
340 func Test_cmd_in_reg_undo() 340 func Test_cmd_in_reg_undo()
341 enew! 341 enew!
342 let @a="Ox\<Esc>jAy\<Esc>kdd" 342 let @a = "Ox\<Esc>jAy\<Esc>kdd"
343 edit +/^$ test_undo.vim 343 edit +/^$ test_undo.vim
344 normal @au 344 normal @au
345 call assert_equal(0, &modified) 345 call assert_equal(0, &modified)
346 return 346 return
347 new 347 new
348 normal @au 348 normal @au
349 call assert_equal(0, &modified) 349 call assert_equal(0, &modified)
350 only! 350 only!
351 let @a='' 351 let @a = ''
352 endfunc 352 endfunc
353 353
354 " This used to cause an illegal memory access 354 " This used to cause an illegal memory access
355 func Test_undo_append() 355 func Test_undo_append()
356 new 356 new
408 new 408 new
409 exe "norm\x16r\x160" 409 exe "norm\x16r\x160"
410 exe "norm." 410 exe "norm."
411 bwipe! 411 bwipe!
412 endfunc 412 endfunc
413
414 funct Test_undofile()
415 " Test undofile() without setting 'undodir'.
416 if has('persistent_undo')
417 call assert_equal(fnamemodify('.Xundofoo.un~', ':p'), undofile('Xundofoo'))
418 else
419 call assert_equal('', undofile('Xundofoo'))
420 endif
421 call assert_equal('', undofile(''))
422
423 " Test undofile() with 'undodir' set to to an existing directory.
424 call mkdir('Xundodir')
425 set undodir=Xundodir
426 let cwd = getcwd()
427 if has('win32')
428 " Replace windows drive such as C:... into C%...
429 let cwd = substitute(cwd, '^\([A-Z]\):', '\1%', 'g')
430 endif
431 let cwd = substitute(cwd . '/Xundofoo', '/', '%', 'g')
432 if has('persistent_undo')
433 call assert_equal('Xundodir/' . cwd, undofile('Xundofoo'))
434 else
435 call assert_equal('', undofile('Xundofoo'))
436 endif
437 call assert_equal('', undofile(''))
438 call delete('Xundodir', 'd')
439
440 " Test undofile() with 'undodir' set to a non-existing directory.
441 call assert_equal('', undofile('Xundofoo'))
442
443 set undodir&
444 endfunc