Skip to content

Commit e5fa111

Browse files
committed
patch 8.1.0025: no test for the undofile() function
Problem: No test for the undofile() function. Solution: Add test. (Dominique Pelle, closes #2958)
1 parent 6b69e5c commit e5fa111

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/testdir/test_undo.vim

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ endfunc
8585
func FillBuffer()
8686
for i in range(1,13)
8787
put=i
88-
" Set 'undolevels' to split undo.
88+
" Set 'undolevels' to split undo.
8989
exe "setg ul=" . &g:ul
9090
endfor
9191
endfunc
@@ -193,19 +193,19 @@ func Test_undolist()
193193
new
194194
set ul=100
195195

196-
let a=execute('undolist')
196+
let a = execute('undolist')
197197
call assert_equal("\nNothing to undo", a)
198198

199199
" 1 leaf (2 changes).
200200
call feedkeys('achange1', 'xt')
201201
call feedkeys('achange2', 'xt')
202-
let a=execute('undolist')
202+
let a = execute('undolist')
203203
call assert_match("^\nnumber changes when *saved\n *2 *2 .*$", a)
204204

205205
" 2 leaves.
206206
call feedkeys('u', 'xt')
207207
call feedkeys('achange3\<Esc>', 'xt')
208-
let a=execute('undolist')
208+
let a = execute('undolist')
209209
call assert_match("^\nnumber changes when *saved\n *2 *2 *.*\n *3 *2 .*$", a)
210210
close!
211211
endfunc
@@ -339,7 +339,7 @@ endfunc
339339
" Also test this in an empty buffer.
340340
func Test_cmd_in_reg_undo()
341341
enew!
342-
let @a="Ox\<Esc>jAy\<Esc>kdd"
342+
let @a = "Ox\<Esc>jAy\<Esc>kdd"
343343
edit +/^$ test_undo.vim
344344
normal @au
345345
call assert_equal(0, &modified)
@@ -348,7 +348,7 @@ func Test_cmd_in_reg_undo()
348348
normal @au
349349
call assert_equal(0, &modified)
350350
only!
351-
let @a=''
351+
let @a = ''
352352
endfunc
353353

354354
" This used to cause an illegal memory access
@@ -410,3 +410,35 @@ func Test_redo_empty_line()
410410
exe "norm."
411411
bwipe!
412412
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

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
25,
764766
/**/
765767
24,
766768
/**/

0 commit comments

Comments
 (0)