1" Test for :mksession, :mkview and :loadview in latin1 encoding 2 3set encoding=latin1 4scriptencoding latin1 5 6source check.vim 7CheckFeature mksession 8 9source shared.vim 10source term_util.vim 11 12" Test for storing global and local argument list in a session file 13" This one must be done first. 14func Test__mksession_arglocal() 15 enew | only 16 n a b c 17 new 18 arglocal 19 mksession! Xtest_mks.out 20 21 %bwipe! 22 %argdelete 23 argglobal 24 source Xtest_mks.out 25 call assert_equal(2, winnr('$')) 26 call assert_equal(2, arglistid(1)) 27 call assert_equal(0, arglistid(2)) 28 29 %bwipe! 30 %argdelete 31 argglobal 32 call delete('Xtest_mks.out') 33endfunc 34 35func Test_mksession() 36 tabnew 37 let wrap_save = &wrap 38 set sessionoptions=buffers splitbelow fileencoding=latin1 39 call setline(1, [ 40 \ 'start:', 41 \ 'no multibyte chAracter', 42 \ ' one leaDing tab', 43 \ ' four leadinG spaces', 44 \ 'two consecutive tabs', 45 \ 'two tabs in one line', 46 \ 'one � multibyteCharacter', 47 \ 'a� � two multiByte characters', 48 \ 'A��� three mulTibyte characters', 49 \ 'short line', 50 \ ]) 51 let tmpfile = 'Xtemp' 52 exec 'w! ' . tmpfile 53 /^start: 54 set wrap 55 vsplit 56 norm! j16| 57 split 58 norm! j16| 59 split 60 norm! j16| 61 split 62 norm! j8| 63 split 64 norm! j8| 65 split 66 norm! j16| 67 split 68 norm! j16| 69 split 70 norm! j16| 71 split 72 norm! j$ 73 wincmd l 74 75 set nowrap 76 /^start: 77 norm! j16|3zl 78 split 79 norm! j016|3zl 80 split 81 norm! j016|3zl 82 split 83 norm! j08|3zl 84 split 85 norm! j08|3zl 86 split 87 norm! j016|3zl 88 split 89 norm! j016|3zl 90 split 91 norm! j016|3zl 92 split 93 call wincol() 94 mksession! Xtest_mks.out 95 let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "\\(^ *normal! [0$]\\|^ *exe ''normal!\\)"') 96 let expected = [ 97 \ 'normal! 016|', 98 \ 'normal! 016|', 99 \ 'normal! 016|', 100 \ 'normal! 08|', 101 \ 'normal! 08|', 102 \ 'normal! 016|', 103 \ 'normal! 016|', 104 \ 'normal! 016|', 105 \ 'normal! $', 106 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", 107 \ " normal! 016|", 108 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", 109 \ " normal! 016|", 110 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", 111 \ " normal! 016|", 112 \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'", 113 \ " normal! 08|", 114 \ " exe 'normal! ' . s:c . '|zs' . 8 . '|'", 115 \ " normal! 08|", 116 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", 117 \ " normal! 016|", 118 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", 119 \ " normal! 016|", 120 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", 121 \ " normal! 016|", 122 \ " exe 'normal! ' . s:c . '|zs' . 16 . '|'", 123 \ " normal! 016|" 124 \ ] 125 call assert_equal(expected, li) 126 tabclose! 127 128 call delete('Xtest_mks.out') 129 call delete(tmpfile) 130 let &wrap = wrap_save 131 set sessionoptions& 132endfunc 133 134func Test_mksession_winheight() 135 new 136 set winheight=10 137 set winminheight=2 138 mksession! Xtest_mks.out 139 source Xtest_mks.out 140 141 call delete('Xtest_mks.out') 142endfunc 143 144func Test_mksession_large_winheight() 145 set winheight=999 146 mksession! Xtest_mks_winheight.out 147 set winheight& 148 source Xtest_mks_winheight.out 149 call delete('Xtest_mks_winheight.out') 150endfunc 151 152func Test_mksession_rtp() 153 " TODO: fix problem with backslashes on Win32 154 CheckNotMSWindows 155 156 new 157 let _rtp=&rtp 158 " Make a real long (invalid) runtimepath value, 159 " that should exceed PATH_MAX (hopefully) 160 let newrtp=&rtp.',~'.repeat('/foobar', 1000) 161 let newrtp.=",".expand("$HOME")."/.vim" 162 let &rtp=newrtp 163 164 " determine expected value 165 let expected=split(&rtp, ',') 166 let expected = map(expected, '"set runtimepath+=".v:val') 167 let expected = ['set runtimepath='] + expected 168 let expected = map(expected, {v,w -> substitute(w, $HOME, "~", "g")}) 169 170 mksession! Xtest_mks.out 171 let &rtp=_rtp 172 let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "runtimepath"') 173 call assert_equal(expected, li) 174 175 call delete('Xtest_mks.out') 176endfunc 177 178func Test_mksession_arglist() 179 %argdel 180 next file1 file2 file3 file4 181 new 182 next | next 183 mksession! Xtest_mks.out 184 source Xtest_mks.out 185 call assert_equal(['file1', 'file2', 'file3', 'file4'], argv()) 186 call assert_equal(2, argidx()) 187 wincmd w 188 call assert_equal(0, argidx()) 189 190 call delete('Xtest_mks.out') 191 enew | only 192 argdel * 193endfunc 194 195func Test_mksession_one_buffer_two_windows() 196 edit Xtest1 197 new Xtest2 198 split 199 mksession! Xtest_mks.out 200 let lines = readfile('Xtest_mks.out') 201 let count1 = 0 202 let count2 = 0 203 let count2buf = 0 204 for line in lines 205 if line =~ 'edit \f*Xtest1$' 206 let count1 += 1 207 endif 208 if line =~ 'edit \f\{-}Xtest2' 209 let count2 += 1 210 endif 211 if line =~ 'buffer \f\{-}Xtest2' 212 let count2buf += 1 213 endif 214 endfor 215 call assert_equal(1, count1, 'Xtest1 count') 216 call assert_equal(2, count2, 'Xtest2 count') 217 call assert_equal(2, count2buf, 'Xtest2 buffer count') 218 219 close 220 bwipe! 221 call delete('Xtest_mks.out') 222endfunc 223 224func Test_mksession_lcd_multiple_tabs() 225 tabnew 226 tabnew 227 lcd . 228 tabfirst 229 lcd . 230 mksession! Xtest_mks.out 231 tabonly 232 source Xtest_mks.out 233 call assert_true(haslocaldir(), 'Tab 1 localdir') 234 tabnext 2 235 call assert_true(!haslocaldir(), 'Tab 2 localdir') 236 tabnext 3 237 call assert_true(haslocaldir(), 'Tab 3 localdir') 238 call delete('Xtest_mks.out') 239endfunc 240 241" Test for tabpage-local directory 242func Test_mksession_tcd_multiple_tabs() 243 let save_cwd = getcwd() 244 call mkdir('Xtopdir') 245 cd Xtopdir 246 call mkdir('Xtabdir1') 247 call mkdir('Xtabdir2') 248 call mkdir('Xtabdir3') 249 call mkdir('Xwindir1') 250 call mkdir('Xwindir2') 251 call mkdir('Xwindir3') 252 tcd Xtabdir1 253 botright new 254 wincmd t 255 lcd ../Xwindir1 256 tabnew 257 tcd ../Xtabdir2 258 botright new 259 lcd ../Xwindir2 260 tabnew 261 tcd ../Xtabdir3 262 botright new 263 lcd ../Xwindir3 264 tabfirst 265 1wincmd w 266 mksession! Xtest_mks.out 267 only | tabonly 268 source Xtest_mks.out 269 call assert_equal('Xtabdir1', fnamemodify(getcwd(-1, 1), ':t')) 270 call assert_equal('Xwindir1', fnamemodify(getcwd(1, 1), ':t')) 271 call assert_equal('Xtabdir1', fnamemodify(getcwd(2, 1), ':t')) 272 call assert_equal('Xtabdir2', fnamemodify(getcwd(-1, 2), ':t')) 273 call assert_equal('Xtabdir2', fnamemodify(getcwd(1, 2), ':t')) 274 call assert_equal('Xwindir2', fnamemodify(getcwd(2, 2), ':t')) 275 call assert_equal('Xtabdir3', fnamemodify(getcwd(-1, 3), ':t')) 276 call assert_equal('Xtabdir3', fnamemodify(getcwd(1, 3), ':t')) 277 call assert_equal('Xwindir3', fnamemodify(getcwd(2, 3), ':t')) 278 %bwipe 279 call chdir(save_cwd) 280 call delete("Xtopdir", "rf") 281endfunc 282 283func Test_mksession_blank_tabs() 284 tabnew 285 tabnew 286 tabnew 287 tabnext 3 288 mksession! Xtest_mks.out 289 tabnew 290 tabnew 291 tabnext 2 292 source Xtest_mks.out 293 call assert_equal(4, tabpagenr('$'), 'session restore should restore number of tabs') 294 call assert_equal(3, tabpagenr(), 'session restore should restore the active tab') 295 call delete('Xtest_mks.out') 296endfunc 297 298func Test_mksession_buffer_count() 299 set hidden 300 301 " Edit exactly three files in the current session. 302 %bwipe! 303 e Xfoo | tabe Xbar | tabe Xbaz 304 tabdo write 305 mksession! Xtest_mks.out 306 307 " Verify that loading the session does not create additional buffers. 308 %bwipe! 309 source Xtest_mks.out 310 call assert_equal(3, len(getbufinfo())) 311 312 " Clean up. 313 call delete('Xfoo') 314 call delete('Xbar') 315 call delete('Xbaz') 316 call delete('Xtest_mks.out') 317 %bwipe! 318 set hidden& 319endfunc 320 321if has('extra_search') 322 323func Test_mksession_hlsearch() 324 set hlsearch 325 mksession! Xtest_mks.out 326 nohlsearch 327 source Xtest_mks.out 328 call assert_equal(1, v:hlsearch, 'session should restore search highlighting state') 329 nohlsearch 330 mksession! Xtest_mks.out 331 source Xtest_mks.out 332 call assert_equal(0, v:hlsearch, 'session should restore search highlighting state') 333 call delete('Xtest_mks.out') 334endfunc 335 336endif 337 338 339func Test_mksession_blank_windows() 340 split 341 split 342 split 343 3 wincmd w 344 mksession! Xtest_mks.out 345 split 346 split 347 2 wincmd w 348 source Xtest_mks.out 349 call assert_equal(4, winnr('$'), 'session restore should restore number of windows') 350 call assert_equal(3, winnr(), 'session restore should restore the active window') 351 call delete('Xtest_mks.out') 352endfunc 353 354func Test_mksession_terminal_shell() 355 CheckFeature terminal 356 CheckFeature quickfix 357 358 terminal 359 mksession! Xtest_mks.out 360 let lines = readfile('Xtest_mks.out') 361 let term_cmd = '' 362 for line in lines 363 if line =~ '^terminal' 364 let term_cmd = line 365 elseif line =~ 'badd.*' . &shell 366 call assert_report('unexpected shell line: ' . line) 367 endif 368 endfor 369 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+\s*.*$', term_cmd) 370 371 call StopShellInTerminal(bufnr('%')) 372 call delete('Xtest_mks.out') 373endfunc 374 375func Test_mksession_terminal_no_restore_cmdarg() 376 CheckFeature terminal 377 378 terminal ++norestore 379 mksession! Xtest_mks.out 380 let lines = readfile('Xtest_mks.out') 381 let term_cmd = '' 382 for line in lines 383 if line =~ '^terminal' 384 call assert_report('session must not restore terminal') 385 endif 386 endfor 387 388 call StopShellInTerminal(bufnr('%')) 389 call delete('Xtest_mks.out') 390endfunc 391 392func Test_mksession_terminal_no_restore_funcarg() 393 CheckFeature terminal 394 395 call term_start(&shell, {'norestore': 1}) 396 mksession! Xtest_mks.out 397 let lines = readfile('Xtest_mks.out') 398 let term_cmd = '' 399 for line in lines 400 if line =~ '^terminal' 401 call assert_report('session must not restore terminal') 402 endif 403 endfor 404 405 call StopShellInTerminal(bufnr('%')) 406 call delete('Xtest_mks.out') 407endfunc 408 409func Test_mksession_terminal_no_restore_func() 410 CheckFeature terminal 411 412 terminal 413 call term_setrestore(bufnr('%'), 'NONE') 414 mksession! Xtest_mks.out 415 let lines = readfile('Xtest_mks.out') 416 let term_cmd = '' 417 for line in lines 418 if line =~ '^terminal' 419 call assert_report('session must not restore terminal') 420 endif 421 endfor 422 423 call StopShellInTerminal(bufnr('%')) 424 call delete('Xtest_mks.out') 425endfunc 426 427func Test_mksession_terminal_no_ssop() 428 CheckFeature terminal 429 430 terminal 431 set sessionoptions-=terminal 432 mksession! Xtest_mks.out 433 let lines = readfile('Xtest_mks.out') 434 let term_cmd = '' 435 for line in lines 436 if line =~ '^terminal' 437 call assert_report('session must not restore terminal') 438 endif 439 endfor 440 441 call StopShellInTerminal(bufnr('%')) 442 call delete('Xtest_mks.out') 443 set sessionoptions& 444endfunc 445 446func Test_mksession_terminal_restore_other() 447 CheckFeature terminal 448 CheckFeature quickfix 449 450 terminal 451 eval bufnr('%')->term_setrestore('other') 452 mksession! Xtest_mks.out 453 let lines = readfile('Xtest_mks.out') 454 let term_cmd = '' 455 for line in lines 456 if line =~ '^terminal' 457 let term_cmd = line 458 endif 459 endfor 460 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+.*other', term_cmd) 461 462 call StopShellInTerminal(bufnr('%')) 463 call delete('Xtest_mks.out') 464endfunc 465 466func Test_mksession_terminal_shared_windows() 467 CheckFeature terminal 468 469 terminal 470 let term_buf = bufnr() 471 new 472 execute "buffer" term_buf 473 mksession! Xtest_mks.out 474 475 let lines = readfile('Xtest_mks.out') 476 let found_creation = 0 477 let found_use = 0 478 479 for line in lines 480 if line =~ '^terminal' 481 let found_creation = 1 482 call assert_match('terminal ++curwin ++cols=\d\+ ++rows=\d\+', line) 483 elseif line =~ "^execute 'buffer ' . s:term_buf_" . term_buf . "$" 484 let found_use = 1 485 endif 486 endfor 487 488 call assert_true(found_creation && found_use) 489 490 call StopShellInTerminal(term_buf) 491 call delete('Xtest_mks.out') 492endfunc 493 494func Test_mkview_terminal_windows() 495 CheckFeature terminal 496 497 " create two window on the same terminal to check this is handled OK 498 terminal 499 let term_buf = bufnr() 500 exe 'sbuf ' .. term_buf 501 mkview! Xtestview 502 503 call StopShellInTerminal(term_buf) 504 call delete('Xtestview') 505endfunc 506 507func Test_mkview_open_folds() 508 enew! 509 510 call append(0, ['a', 'b', 'c']) 511 1,3fold 512 " zR affects 'foldlevel', make sure the option is applied after the folds 513 " have been recreated. 514 normal zR 515 write! Xtestfile 516 517 call assert_equal(-1, foldclosed(1)) 518 call assert_equal(-1, foldclosed(2)) 519 call assert_equal(-1, foldclosed(3)) 520 521 mkview! Xtestview 522 source Xtestview 523 524 call assert_equal(-1, foldclosed(1)) 525 call assert_equal(-1, foldclosed(2)) 526 call assert_equal(-1, foldclosed(3)) 527 528 call delete('Xtestview') 529 call delete('Xtestfile') 530 %bwipe 531endfunc 532 533func Test_mkview_no_balt() 534 edit Xtestfile1 535 edit Xtestfile2 536 537 mkview! Xtestview 538 bdelete Xtestfile1 539 540 source Xtestview 541 call assert_equal(0, buflisted('Xtestfile1')) 542 543 call delete('Xtestview') 544 %bwipe 545endfunc 546 547" Test :mkview with a file argument. 548func Test_mkview_file() 549 " Create a view with line number and a fold. 550 help :mkview 551 set number 552 norm! V}zf0 553 let pos = getpos('.') 554 let linefoldclosed1 = foldclosed('.') 555 mkview! Xview 556 set nonumber 557 norm! zrj 558 " We can close the help window, as mkview with a file name should 559 " generate a command to edit the file. 560 helpclose 561 562 source Xview 563 call assert_equal(1, &number) 564 call assert_match('\*:mkview\*$', getline('.')) 565 call assert_equal(pos, getpos('.')) 566 call assert_equal(linefoldclosed1, foldclosed('.')) 567 568 " Creating a view again with the same file name should fail (file 569 " already exists). But with a !, the previous view should be 570 " overwritten without error. 571 help :loadview 572 call assert_fails('mkview Xview', 'E189:') 573 call assert_match('\*:loadview\*$', getline('.')) 574 mkview! Xview 575 call assert_match('\*:loadview\*$', getline('.')) 576 577 call delete('Xview') 578 bwipe 579endfunc 580 581" Test :mkview and :loadview with a custom 'viewdir'. 582func Test_mkview_loadview_with_viewdir() 583 set viewdir=Xviewdir 584 585 help :mkview 586 set number 587 norm! V}zf 588 let pos = getpos('.') 589 let linefoldclosed1 = foldclosed('.') 590 mkview 1 591 set nonumber 592 norm! zrj 593 594 loadview 1 595 596 " The directory Xviewdir/ should have been created and the view 597 " should be stored in that directory. 598 call assert_equal('Xviewdir/' . 599 \ substitute( 600 \ substitute( 601 \ expand('%:p'), '/', '=+', 'g'), ':', '=-', 'g') . '=1.vim', 602 \ glob('Xviewdir/*')) 603 call assert_equal(1, &number) 604 call assert_match('\*:mkview\*$', getline('.')) 605 call assert_equal(pos, getpos('.')) 606 call assert_equal(linefoldclosed1, foldclosed('.')) 607 608 call delete('Xviewdir', 'rf') 609 set viewdir& 610 helpclose 611endfunc 612 613func Test_mkview_no_file_name() 614 new 615 " :mkview or :mkview {nr} should fail in a unnamed buffer. 616 call assert_fails('mkview', 'E32:') 617 call assert_fails('mkview 1', 'E32:') 618 619 " :mkview {file} should succeed in a unnamed buffer. 620 mkview Xview 621 help 622 source Xview 623 call assert_equal('', bufname('%')) 624 625 call delete('Xview') 626 %bwipe 627endfunc 628 629func Test_mkview_loadview_jumplist() 630 set viewdir=Xviewdir 631 au BufWinLeave * silent mkview 632 au BufWinEnter * silent loadview 633 634 edit Xfile1 635 call setline(1, ['a', 'bbbbbbb', 'c']) 636 normal j3l 637 call assert_equal([2, 4], getcurpos()[1:2]) 638 write 639 640 edit Xfile2 641 call setline(1, ['d', 'eeeeeee', 'f']) 642 normal j5l 643 call assert_equal([2, 6], getcurpos()[1:2]) 644 write 645 646 edit Xfile3 647 call setline(1, ['g', 'h', 'iiiii']) 648 normal jj3l 649 call assert_equal([3, 4], getcurpos()[1:2]) 650 write 651 652 edit Xfile1 653 call assert_equal([2, 4], getcurpos()[1:2]) 654 edit Xfile2 655 call assert_equal([2, 6], getcurpos()[1:2]) 656 edit Xfile3 657 call assert_equal([3, 4], getcurpos()[1:2]) 658 659 exe "normal \<C-O>" 660 call assert_equal('Xfile2', expand('%')) 661 call assert_equal([2, 6], getcurpos()[1:2]) 662 exe "normal \<C-O>" 663 call assert_equal('Xfile1', expand('%')) 664 call assert_equal([2, 4], getcurpos()[1:2]) 665 666 au! BufWinLeave 667 au! BufWinEnter 668 bwipe! 669 call delete('Xviewdir', 'rf') 670 call delete('Xfile1') 671 call delete('Xfile2') 672 call delete('Xfile3') 673 set viewdir& 674endfunc 675 676" A clean session (one empty buffer, one window, and one tab) should not 677" set any error messages when sourced because no commands should fail. 678func Test_mksession_no_errmsg() 679 let v:errmsg = '' 680 %bwipe! 681 mksession! Xtest_mks.out 682 source Xtest_mks.out 683 call assert_equal('', v:errmsg) 684 call delete('Xtest_mks.out') 685endfunc 686 687func Test_mksession_quote_in_filename() 688 " only Unix can handle this weird filename 689 CheckUnix 690 691 let v:errmsg = '' 692 %bwipe! 693 split another 694 split x'y\"z 695 mksession! Xtest_mks_quoted.out 696 %bwipe! 697 source Xtest_mks_quoted.out 698 call assert_true(bufexists("x'y\"z")) 699 700 %bwipe! 701 call delete('Xtest_mks_quoted.out') 702endfunc 703 704" Test for storing global variables in a session file 705func Test_mksession_globals() 706 set sessionoptions+=globals 707 708 " create different global variables 709 let g:Global_string = "Sun is shining\r\n" 710 let g:Global_count = 100 711 let g:Global_pi = 3.14 712 let g:Global_neg_float = -2.68 713 714 mksession! Xtest_mks.out 715 716 unlet g:Global_string 717 unlet g:Global_count 718 unlet g:Global_pi 719 unlet g:Global_neg_float 720 721 source Xtest_mks.out 722 call assert_equal("Sun is shining\r\n", g:Global_string) 723 call assert_equal(100, g:Global_count) 724 call assert_equal(3.14, g:Global_pi) 725 call assert_equal(-2.68, g:Global_neg_float) 726 727 unlet g:Global_string 728 unlet g:Global_count 729 unlet g:Global_pi 730 unlet g:Global_neg_float 731 call delete('Xtest_mks.out') 732 set sessionoptions& 733endfunc 734 735" Test for changing backslash to forward slash in filenames 736func Test_mksession_slash() 737 if exists('+shellslash') 738 throw 'Skipped: cannot use backslash in file name' 739 endif 740 enew 741 %bwipe! 742 e a\\b\\c 743 mksession! Xtest_mks1.out 744 set sessionoptions+=slash 745 mksession! Xtest_mks2.out 746 747 %bwipe! 748 source Xtest_mks1.out 749 call assert_equal('a\b\c', bufname('')) 750 %bwipe! 751 source Xtest_mks2.out 752 call assert_equal('a/b/c', bufname('')) 753 754 %bwipe! 755 call delete('Xtest_mks1.out') 756 call delete('Xtest_mks2.out') 757 set sessionoptions& 758endfunc 759 760" Test for changing directory to the session file directory 761func Test_mksession_sesdir() 762 let save_cwd = getcwd() 763 call mkdir('Xproj') 764 mksession! Xproj/Xtest_mks1.out 765 set sessionoptions-=curdir 766 set sessionoptions+=sesdir 767 mksession! Xproj/Xtest_mks2.out 768 769 source Xproj/Xtest_mks1.out 770 call assert_equal('testdir', fnamemodify(getcwd(), ':t')) 771 source Xproj/Xtest_mks2.out 772 call assert_equal('Xproj', fnamemodify(getcwd(), ':t')) 773 call chdir(save_cwd) 774 %bwipe 775 776 set sessionoptions& 777 call delete('Xproj', 'rf') 778endfunc 779 780" Test for storing the 'lines' and 'columns' settings 781func Test_mksession_resize() 782 mksession! Xtest_mks1.out 783 set sessionoptions+=resize 784 mksession! Xtest_mks2.out 785 786 let lines = readfile('Xtest_mks1.out') 787 let found_resize = v:false 788 for line in lines 789 if line =~ '^set lines=' 790 let found_resize = v:true 791 break 792 endif 793 endfor 794 call assert_false(found_resize) 795 let lines = readfile('Xtest_mks2.out') 796 let found_resize = v:false 797 for line in lines 798 if line =~ '^set lines=' 799 let found_resize = v:true 800 break 801 endif 802 endfor 803 call assert_true(found_resize) 804 805 call delete('Xtest_mks1.out') 806 call delete('Xtest_mks2.out') 807 set sessionoptions& 808endfunc 809 810" Test for mksession with a named scratch buffer 811func Test_mksession_scratch() 812 enew | only 813 file Xscratch 814 set buftype=nofile 815 mksession! Xtest_mks.out 816 %bwipe 817 source Xtest_mks.out 818 call assert_equal('Xscratch', bufname('')) 819 call assert_equal('nofile', &buftype) 820 %bwipe 821 call delete('Xtest_mks.out') 822endfunc 823 824" Test for mksession with fold options 825func Test_mksession_foldopt() 826 set sessionoptions-=options 827 set sessionoptions+=folds 828 new 829 setlocal foldenable 830 setlocal foldmethod=expr 831 setlocal foldmarker=<<<,>>> 832 setlocal foldignore=% 833 setlocal foldlevel=2 834 setlocal foldminlines=10 835 setlocal foldnestmax=15 836 mksession! Xtest_mks.out 837 close 838 %bwipe 839 840 source Xtest_mks.out 841 call assert_true(&foldenable) 842 call assert_equal('expr', &foldmethod) 843 call assert_equal('<<<,>>>', &foldmarker) 844 call assert_equal('%', &foldignore) 845 call assert_equal(2, &foldlevel) 846 call assert_equal(10, &foldminlines) 847 call assert_equal(15, &foldnestmax) 848 849 close 850 %bwipe 851 set sessionoptions& 852endfunc 853 854" Test for mksession with window position 855func Test_mksession_winpos() 856 " Only applicable in GUI Vim 857 CheckGui 858 859 set sessionoptions+=winpos 860 mksession! Xtest_mks.out 861 let found_winpos = v:false 862 let lines = readfile('Xtest_mks.out') 863 for line in lines 864 if line =~ '^winpos ' 865 let found_winpos = v:true 866 break 867 endif 868 endfor 869 call assert_true(found_winpos) 870 call delete('Xtest_mks.out') 871 set sessionoptions& 872endfunc 873 874" Test for mksession with 'compatible' option 875func Test_mksession_compatible() 876 mksession! Xtest_mks1.out 877 set compatible 878 mksession! Xtest_mks2.out 879 set nocp 880 881 let test_success = v:false 882 let lines = readfile('Xtest_mks1.out') 883 for line in lines 884 if line =~ '^if &cp | set nocp | endif' 885 let test_success = v:true 886 break 887 endif 888 endfor 889 call assert_true(test_success) 890 891 let test_success = v:false 892 let lines = readfile('Xtest_mks2.out') 893 for line in lines 894 if line =~ '^if !&cp | set cp | endif' 895 let test_success = v:true 896 break 897 endif 898 endfor 899 call assert_true(test_success) 900 901 call delete('Xtest_mks1.out') 902 call delete('Xtest_mks2.out') 903 set compatible& 904 set sessionoptions& 905endfunc 906 907func s:ClearMappings() 908 mapclear 909 omapclear 910 mapclear! 911 lmapclear 912 tmapclear 913endfunc 914 915func Test_mkvimrc() 916 let entries = [ 917 \ ['', 'nothing', '<Nop>'], 918 \ ['n', 'normal', 'NORMAL'], 919 \ ['v', 'visual', 'VISUAL'], 920 \ ['s', 'select', 'SELECT'], 921 \ ['x', 'visualonly', 'VISUALONLY'], 922 \ ['o', 'operator', 'OPERATOR'], 923 \ ['i', 'insert', 'INSERT'], 924 \ ['l', 'lang', 'LANG'], 925 \ ['c', 'command', 'COMMAND'], 926 \ ['t', 'terminal', 'TERMINAL'], 927 \ ] 928 for entry in entries 929 exe entry[0] .. 'map ' .. entry[1] .. ' ' .. entry[2] 930 endfor 931 932 mkvimrc Xtestvimrc 933 934 call s:ClearMappings() 935 for entry in entries 936 call assert_equal('', maparg(entry[1], entry[0])) 937 endfor 938 939 source Xtestvimrc 940 941 for entry in entries 942 call assert_equal(entry[2], maparg(entry[1], entry[0])) 943 endfor 944 945 call s:ClearMappings() 946 call delete('Xtestvimrc') 947endfunc 948 949func Test_scrolloff() 950 set sessionoptions+=localoptions 951 setlocal so=1 siso=1 952 mksession! Xtest_mks.out 953 setlocal so=-1 siso=-1 954 source Xtest_mks.out 955 call assert_equal(1, &l:so) 956 call assert_equal(1, &l:siso) 957 call delete('Xtest_mks.out') 958 setlocal so& siso& 959 set sessionoptions& 960endfunc 961 962func Test_altfile() 963 edit Xone 964 split Xtwo 965 edit Xtwoalt 966 edit # 967 wincmd w 968 edit Xonealt 969 edit # 970 mksession! Xtest_altfile 971 only 972 bwipe Xonealt 973 bwipe Xtwoalt 974 bwipe! 975 source Xtest_altfile 976 call assert_equal('Xone', bufname()) 977 call assert_equal('Xonealt', bufname('#')) 978 wincmd w 979 call assert_equal('Xtwo', bufname()) 980 call assert_equal('Xtwoalt', bufname('#')) 981 only 982 bwipe! 983 call delete('Xtest_altfile') 984endfunc 985 986" vim: shiftwidth=2 sts=2 expandtab 987