1" Test commands that are not compiled in a :def function 2 3source check.vim 4source vim9.vim 5source term_util.vim 6source view_util.vim 7 8def Test_vim9cmd() 9 var lines =<< trim END 10 vim9cmd var x = 123 11 let s:y = 'yes' 12 vim9c assert_equal(123, x) 13 vim9cm assert_equal('yes', y) 14 END 15 CheckScriptSuccess(lines) 16enddef 17 18def Test_edit_wildcards() 19 var filename = 'Xtest' 20 edit `=filename` 21 assert_equal('Xtest', bufname()) 22 23 var filenr = 123 24 edit Xtest`=filenr` 25 assert_equal('Xtest123', bufname()) 26 27 filenr = 77 28 edit `=filename``=filenr` 29 assert_equal('Xtest77', bufname()) 30 31 edit X`=filename`xx`=filenr`yy 32 assert_equal('XXtestxx77yy', bufname()) 33 34 CheckDefFailure(['edit `=xxx`'], 'E1001:') 35 CheckDefFailure(['edit `="foo"'], 'E1083:') 36enddef 37 38def Test_expand_alternate_file() 39 var lines =<< trim END 40 edit Xfileone 41 var bone = bufnr() 42 edit Xfiletwo 43 var btwo = bufnr() 44 edit Xfilethree 45 var bthree = bufnr() 46 47 edit # 48 assert_equal(bthree, bufnr()) 49 edit %% 50 assert_equal(btwo, bufnr()) 51 edit %% # comment 52 assert_equal(bthree, bufnr()) 53 edit %%yy 54 assert_equal('Xfiletwoyy', bufname()) 55 56 exe "edit %%" .. bone 57 assert_equal(bone, bufnr()) 58 exe "edit %%" .. btwo .. "xx" 59 assert_equal('Xfiletwoxx', bufname()) 60 61 next Xfileone Xfiletwo Xfilethree 62 assert_equal('Xfileone', argv(0)) 63 assert_equal('Xfiletwo', argv(1)) 64 assert_equal('Xfilethree', argv(2)) 65 next %%%zz 66 assert_equal('Xfileone', argv(0)) 67 assert_equal('Xfiletwo', argv(1)) 68 assert_equal('Xfilethreezz', argv(2)) 69 70 v:oldfiles = ['Xonefile', 'Xtwofile'] 71 edit %%<1 72 assert_equal('Xonefile', bufname()) 73 edit %%<2 74 assert_equal('Xtwofile', bufname()) 75 assert_fails('edit %%<3', 'E684:') 76 77 edit Xfileone.vim 78 edit Xfiletwo 79 edit %%:r 80 assert_equal('Xfileone', bufname()) 81 82 assert_false(bufexists('altfoo')) 83 edit altfoo 84 edit bar 85 assert_true(bufexists('altfoo')) 86 assert_true(buflisted('altfoo')) 87 bdel %% 88 assert_true(bufexists('altfoo')) 89 assert_false(buflisted('altfoo')) 90 bwipe! altfoo 91 bwipe! bar 92 END 93 CheckDefAndScriptSuccess(lines) 94enddef 95 96def Test_global_backtick_expansion() 97 new 98 setline(1, 'xx') 99 var name = 'foobar' 100 g/^xx/s/.*/`=name` 101 assert_equal('foobar', getline(1)) 102 bwipe! 103enddef 104 105def Test_folddo_backtick_expansion() 106 new 107 var name = 'xxx' 108 folddoopen edit `=name` 109 assert_equal('xxx', bufname()) 110 bwipe! 111 112 new 113 setline(1, ['one', 'two']) 114 set nomodified 115 :1,2fold 116 foldclose 117 folddoclose edit `=name` 118 assert_equal('xxx', bufname()) 119 bwipe! 120enddef 121 122def Test_hardcopy_wildcards() 123 CheckUnix 124 CheckFeature postscript 125 126 var outfile = 'print' 127 hardcopy > X`=outfile`.ps 128 assert_true(filereadable('Xprint.ps')) 129 130 delete('Xprint.ps') 131enddef 132 133def Test_syn_include_wildcards() 134 writefile(['syn keyword Found found'], 'Xthemine.vim') 135 var save_rtp = &rtp 136 &rtp = '.' 137 138 var fname = 'mine' 139 syn include @Group Xthe`=fname`.vim 140 assert_match('Found.* contained found', execute('syn list Found')) 141 142 &rtp = save_rtp 143 delete('Xthemine.vim') 144enddef 145 146def Test_echo_linebreak() 147 var lines =<< trim END 148 vim9script 149 redir @a 150 echo 'one' 151 .. 'two' 152 redir END 153 assert_equal("\nonetwo", @a) 154 END 155 CheckScriptSuccess(lines) 156 157 lines =<< trim END 158 vim9script 159 redir @a 160 echo 11 + 161 77 162 - 22 163 redir END 164 assert_equal("\n66", @a) 165 END 166 CheckScriptSuccess(lines) 167enddef 168 169def Test_condition_types() 170 var lines =<< trim END 171 if 'text' 172 endif 173 END 174 CheckDefAndScriptFailure(lines, 'E1135:', 1) 175 176 lines =<< trim END 177 if [1] 178 endif 179 END 180 CheckDefFailure(lines, 'E1012:', 1) 181 CheckScriptFailure(['vim9script'] + lines, 'E745:', 2) 182 183 lines =<< trim END 184 g:cond = 'text' 185 if g:cond 186 endif 187 END 188 CheckDefExecAndScriptFailure(lines, 'E1135:', 2) 189 190 lines =<< trim END 191 g:cond = 0 192 if g:cond 193 elseif 'text' 194 endif 195 END 196 CheckDefFailure(lines, 'E1012:', 3) 197 CheckScriptFailure(['vim9script'] + lines, 'E1135:', 4) 198 199 lines =<< trim END 200 if g:cond 201 elseif [1] 202 endif 203 END 204 CheckDefFailure(lines, 'E1012:', 2) 205 CheckScriptFailure(['vim9script'] + lines, 'E745:', 3) 206 207 lines =<< trim END 208 g:cond = 'text' 209 if 0 210 elseif g:cond 211 endif 212 END 213 CheckDefExecAndScriptFailure(lines, 'E1135:', 3) 214 215 lines =<< trim END 216 while 'text' 217 endwhile 218 END 219 CheckDefFailure(lines, 'E1012:', 1) 220 CheckScriptFailure(['vim9script'] + lines, 'E1135:', 2) 221 222 lines =<< trim END 223 while [1] 224 endwhile 225 END 226 CheckDefFailure(lines, 'E1012:', 1) 227 CheckScriptFailure(['vim9script'] + lines, 'E745:', 2) 228 229 lines =<< trim END 230 g:cond = 'text' 231 while g:cond 232 endwhile 233 END 234 CheckDefExecAndScriptFailure(lines, 'E1135:', 2) 235enddef 236 237def Test_if_linebreak() 238 var lines =<< trim END 239 vim9script 240 if 1 && 241 true 242 || 1 243 g:res = 42 244 endif 245 assert_equal(42, g:res) 246 END 247 CheckScriptSuccess(lines) 248 unlet g:res 249 250 lines =<< trim END 251 vim9script 252 if 1 && 253 0 254 g:res = 0 255 elseif 0 || 256 0 257 || 1 258 g:res = 12 259 endif 260 assert_equal(12, g:res) 261 END 262 CheckScriptSuccess(lines) 263 unlet g:res 264enddef 265 266def Test_while_linebreak() 267 var lines =<< trim END 268 vim9script 269 var nr = 0 270 while nr < 271 10 + 3 272 nr = nr 273 + 4 274 endwhile 275 assert_equal(16, nr) 276 END 277 CheckScriptSuccess(lines) 278 279 lines =<< trim END 280 vim9script 281 var nr = 0 282 while nr 283 < 284 10 285 + 286 3 287 nr = nr 288 + 289 4 290 endwhile 291 assert_equal(16, nr) 292 END 293 CheckScriptSuccess(lines) 294enddef 295 296def Test_for_linebreak() 297 var lines =<< trim END 298 vim9script 299 var nr = 0 300 for x 301 in 302 [1, 2, 3, 4] 303 nr = nr + x 304 endfor 305 assert_equal(10, nr) 306 END 307 CheckScriptSuccess(lines) 308 309 lines =<< trim END 310 vim9script 311 var nr = 0 312 for x 313 in 314 [1, 2, 315 3, 4 316 ] 317 nr = nr 318 + 319 x 320 endfor 321 assert_equal(10, nr) 322 END 323 CheckScriptSuccess(lines) 324enddef 325 326def MethodAfterLinebreak(arg: string) 327 arg 328 ->setline(1) 329enddef 330 331def Test_method_call_linebreak() 332 var lines =<< trim END 333 vim9script 334 var res = [] 335 func RetArg( 336 arg 337 ) 338 let s:res = a:arg 339 endfunc 340 [1, 341 2, 342 3]->RetArg() 343 assert_equal([1, 2, 3], res) 344 END 345 CheckScriptSuccess(lines) 346 347 lines =<< trim END 348 new 349 var name = [1, 2] 350 name 351 ->copy() 352 ->setline(1) 353 assert_equal(['1', '2'], getline(1, 2)) 354 bwipe! 355 END 356 CheckDefAndScriptSuccess(lines) 357 358 lines =<< trim END 359 new 360 def Foo(): string 361 return 'the text' 362 enddef 363 def Bar(F: func): string 364 return F() 365 enddef 366 def Test() 367 Foo 368 ->Bar() 369 ->setline(1) 370 enddef 371 Test() 372 assert_equal('the text', getline(1)) 373 bwipe! 374 END 375 CheckDefAndScriptSuccess(lines) 376 377 lines =<< trim END 378 new 379 g:shortlist 380 ->copy() 381 ->setline(1) 382 assert_equal(['1', '2'], getline(1, 2)) 383 bwipe! 384 END 385 g:shortlist = [1, 2] 386 CheckDefAndScriptSuccess(lines) 387 unlet g:shortlist 388 389 new 390 MethodAfterLinebreak('foobar') 391 assert_equal('foobar', getline(1)) 392 bwipe! 393 394 lines =<< trim END 395 vim9script 396 def Foo(): string 397 return '# some text' 398 enddef 399 400 def Bar(F: func): string 401 return F() 402 enddef 403 404 Foo 405 ->Bar() 406 ->setline(1) 407 END 408 CheckScriptSuccess(lines) 409 assert_equal('# some text', getline(1)) 410 bwipe! 411enddef 412 413def Test_method_call_whitespace() 414 var lines =<< trim END 415 new 416 var yank = 'text' 417 yank->setline(1) 418 yank ->setline(2) 419 yank-> setline(3) 420 yank -> setline(4) 421 assert_equal(['text', 'text', 'text', 'text'], getline(1, 4)) 422 bwipe! 423 END 424 CheckDefAndScriptSuccess(lines) 425enddef 426 427def Test_skipped_expr_linebreak() 428 if 0 429 var x = [] 430 ->map(() => 0) 431 endif 432enddef 433 434def Test_dict_member() 435 var test: dict<list<number>> = {data: [3, 1, 2]} 436 test.data->sort() 437 assert_equal({data: [1, 2, 3]}, test) 438 test.data 439 ->reverse() 440 assert_equal({data: [3, 2, 1]}, test) 441 442 var lines =<< trim END 443 vim9script 444 var test: dict<list<number>> = {data: [3, 1, 2]} 445 test.data->sort() 446 assert_equal({data: [1, 2, 3]}, test) 447 END 448 CheckScriptSuccess(lines) 449enddef 450 451def Test_bar_after_command() 452 def RedrawAndEcho() 453 var x = 'did redraw' 454 redraw | echo x 455 enddef 456 RedrawAndEcho() 457 assert_match('did redraw', Screenline(&lines)) 458 459 def CallAndEcho() 460 var x = 'did redraw' 461 reg_executing() | echo x 462 enddef 463 CallAndEcho() 464 assert_match('did redraw', Screenline(&lines)) 465 466 if has('unix') 467 # bar in filter write command does not start new command 468 def WriteToShell() 469 new 470 setline(1, 'some text') 471 w !cat | cat > Xoutfile 472 bwipe! 473 enddef 474 WriteToShell() 475 assert_equal(['some text'], readfile('Xoutfile')) 476 delete('Xoutfile') 477 478 # bar in filter read command does not start new command 479 def ReadFromShell() 480 new 481 r! echo hello there | cat > Xoutfile 482 r !echo again | cat >> Xoutfile 483 bwipe! 484 enddef 485 ReadFromShell() 486 assert_equal(['hello there', 'again'], readfile('Xoutfile')) 487 delete('Xoutfile') 488 endif 489enddef 490 491def Test_filter_is_not_modifier() 492 var tags = [{a: 1, b: 2}, {x: 3, y: 4}] 493 filter(tags, ( _, v) => has_key(v, 'x') ? 1 : 0 ) 494 assert_equal([{x: 3, y: 4}], tags) 495enddef 496 497def Test_command_modifier_filter() 498 var lines =<< trim END 499 final expected = "\nType Name Content\n c \"c piyo" 500 @a = 'hoge' 501 @b = 'fuga' 502 @c = 'piyo' 503 504 assert_equal(execute('filter /piyo/ registers abc'), expected) 505 END 506 CheckDefAndScriptSuccess(lines) 507enddef 508 509def Test_win_command_modifiers() 510 assert_equal(1, winnr('$')) 511 512 set splitright 513 vsplit 514 assert_equal(2, winnr()) 515 close 516 aboveleft vsplit 517 assert_equal(1, winnr()) 518 close 519 set splitright& 520 521 vsplit 522 assert_equal(1, winnr()) 523 close 524 belowright vsplit 525 assert_equal(2, winnr()) 526 close 527 rightbelow vsplit 528 assert_equal(2, winnr()) 529 close 530 531 if has('browse') 532 browse set 533 assert_equal('option-window', expand('%')) 534 close 535 endif 536 537 vsplit 538 botright split 539 assert_equal(3, winnr()) 540 assert_equal(&columns, winwidth(0)) 541 close 542 close 543 544 vsplit 545 topleft split 546 assert_equal(1, winnr()) 547 assert_equal(&columns, winwidth(0)) 548 close 549 close 550 551 gettabinfo()->len()->assert_equal(1) 552 tab split 553 gettabinfo()->len()->assert_equal(2) 554 tabclose 555 556 vertical new 557 assert_inrange(&columns / 2 - 2, &columns / 2 + 1, winwidth(0)) 558 close 559enddef 560 561func Test_command_modifier_confirm() 562 CheckNotGui 563 CheckRunVimInTerminal 564 565 " Test for saving all the modified buffers 566 let lines =<< trim END 567 call setline(1, 'changed') 568 def Getout() 569 confirm write Xfile 570 enddef 571 END 572 call writefile(lines, 'Xconfirmscript') 573 call writefile(['empty'], 'Xfile') 574 let buf = RunVimInTerminal('-S Xconfirmscript', {'rows': 8}) 575 call term_sendkeys(buf, ":call Getout()\n") 576 call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000) 577 call term_sendkeys(buf, "y") 578 call WaitForAssert({-> assert_match('(Y)es, \[N\]o: ', term_getline(buf, 8))}, 1000) 579 call term_sendkeys(buf, "\<CR>") 580 call TermWait(buf) 581 call StopVimInTerminal(buf) 582 583 call assert_equal(['changed'], readfile('Xfile')) 584 call delete('Xfile') 585 call delete('.Xfile.swp') " in case Vim was killed 586 call delete('Xconfirmscript') 587endfunc 588 589def Test_command_modifiers_keep() 590 if has('unix') 591 def DoTest(addRflag: bool, keepMarks: bool, hasMarks: bool) 592 new 593 setline(1, ['one', 'two', 'three']) 594 normal 1Gma 595 normal 2Gmb 596 normal 3Gmc 597 if addRflag 598 set cpo+=R 599 else 600 set cpo-=R 601 endif 602 if keepMarks 603 keepmarks :%!cat 604 else 605 :%!cat 606 endif 607 if hasMarks 608 assert_equal(1, line("'a")) 609 assert_equal(2, line("'b")) 610 assert_equal(3, line("'c")) 611 else 612 assert_equal(0, line("'a")) 613 assert_equal(0, line("'b")) 614 assert_equal(0, line("'c")) 615 endif 616 quit! 617 enddef 618 DoTest(false, false, true) 619 DoTest(true, false, false) 620 DoTest(false, true, true) 621 DoTest(true, true, true) 622 set cpo&vim 623 624 new 625 setline(1, ['one', 'two', 'three', 'four']) 626 assert_equal(4, line("$")) 627 normal 1Gma 628 normal 2Gmb 629 normal 3Gmc 630 lockmarks :1,2!wc 631 # line is deleted, marks don't move 632 assert_equal(3, line("$")) 633 assert_equal('four', getline(3)) 634 assert_equal(1, line("'a")) 635 assert_equal(2, line("'b")) 636 assert_equal(3, line("'c")) 637 quit! 638 endif 639 640 edit Xone 641 edit Xtwo 642 assert_equal('Xone', expand('#')) 643 keepalt edit Xthree 644 assert_equal('Xone', expand('#')) 645 646 normal /a*b* 647 assert_equal('a*b*', histget("search")) 648 keeppatterns normal /c*d* 649 assert_equal('a*b*', histget("search")) 650 651 new 652 setline(1, range(10)) 653 :10 654 normal gg 655 assert_equal(10, getpos("''")[1]) 656 keepjumps normal 5G 657 assert_equal(10, getpos("''")[1]) 658 quit! 659enddef 660 661def Test_bar_line_continuation() 662 var lines =<< trim END 663 au BufNewFile Xfile g:readFile = 1 664 | g:readExtra = 2 665 g:readFile = 0 666 g:readExtra = 0 667 edit Xfile 668 assert_equal(1, g:readFile) 669 assert_equal(2, g:readExtra) 670 bwipe! 671 au! BufNewFile 672 673 au BufNewFile Xfile g:readFile = 1 674 | g:readExtra = 2 675 | g:readMore = 3 676 g:readFile = 0 677 g:readExtra = 0 678 g:readMore = 0 679 edit Xfile 680 assert_equal(1, g:readFile) 681 assert_equal(2, g:readExtra) 682 assert_equal(3, g:readMore) 683 bwipe! 684 au! BufNewFile 685 unlet g:readFile 686 unlet g:readExtra 687 unlet g:readMore 688 END 689 CheckDefAndScriptSuccess(lines) 690enddef 691 692def Test_command_modifier_other() 693 new Xsomefile 694 setline(1, 'changed') 695 var buf = bufnr() 696 hide edit Xotherfile 697 var info = getbufinfo(buf) 698 assert_equal(1, info[0].hidden) 699 assert_equal(1, info[0].changed) 700 edit Xsomefile 701 bwipe! 702 703 au BufNewFile Xfile g:readFile = 1 704 g:readFile = 0 705 edit Xfile 706 assert_equal(1, g:readFile) 707 bwipe! 708 g:readFile = 0 709 noautocmd edit Xfile 710 assert_equal(0, g:readFile) 711 au! BufNewFile 712 unlet g:readFile 713 714 noswapfile edit XnoSwap 715 assert_equal(false, &l:swapfile) 716 bwipe! 717 718 var caught = false 719 try 720 sandbox !ls 721 catch /E48:/ 722 caught = true 723 endtry 724 assert_true(caught) 725 726 :8verbose g:verbose_now = &verbose 727 assert_equal(8, g:verbose_now) 728 unlet g:verbose_now 729enddef 730 731def EchoHere() 732 echomsg 'here' 733enddef 734def EchoThere() 735 unsilent echomsg 'there' 736enddef 737 738def Test_modifier_silent_unsilent() 739 echomsg 'last one' 740 silent echomsg "text" 741 assert_equal("\nlast one", execute(':1messages')) 742 743 silent! echoerr "error" 744 745 echomsg 'last one' 746 silent EchoHere() 747 assert_equal("\nlast one", execute(':1messages')) 748 749 silent EchoThere() 750 assert_equal("\nthere", execute(':1messages')) 751 752 try 753 silent eval [][0] 754 catch 755 echomsg "caught" 756 endtry 757 assert_equal("\ncaught", execute(':1messages')) 758enddef 759 760def Test_range_after_command_modifier() 761 CheckScriptFailure(['vim9script', 'silent keepjump 1d _'], 'E1050: Colon required before a range: 1d _', 2) 762 new 763 setline(1, 'xxx') 764 CheckScriptSuccess(['vim9script', 'silent keepjump :1d _']) 765 assert_equal('', getline(1)) 766 bwipe! 767enddef 768 769def Test_silent_pattern() 770 new 771 silent! :/pat/put _ 772 bwipe! 773enddef 774 775def Test_eval_command() 776 var from = 3 777 var to = 5 778 g:val = 111 779 def Increment(nrs: list<number>) 780 for nr in nrs 781 g:val += nr 782 endfor 783 enddef 784 eval range(from, to) 785 ->Increment() 786 assert_equal(111 + 3 + 4 + 5, g:val) 787 unlet g:val 788 789 var lines =<< trim END 790 vim9script 791 g:caught = 'no' 792 try 793 eval 123 || 0 794 catch 795 g:caught = 'yes' 796 endtry 797 assert_equal('yes', g:caught) 798 unlet g:caught 799 END 800 CheckScriptSuccess(lines) 801enddef 802 803def Test_map_command() 804 var lines =<< trim END 805 nnoremap <F3> :echo 'hit F3 #'<CR> 806 assert_equal(":echo 'hit F3 #'<CR>", maparg("<F3>", "n")) 807 END 808 CheckDefSuccess(lines) 809 CheckScriptSuccess(['vim9script'] + lines) 810enddef 811 812def Test_normal_command() 813 new 814 setline(1, 'doesnotexist') 815 var caught = 0 816 try 817 exe "norm! \<C-]>" 818 catch /E433/ 819 caught = 2 820 endtry 821 assert_equal(2, caught) 822 823 try 824 exe "norm! 3\<C-]>" 825 catch /E433/ 826 caught = 3 827 endtry 828 assert_equal(3, caught) 829 bwipe! 830enddef 831 832def Test_put_command() 833 new 834 @p = 'ppp' 835 put p 836 assert_equal('ppp', getline(2)) 837 838 put ='below' 839 assert_equal('below', getline(3)) 840 put! ='above' 841 assert_equal('above', getline(3)) 842 assert_equal('below', getline(4)) 843 844 :2put =['a', 'b', 'c'] 845 assert_equal(['ppp', 'a', 'b', 'c', 'above'], getline(2, 6)) 846 847 # compute range at runtime 848 setline(1, range(1, 8)) 849 @a = 'aaa' 850 :$-2put a 851 assert_equal('aaa', getline(7)) 852 853 setline(1, range(1, 8)) 854 :2 855 :+2put! a 856 assert_equal('aaa', getline(4)) 857 858 []->mapnew(() => 0) 859 :$put ='end' 860 assert_equal('end', getline('$')) 861 862 bwipe! 863 864 CheckDefFailure(['put =xxx'], 'E1001:') 865enddef 866 867def Test_put_with_linebreak() 868 new 869 var lines =<< trim END 870 vim9script 871 pu =split('abc', '\zs') 872 ->join() 873 END 874 CheckScriptSuccess(lines) 875 getline(2)->assert_equal('a b c') 876 bwipe! 877enddef 878 879def Test_command_star_range() 880 new 881 setline(1, ['xxx foo xxx', 'xxx bar xxx', 'xxx foo xx bar']) 882 setpos("'<", [0, 1, 0, 0]) 883 setpos("'>", [0, 3, 0, 0]) 884 :*s/\(foo\|bar\)/baz/g 885 getline(1, 3)->assert_equal(['xxx baz xxx', 'xxx baz xxx', 'xxx baz xx baz']) 886 887 bwipe! 888enddef 889 890def Test_f_args() 891 var lines =<< trim END 892 vim9script 893 894 func SaveCmdArgs(...) 895 let g:args = a:000 896 endfunc 897 898 command -nargs=* TestFArgs call SaveCmdArgs(<f-args>) 899 900 TestFArgs 901 assert_equal([], g:args) 902 903 TestFArgs one two three 904 assert_equal(['one', 'two', 'three'], g:args) 905 END 906 CheckScriptSuccess(lines) 907enddef 908 909def Test_user_command_comment() 910 command -nargs=1 Comd echom <q-args> 911 912 var lines =<< trim END 913 vim9script 914 Comd # comment 915 END 916 CheckScriptSuccess(lines) 917 918 lines =<< trim END 919 vim9script 920 Comd# comment 921 END 922 CheckScriptFailure(lines, 'E1144:') 923 924 delcommand Comd 925enddef 926 927def Test_star_command() 928 var lines =<< trim END 929 vim9script 930 @s = 'g:success = 8' 931 set cpo+=* 932 exe '*s' 933 assert_equal(8, g:success) 934 unlet g:success 935 set cpo-=* 936 assert_fails("exe '*s'", 'E1050:') 937 END 938 CheckScriptSuccess(lines) 939enddef 940 941def Test_cmd_argument_without_colon() 942 new Xfile 943 setline(1, ['a', 'b', 'c', 'd']) 944 write 945 edit +3 % 946 assert_equal(3, getcurpos()[1]) 947 edit +/a % 948 assert_equal(1, getcurpos()[1]) 949 bwipe 950 delete('Xfile') 951enddef 952 953def Test_ambiguous_user_cmd() 954 command Cmd1 eval 0 955 command Cmd2 eval 0 956 var lines =<< trim END 957 Cmd 958 END 959 CheckDefAndScriptFailure(lines, 'E464:', 1) 960 delcommand Cmd1 961 delcommand Cmd2 962enddef 963 964def Test_command_not_recognized() 965 var lines =<< trim END 966 d.key = 'asdf' 967 END 968 CheckDefFailure(lines, 'E1146:', 1) 969 970 lines =<< trim END 971 d['key'] = 'asdf' 972 END 973 CheckDefFailure(lines, 'E1146:', 1) 974enddef 975 976def Test_magic_not_used() 977 new 978 for cmd in ['set magic', 'set nomagic'] 979 exe cmd 980 setline(1, 'aaa') 981 s/.../bbb/ 982 assert_equal('bbb', getline(1)) 983 endfor 984 985 set magic 986 setline(1, 'aaa') 987 assert_fails('s/.\M../bbb/', 'E486:') 988 assert_fails('snomagic/.../bbb/', 'E486:') 989 assert_equal('aaa', getline(1)) 990 991 bwipe! 992enddef 993 994def Test_gdefault_not_used() 995 new 996 for cmd in ['set gdefault', 'set nogdefault'] 997 exe cmd 998 setline(1, 'aaa') 999 s/./b/ 1000 assert_equal('baa', getline(1)) 1001 endfor 1002 1003 set nogdefault 1004 bwipe! 1005enddef 1006 1007def g:SomeComplFunc(findstart: number, base: string): any 1008 if findstart 1009 return 0 1010 else 1011 return ['aaa', 'bbb'] 1012 endif 1013enddef 1014 1015def Test_insert_complete() 1016 # this was running into an error with the matchparen hack 1017 new 1018 set completefunc=SomeComplFunc 1019 feedkeys("i\<c-x>\<c-u>\<Esc>", 'ntx') 1020 assert_equal('aaa', getline(1)) 1021 1022 set completefunc= 1023 bwipe! 1024enddef 1025 1026def Test_wincmd() 1027 split 1028 var id1 = win_getid() 1029 if true 1030 try | wincmd w | catch | endtry 1031 endif 1032 assert_notequal(id1, win_getid()) 1033 close 1034enddef 1035 1036def Test_windo_missing_endif() 1037 var lines =<< trim END 1038 windo if 1 1039 END 1040 CheckDefExecFailure(lines, 'E171:', 1) 1041enddef 1042 1043" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker 1044