@@ -311,5 +311,86 @@ endfunc
311311
312312endif " has('terminal')
313313
314+ " Test :mkview with a file argument.
315+ func Test_mkview_file ()
316+ " Create a view with line number and a fold.
317+ help :mkview
318+ set number
319+ norm! V}zf
320+ let pos = getpos (' .' )
321+ let linefoldclosed1 = foldclosed (' .' )
322+ mkview ! Xview
323+ set nonumber
324+ norm! zrj
325+ " We can close the help window, as mkview with a file name should
326+ " generate a command to edit the file.
327+ helpclose
328+
329+ source Xview
330+ call assert_equal (1 , &number )
331+ call assert_match (' \*:mkview\*$' , getline (' .' ))
332+ call assert_equal (pos, getpos (' .' ))
333+ call assert_equal (linefoldclosed1, foldclosed (' .' ))
334+
335+ " Creating a view again with the same file name should fail (file
336+ " already exists). But with a !, the previous view should be
337+ " overwritten without error.
338+ help :loadview
339+ call assert_fails (' mkview Xview' , ' E189:' )
340+ call assert_match (' \*:loadview\*$' , getline (' .' ))
341+ mkview ! Xview
342+ call assert_match (' \*:loadview\*$' , getline (' .' ))
343+
344+ call delete (' Xview' )
345+ bwipe
346+ endfunc
347+
348+ " Test :mkview and :loadview with a custom 'viewdir'.
349+ func Test_mkview_loadview_with_viewdir ()
350+ set viewdir = Xviewdir
351+
352+ help :mkview
353+ set number
354+ norm! V}zf
355+ let pos = getpos (' .' )
356+ let linefoldclosed1 = foldclosed (' .' )
357+ mkview 1
358+ set nonumber
359+ norm! zrj
360+
361+ loadview 1
362+
363+ " The directory Xviewdir/ should have been created and the view
364+ " should be stored in that directory.
365+ call assert_equal (' Xviewdir/' .
366+ \ substitute (
367+ \ substitute (
368+ \ expand (' %:p' ), ' /' , ' =+' , ' g' ), ' :' , ' =-' , ' g' ) . ' =1.vim' ,
369+ \ glob (' Xviewdir/*' ))
370+ call assert_equal (1 , &number )
371+ call assert_match (' \*:mkview\*$' , getline (' .' ))
372+ call assert_equal (pos, getpos (' .' ))
373+ call assert_equal (linefoldclosed1, foldclosed (' .' ))
374+
375+ call delete (' Xviewdir' , ' rf' )
376+ set viewdir &
377+ helpclose
378+ endfunc
379+
380+ func Test_mkview_no_file_name ()
381+ new
382+ " :mkview or :mkview {nr} should fail in a unnamed buffer.
383+ call assert_fails (' mkview' , ' E32:' )
384+ call assert_fails (' mkview 1' , ' E32:' )
385+
386+ " :mkview {file} should succeed in a unnamed buffer.
387+ mkview Xview
388+ help
389+ source Xview
390+ call assert_equal (' ' , bufname (' %' ))
391+
392+ call delete (' Xview' )
393+ % bwipe
394+ endfunc
314395
315396" vim: shiftwidth = 2 sts = 2 expandtab
0 commit comments