@@ -85,7 +85,7 @@ endfunc
8585func 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
9191endfunc
@@ -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 (" \n Nothing 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 (" ^\n number 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 (" ^\n number changes when *saved\n *2 *2 *.*\n *3 *2 .*$" , a )
210210 close !
211211endfunc
@@ -339,7 +339,7 @@ endfunc
339339" Also test this in an empty buffer.
340340func 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 @a u
345345 call assert_equal (0 , &modified )
@@ -348,7 +348,7 @@ func Test_cmd_in_reg_undo()
348348 normal @a u
349349 call assert_equal (0 , &modified )
350350 only !
351- let @a = ' '
351+ let @a = ' '
352352endfunc
353353
354354" This used to cause an illegal memory access
@@ -410,3 +410,35 @@ func Test_redo_empty_line()
410410 exe " norm."
411411 bwipe!
412412endfunc
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
0 commit comments