Skip to content

Commit ee1a2b5

Browse files
committed
patch 8.1.2100: :mksession is not sufficiently tested
Problem: :mksession is not sufficiently tested. Solution: Add more test cases. (Yegappan Lakshmanan, closes #4993)
1 parent b7a97ef commit ee1a2b5

2 files changed

Lines changed: 116 additions & 5 deletions

File tree

src/testdir/test_mksession.vim

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,17 @@ endfunc
156156
func Test_mksession_arglist()
157157
%argdel
158158
next file1 file2 file3 file4
159+
new
160+
next | next
159161
mksession! Xtest_mks.out
160162
source Xtest_mks.out
161163
call assert_equal(['file1', 'file2', 'file3', 'file4'], argv())
164+
call assert_equal(2, argidx())
165+
wincmd w
166+
call assert_equal(0, argidx())
162167

163168
call delete('Xtest_mks.out')
169+
enew | only
164170
argdel *
165171
endfunc
166172

@@ -541,24 +547,28 @@ func Test_mksession_globals()
541547
set sessionoptions+=globals
542548

543549
" create different global variables
544-
let g:Global_string = "Sun is shining"
550+
let g:Global_string = "Sun is shining\r\n"
545551
let g:Global_count = 100
546552
let g:Global_pi = 3.14
553+
let g:Global_neg_float = -2.68
547554

548555
mksession! Xtest_mks.out
549556

550557
unlet g:Global_string
551558
unlet g:Global_count
552559
unlet g:Global_pi
560+
unlet g:Global_neg_float
553561

554562
source Xtest_mks.out
555-
call assert_equal("Sun is shining", g:Global_string)
563+
call assert_equal("Sun is shining\r\n", g:Global_string)
556564
call assert_equal(100, g:Global_count)
557565
call assert_equal(3.14, g:Global_pi)
566+
call assert_equal(-2.68, g:Global_neg_float)
558567

559568
unlet g:Global_string
560569
unlet g:Global_count
561570
unlet g:Global_pi
571+
unlet g:Global_neg_float
562572
call delete('Xtest_mks.out')
563573
set sessionoptions&
564574
endfunc
@@ -639,20 +649,120 @@ func Test_mksession_resize()
639649
for line in lines
640650
if line =~ '^set lines='
641651
let found_resize = v:true
652+
break
642653
endif
643654
endfor
644-
call assert_equal(v:false, found_resize)
655+
call assert_false(found_resize)
645656
let lines = readfile('Xtest_mks2.out')
646657
let found_resize = v:false
647658
for line in lines
648659
if line =~ '^set lines='
649660
let found_resize = v:true
661+
break
662+
endif
663+
endfor
664+
call assert_true(found_resize)
665+
666+
call delete('Xtest_mks1.out')
667+
call delete('Xtest_mks2.out')
668+
set sessionoptions&
669+
endfunc
670+
671+
" Test for mksession with a named scratch buffer
672+
func Test_mksession_scratch()
673+
enew | only
674+
file Xscratch
675+
set buftype=nofile
676+
mksession! Xtest_mks.out
677+
%bwipe
678+
source Xtest_mks.out
679+
call assert_equal('Xscratch', bufname(''))
680+
call assert_equal('nofile', &buftype)
681+
%bwipe
682+
call delete('Xtest_mks.out')
683+
endfunc
684+
685+
" Test for mksession with fold options
686+
func Test_mksession_foldopt()
687+
set sessionoptions-=options
688+
set sessionoptions+=folds
689+
new
690+
setlocal foldenable
691+
setlocal foldmethod=expr
692+
setlocal foldmarker=<<<,>>>
693+
setlocal foldignore=%
694+
setlocal foldlevel=2
695+
setlocal foldminlines=10
696+
setlocal foldnestmax=15
697+
mksession! Xtest_mks.out
698+
close
699+
%bwipe
700+
701+
source Xtest_mks.out
702+
call assert_true(&foldenable)
703+
call assert_equal('expr', &foldmethod)
704+
call assert_equal('<<<,>>>', &foldmarker)
705+
call assert_equal('%', &foldignore)
706+
call assert_equal(2, &foldlevel)
707+
call assert_equal(10, &foldminlines)
708+
call assert_equal(15, &foldnestmax)
709+
710+
close
711+
%bwipe
712+
set sessionoptions&
713+
endfunc
714+
715+
" Test for mksession with window position
716+
func Test_mksession_winpos()
717+
if !has('gui_running')
718+
" Only applicable in GUI Vim
719+
return
720+
endif
721+
set sessionoptions+=winpos
722+
mksession! Xtest_mks.out
723+
let found_winpos = v:false
724+
let lines = readfile('Xtest_mks.out')
725+
for line in lines
726+
if line =~ '^winpos '
727+
let found_winpos = v:true
728+
break
729+
endif
730+
endfor
731+
call assert_true(found_winpos)
732+
call delete('Xtest_mks.out')
733+
set sessionoptions&
734+
endfunc
735+
736+
" Test for mksession with 'compatible' option
737+
func Test_mksession_compatible()
738+
mksession! Xtest_mks1.out
739+
set compatible
740+
mksession! Xtest_mks2.out
741+
set nocp
742+
743+
let test_success = v:false
744+
let lines = readfile('Xtest_mks1.out')
745+
for line in lines
746+
if line =~ '^if &cp | set nocp | endif'
747+
let test_success = v:true
748+
break
650749
endif
651750
endfor
652-
call assert_equal(v:true, found_resize)
751+
call assert_true(test_success)
752+
753+
let test_success = v:false
754+
let lines = readfile('Xtest_mks2.out')
755+
for line in lines
756+
if line =~ '^if !&cp | set cp | endif'
757+
let test_success = v:true
758+
break
759+
endif
760+
endfor
761+
call assert_true(test_success)
653762

654763
call delete('Xtest_mks1.out')
655764
call delete('Xtest_mks2.out')
765+
set compatible&
656766
set sessionoptions&
657767
endfunc
658768

@@ -698,5 +808,4 @@ func Test_mkvimrc()
698808
call delete('Xtestvimrc')
699809
endfunc
700810

701-
702811
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

754754
static int included_patches[] =
755755
{ /* Add new patch number below this line */
756+
/**/
757+
2100,
756758
/**/
757759
2099,
758760
/**/

0 commit comments

Comments
 (0)