1" Tests for user defined commands 2 3source vim9.vim 4 5" Test for <mods> in user defined commands 6function Test_cmdmods() 7 let g:mods = '' 8 9 command! -nargs=* MyCmd let g:mods = '<mods>' 10 11 MyCmd 12 call assert_equal('', g:mods) 13 aboveleft MyCmd 14 call assert_equal('aboveleft', g:mods) 15 abo MyCmd 16 call assert_equal('aboveleft', g:mods) 17 belowright MyCmd 18 call assert_equal('belowright', g:mods) 19 bel MyCmd 20 call assert_equal('belowright', g:mods) 21 botright MyCmd 22 call assert_equal('botright', g:mods) 23 bo MyCmd 24 call assert_equal('botright', g:mods) 25 browse MyCmd 26 call assert_equal('browse', g:mods) 27 bro MyCmd 28 call assert_equal('browse', g:mods) 29 confirm MyCmd 30 call assert_equal('confirm', g:mods) 31 conf MyCmd 32 call assert_equal('confirm', g:mods) 33 hide MyCmd 34 call assert_equal('hide', g:mods) 35 hid MyCmd 36 call assert_equal('hide', g:mods) 37 keepalt MyCmd 38 call assert_equal('keepalt', g:mods) 39 keepa MyCmd 40 call assert_equal('keepalt', g:mods) 41 keepjumps MyCmd 42 call assert_equal('keepjumps', g:mods) 43 keepj MyCmd 44 call assert_equal('keepjumps', g:mods) 45 keepmarks MyCmd 46 call assert_equal('keepmarks', g:mods) 47 kee MyCmd 48 call assert_equal('keepmarks', g:mods) 49 keeppatterns MyCmd 50 call assert_equal('keeppatterns', g:mods) 51 keepp MyCmd 52 call assert_equal('keeppatterns', g:mods) 53 leftabove MyCmd " results in :aboveleft 54 call assert_equal('aboveleft', g:mods) 55 lefta MyCmd 56 call assert_equal('aboveleft', g:mods) 57 lockmarks MyCmd 58 call assert_equal('lockmarks', g:mods) 59 loc MyCmd 60 call assert_equal('lockmarks', g:mods) 61 " noautocmd MyCmd 62 noswapfile MyCmd 63 call assert_equal('noswapfile', g:mods) 64 nos MyCmd 65 call assert_equal('noswapfile', g:mods) 66 rightbelow MyCmd " results in :belowright 67 call assert_equal('belowright', g:mods) 68 rightb MyCmd 69 call assert_equal('belowright', g:mods) 70 " sandbox MyCmd 71 silent MyCmd 72 call assert_equal('silent', g:mods) 73 sil MyCmd 74 call assert_equal('silent', g:mods) 75 tab MyCmd 76 call assert_equal('tab', g:mods) 77 topleft MyCmd 78 call assert_equal('topleft', g:mods) 79 to MyCmd 80 call assert_equal('topleft', g:mods) 81 " unsilent MyCmd 82 verbose MyCmd 83 call assert_equal('verbose', g:mods) 84 verb MyCmd 85 call assert_equal('verbose', g:mods) 86 vertical MyCmd 87 call assert_equal('vertical', g:mods) 88 vert MyCmd 89 call assert_equal('vertical', g:mods) 90 91 aboveleft belowright botright browse confirm hide keepalt keepjumps 92 \ keepmarks keeppatterns lockmarks noswapfile silent tab 93 \ topleft verbose vertical MyCmd 94 95 call assert_equal('browse confirm hide keepalt keepjumps ' . 96 \ 'keepmarks keeppatterns lockmarks noswapfile silent ' . 97 \ 'verbose aboveleft belowright botright tab topleft vertical', g:mods) 98 99 let g:mods = '' 100 command! -nargs=* MyQCmd let g:mods .= '<q-mods> ' 101 102 vertical MyQCmd 103 call assert_equal('"vertical" ', g:mods) 104 105 delcommand MyCmd 106 delcommand MyQCmd 107 unlet g:mods 108endfunction 109 110func SaveCmdArgs(...) 111 let g:args = a:000 112endfunc 113 114func Test_f_args() 115 command -nargs=* TestFArgs call SaveCmdArgs(<f-args>) 116 117 TestFArgs 118 call assert_equal([], g:args) 119 120 TestFArgs one two three 121 call assert_equal(['one', 'two', 'three'], g:args) 122 123 TestFArgs one\\two three 124 call assert_equal(['one\two', 'three'], g:args) 125 126 TestFArgs one\ two three 127 call assert_equal(['one two', 'three'], g:args) 128 129 TestFArgs one\"two three 130 call assert_equal(['one\"two', 'three'], g:args) 131 132 delcommand TestFArgs 133endfunc 134 135func Test_q_args() 136 command -nargs=* TestQArgs call SaveCmdArgs(<q-args>) 137 138 TestQArgs 139 call assert_equal([''], g:args) 140 141 TestQArgs one two three 142 call assert_equal(['one two three'], g:args) 143 144 TestQArgs one\\two three 145 call assert_equal(['one\\two three'], g:args) 146 147 TestQArgs one\ two three 148 call assert_equal(['one\ two three'], g:args) 149 150 TestQArgs one\"two three 151 call assert_equal(['one\"two three'], g:args) 152 153 delcommand TestQArgs 154endfunc 155 156func Test_reg_arg() 157 command -nargs=* -reg TestRegArg call SaveCmdArgs("<reg>", "<register>") 158 159 TestRegArg 160 call assert_equal(['', ''], g:args) 161 162 TestRegArg x 163 call assert_equal(['x', 'x'], g:args) 164 165 delcommand TestRegArg 166endfunc 167 168func Test_no_arg() 169 command -nargs=* TestNoArg call SaveCmdArgs("<args>", "<>", "<x>", "<lt>") 170 171 TestNoArg 172 call assert_equal(['', '<>', '<x>', '<'], g:args) 173 174 TestNoArg one 175 call assert_equal(['one', '<>', '<x>', '<'], g:args) 176 177 delcommand TestNoArg 178endfunc 179 180func Test_range_arg() 181 command -range TestRangeArg call SaveCmdArgs(<range>, <line1>, <line2>) 182 new 183 call setline(1, range(100)) 184 let lnum = line('.') 185 186 TestRangeArg 187 call assert_equal([0, lnum, lnum], g:args) 188 189 99TestRangeArg 190 call assert_equal([1, 99, 99], g:args) 191 192 88,99TestRangeArg 193 call assert_equal([2, 88, 99], g:args) 194 195 call assert_fails('102TestRangeArg', 'E16:') 196 197 bwipe! 198 delcommand TestRangeArg 199endfunc 200 201func Test_Ambiguous() 202 command Doit let g:didit = 'yes' 203 command Dothat let g:didthat = 'also' 204 call assert_fails('Do', 'E464:') 205 Doit 206 call assert_equal('yes', g:didit) 207 Dothat 208 call assert_equal('also', g:didthat) 209 unlet g:didit 210 unlet g:didthat 211 212 delcommand Doit 213 Do 214 call assert_equal('also', g:didthat) 215 delcommand Dothat 216 217 call assert_fails("\x4ei\041", ' you demand a ') 218endfunc 219 220func Test_redefine_on_reload() 221 call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists') 222 call assert_equal(0, exists(':ExistingCommand')) 223 source Xcommandexists 224 call assert_equal(2, exists(':ExistingCommand')) 225 " Redefining a command when reloading a script is OK. 226 source Xcommandexists 227 call assert_equal(2, exists(':ExistingCommand')) 228 229 " But redefining in another script is not OK. 230 call writefile(['command ExistingCommand echo "yes"'], 'Xcommandexists2') 231 call assert_fails('source Xcommandexists2', 'E174:') 232 call delete('Xcommandexists2') 233 234 " And defining twice in one script is not OK. 235 delcommand ExistingCommand 236 call assert_equal(0, exists(':ExistingCommand')) 237 call writefile([ 238 \ 'command ExistingCommand echo "yes"', 239 \ 'command ExistingCommand echo "no"', 240 \ ], 'Xcommandexists') 241 call assert_fails('source Xcommandexists', 'E174:') 242 call assert_equal(2, exists(':ExistingCommand')) 243 244 call delete('Xcommandexists') 245 delcommand ExistingCommand 246endfunc 247 248func Test_CmdUndefined() 249 call assert_fails('Doit', 'E492:') 250 au CmdUndefined Doit :command Doit let g:didit = 'yes' 251 Doit 252 call assert_equal('yes', g:didit) 253 delcommand Doit 254 255 call assert_fails('Dothat', 'E492:') 256 au CmdUndefined * let g:didnot = 'yes' 257 call assert_fails('Dothat', 'E492:') 258 call assert_equal('yes', g:didnot) 259endfunc 260 261func Test_CmdErrors() 262 call assert_fails('com! docmd :', 'E183:') 263 call assert_fails('com! \<Tab> :', 'E182:') 264 call assert_fails('com! _ :', 'E182:') 265 call assert_fails('com! X :', 'E841:') 266 call assert_fails('com! - DoCmd :', 'E175:') 267 call assert_fails('com! -xxx DoCmd :', 'E181:') 268 call assert_fails('com! -addr DoCmd :', 'E179:') 269 call assert_fails('com! -addr=asdf DoCmd :', 'E180:') 270 call assert_fails('com! -complete DoCmd :', 'E179:') 271 call assert_fails('com! -complete=xxx DoCmd :', 'E180:') 272 call assert_fails('com! -complete=custom DoCmd :', 'E467:') 273 call assert_fails('com! -complete=customlist DoCmd :', 'E467:') 274 call assert_fails('com! -complete=behave,CustomComplete DoCmd :', 'E468:') 275 call assert_fails('com! -nargs=x DoCmd :', 'E176:') 276 call assert_fails('com! -count=1 -count=2 DoCmd :', 'E177:') 277 call assert_fails('com! -count=x DoCmd :', 'E178:') 278 call assert_fails('com! -range=x DoCmd :', 'E178:') 279 280 com! -complete=file DoCmd : 281 call assert_match('E1208:', v:warningmsg) 282 let v:warningmsg = '' 283 com! -nargs=0 -complete=file DoCmd : 284 call assert_match('E1208:', v:warningmsg) 285 286 let lines =<< trim END 287 vim9script 288 com! -complete=file DoCmd : 289 END 290 call CheckScriptFailure(lines, 'E1208', 2) 291 292 let lines =<< trim END 293 vim9script 294 com! -nargs=0 -complete=file DoCmd : 295 END 296 call CheckScriptFailure(lines, 'E1208', 2) 297 298 com! -nargs=0 DoCmd : 299 call assert_fails('DoCmd x', 'E488:') 300 301 com! -nargs=1 DoCmd : 302 call assert_fails('DoCmd', 'E471:') 303 304 com! -nargs=+ DoCmd : 305 call assert_fails('DoCmd', 'E471:') 306 307 call assert_fails('com DoCmd :', 'E174:') 308 comclear 309 call assert_fails('delcom DoCmd', 'E184:') 310endfunc 311 312func CustomComplete(A, L, P) 313 return "January\nFebruary\nMars\n" 314endfunc 315 316func CustomCompleteList(A, L, P) 317 return [ "Monday", "Tuesday", "Wednesday", {}] 318endfunc 319 320func Test_CmdCompletion() 321 call feedkeys(":com -\<C-A>\<C-B>\"\<CR>", 'tx') 322 call assert_equal('"com -addr bang bar buffer complete count keepscript nargs range register', @:) 323 324 call feedkeys(":com -nargs=0 -\<C-A>\<C-B>\"\<CR>", 'tx') 325 call assert_equal('"com -nargs=0 -addr bang bar buffer complete count keepscript nargs range register', @:) 326 327 call feedkeys(":com -nargs=\<C-A>\<C-B>\"\<CR>", 'tx') 328 call assert_equal('"com -nargs=* + 0 1 ?', @:) 329 330 call feedkeys(":com -addr=\<C-A>\<C-B>\"\<CR>", 'tx') 331 call assert_equal('"com -addr=arguments buffers lines loaded_buffers other quickfix tabs windows', @:) 332 333 call feedkeys(":com -complete=co\<C-A>\<C-B>\"\<CR>", 'tx') 334 call assert_equal('"com -complete=color command compiler', @:) 335 336 command! DoCmd1 : 337 command! DoCmd2 : 338 call feedkeys(":com \<C-A>\<C-B>\"\<CR>", 'tx') 339 call assert_equal('"com DoCmd1 DoCmd2', @:) 340 341 call feedkeys(":DoC\<C-A>\<C-B>\"\<CR>", 'tx') 342 call assert_equal('"DoCmd1 DoCmd2', @:) 343 344 call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx') 345 call assert_equal('"delcom DoCmd1 DoCmd2', @:) 346 347 delcom DoCmd1 348 call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx') 349 call assert_equal('"delcom DoCmd2', @:) 350 351 call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx') 352 call assert_equal('"com DoCmd2', @:) 353 354 delcom DoCmd2 355 call feedkeys(":delcom DoC\<C-A>\<C-B>\"\<CR>", 'tx') 356 call assert_equal('"delcom DoC', @:) 357 358 call feedkeys(":com DoC\<C-A>\<C-B>\"\<CR>", 'tx') 359 call assert_equal('"com DoC', @:) 360 361 com! -nargs=1 -complete=behave DoCmd : 362 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') 363 call assert_equal('"DoCmd mswin xterm', @:) 364 365 com! -nargs=* -complete=custom,CustomComplete DoCmd : 366 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') 367 call assert_equal('"DoCmd January February Mars', @:) 368 369 com! -nargs=? -complete=customlist,CustomCompleteList DoCmd : 370 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') 371 call assert_equal('"DoCmd Monday Tuesday Wednesday', @:) 372 373 com! -nargs=+ -complete=custom,CustomCompleteList DoCmd : 374 call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E730:') 375 376 com! -nargs=+ -complete=customlist,CustomComp DoCmd : 377 call assert_fails("call feedkeys(':DoCmd \<C-D>', 'tx')", 'E117:') 378 379 " custom completion without a function 380 com! -nargs=? -complete=custom, DoCmd 381 call assert_beeps("call feedkeys(':DoCmd \t', 'tx')") 382 383 " custom completion failure with the wrong function 384 com! -nargs=? -complete=custom,min DoCmd 385 call assert_fails("call feedkeys(':DoCmd \t', 'tx')", 'E118:') 386 387 delcom DoCmd 388endfunc 389 390func CallExecute(A, L, P) 391 " Drop first '\n' 392 return execute('echo "hi"')[1:] 393endfunc 394 395func Test_use_execute_in_completion() 396 command! -nargs=* -complete=custom,CallExecute DoExec : 397 call feedkeys(":DoExec \<C-A>\<C-B>\"\<CR>", 'tx') 398 call assert_equal('"DoExec hi', @:) 399 delcommand DoExec 400endfunc 401 402func Test_addr_all() 403 command! -addr=lines DoSomething let g:a1 = <line1> | let g:a2 = <line2> 404 %DoSomething 405 call assert_equal(1, g:a1) 406 call assert_equal(line('$'), g:a2) 407 408 command! -addr=arguments DoSomething let g:a1 = <line1> | let g:a2 = <line2> 409 args one two three 410 %DoSomething 411 call assert_equal(1, g:a1) 412 call assert_equal(3, g:a2) 413 414 command! -addr=buffers DoSomething let g:a1 = <line1> | let g:a2 = <line2> 415 %DoSomething 416 for low in range(1, bufnr('$')) 417 if buflisted(low) 418 break 419 endif 420 endfor 421 call assert_equal(low, g:a1) 422 call assert_equal(bufnr('$'), g:a2) 423 424 command! -addr=loaded_buffers DoSomething let g:a1 = <line1> | let g:a2 = <line2> 425 %DoSomething 426 for low in range(1, bufnr('$')) 427 if bufloaded(low) 428 break 429 endif 430 endfor 431 call assert_equal(low, g:a1) 432 for up in range(bufnr('$'), 1, -1) 433 if bufloaded(up) 434 break 435 endif 436 endfor 437 call assert_equal(up, g:a2) 438 439 command! -addr=windows DoSomething let g:a1 = <line1> | let g:a2 = <line2> 440 new 441 %DoSomething 442 call assert_equal(1, g:a1) 443 call assert_equal(winnr('$'), g:a2) 444 bwipe 445 446 command! -addr=tabs DoSomething let g:a1 = <line1> | let g:a2 = <line2> 447 tabnew 448 %DoSomething 449 call assert_equal(1, g:a1) 450 call assert_equal(len(gettabinfo()), g:a2) 451 bwipe 452 453 command! -addr=other DoSomething let g:a1 = <line1> | let g:a2 = <line2> 454 DoSomething 455 call assert_equal(line('.'), g:a1) 456 call assert_equal(line('.'), g:a2) 457 %DoSomething 458 call assert_equal(1, g:a1) 459 call assert_equal(line('$'), g:a2) 460 461 delcommand DoSomething 462endfunc 463 464func Test_command_list() 465 command! DoCmd : 466 call assert_equal("\n Name Args Address Complete Definition" 467 \ .. "\n DoCmd 0 :", 468 \ execute('command DoCmd')) 469 470 " Test with various -range= and -count= argument values. 471 command! -range DoCmd : 472 call assert_equal("\n Name Args Address Complete Definition" 473 \ .. "\n DoCmd 0 . :", 474 \ execute('command DoCmd')) 475 command! -range=% DoCmd : 476 call assert_equal("\n Name Args Address Complete Definition" 477 \ .. "\n DoCmd 0 % :", 478 \ execute('command! DoCmd')) 479 command! -range=2 DoCmd : 480 call assert_equal("\n Name Args Address Complete Definition" 481 \ .. "\n DoCmd 0 2 :", 482 \ execute('command DoCmd')) 483 command! -count=2 DoCmd : 484 call assert_equal("\n Name Args Address Complete Definition" 485 \ .. "\n DoCmd 0 2c ? :", 486 \ execute('command DoCmd')) 487 488 " Test with various -addr= argument values. 489 command! -addr=lines DoCmd : 490 call assert_equal("\n Name Args Address Complete Definition" 491 \ .. "\n DoCmd 0 . :", 492 \ execute('command DoCmd')) 493 command! -addr=arguments DoCmd : 494 call assert_equal("\n Name Args Address Complete Definition" 495 \ .. "\n DoCmd 0 . arg :", 496 \ execute('command DoCmd')) 497 command! -addr=buffers DoCmd : 498 call assert_equal("\n Name Args Address Complete Definition" 499 \ .. "\n DoCmd 0 . buf :", 500 \ execute('command DoCmd')) 501 command! -addr=loaded_buffers DoCmd : 502 call assert_equal("\n Name Args Address Complete Definition" 503 \ .. "\n DoCmd 0 . load :", 504 \ execute('command DoCmd')) 505 command! -addr=windows DoCmd : 506 call assert_equal("\n Name Args Address Complete Definition" 507 \ .. "\n DoCmd 0 . win :", 508 \ execute('command DoCmd')) 509 command! -addr=tabs DoCmd : 510 call assert_equal("\n Name Args Address Complete Definition" 511 \ .. "\n DoCmd 0 . tab :", 512 \ execute('command DoCmd')) 513 command! -addr=other DoCmd : 514 call assert_equal("\n Name Args Address Complete Definition" 515 \ .. "\n DoCmd 0 . ? :", 516 \ execute('command DoCmd')) 517 518 " Test with various -complete= argument values (non-exhaustive list) 519 command! -nargs=1 -complete=arglist DoCmd : 520 call assert_equal("\n Name Args Address Complete Definition" 521 \ .. "\n DoCmd 1 arglist :", 522 \ execute('command DoCmd')) 523 command! -nargs=* -complete=augroup DoCmd : 524 call assert_equal("\n Name Args Address Complete Definition" 525 \ .. "\n DoCmd * augroup :", 526 \ execute('command DoCmd')) 527 command! -nargs=? -complete=custom,CustomComplete DoCmd : 528 call assert_equal("\n Name Args Address Complete Definition" 529 \ .. "\n DoCmd ? custom :", 530 \ execute('command DoCmd')) 531 command! -nargs=+ -complete=customlist,CustomComplete DoCmd : 532 call assert_equal("\n Name Args Address Complete Definition" 533 \ .. "\n DoCmd + customlist :", 534 \ execute('command DoCmd')) 535 536 " Test with various -narg= argument values. 537 command! -nargs=0 DoCmd : 538 call assert_equal("\n Name Args Address Complete Definition" 539 \ .. "\n DoCmd 0 :", 540 \ execute('command DoCmd')) 541 command! -nargs=1 DoCmd : 542 call assert_equal("\n Name Args Address Complete Definition" 543 \ .. "\n DoCmd 1 :", 544 \ execute('command DoCmd')) 545 command! -nargs=* DoCmd : 546 call assert_equal("\n Name Args Address Complete Definition" 547 \ .. "\n DoCmd * :", 548 \ execute('command DoCmd')) 549 command! -nargs=? DoCmd : 550 call assert_equal("\n Name Args Address Complete Definition" 551 \ .. "\n DoCmd ? :", 552 \ execute('command DoCmd')) 553 command! -nargs=+ DoCmd : 554 call assert_equal("\n Name Args Address Complete Definition" 555 \ .. "\n DoCmd + :", 556 \ execute('command DoCmd')) 557 558 " Test with other arguments. 559 command! -bang DoCmd : 560 call assert_equal("\n Name Args Address Complete Definition" 561 \ .. "\n! DoCmd 0 :", 562 \ execute('command DoCmd')) 563 command! -bar DoCmd : 564 call assert_equal("\n Name Args Address Complete Definition" 565 \ .. "\n| DoCmd 0 :", 566 \ execute('command DoCmd')) 567 command! -register DoCmd : 568 call assert_equal("\n Name Args Address Complete Definition" 569 \ .. "\n\" DoCmd 0 :", 570 \ execute('command DoCmd')) 571 command! -buffer DoCmd : 572 call assert_equal("\n Name Args Address Complete Definition" 573 \ .. "\nb DoCmd 0 :" 574 \ .. "\n\" DoCmd 0 :", 575 \ execute('command DoCmd')) 576 comclear 577 578 " Test with many args. 579 command! -bang -bar -register -buffer -nargs=+ -complete=environment -addr=windows -count=3 DoCmd : 580 call assert_equal("\n Name Args Address Complete Definition" 581 \ .. "\n!\"b|DoCmd + 3c win environment :", 582 \ execute('command DoCmd')) 583 comclear 584 585 " Test with special characters in command definition. 586 command! DoCmd :<cr><tab><c-d> 587 call assert_equal("\n Name Args Address Complete Definition" 588 \ .. "\n DoCmd 0 :<CR><Tab><C-D>", 589 \ execute('command DoCmd')) 590 591 " Test output in verbose mode. 592 command! DoCmd : 593 call assert_match("^\n" 594 \ .. " Name Args Address Complete Definition\n" 595 \ .. " DoCmd 0 :\n" 596 \ .. "\tLast set from .*/test_usercommands.vim line \\d\\+$", 597 \ execute('verbose command DoCmd')) 598 599 comclear 600 call assert_equal("\nNo user-defined commands found", execute(':command Xxx')) 601 call assert_equal("\nNo user-defined commands found", execute('command')) 602endfunc 603 604" Test for a custom user completion returning the wrong value type 605func Test_usercmd_custom() 606 func T1(a, c, p) 607 return "a\nb\n" 608 endfunc 609 command -nargs=* -complete=customlist,T1 TCmd1 610 call feedkeys(":TCmd1 \<C-A>\<C-B>\"\<CR>", 'xt') 611 call assert_equal('"TCmd1 ', @:) 612 delcommand TCmd1 613 delfunc T1 614 615 func T2(a, c, p) 616 return {} 617 endfunc 618 command -nargs=* -complete=customlist,T2 TCmd2 619 call feedkeys(":TCmd2 \<C-A>\<C-B>\"\<CR>", 'xt') 620 call assert_equal('"TCmd2 ', @:) 621 delcommand TCmd2 622 delfunc T2 623endfunc 624 625func Test_usercmd_with_block() 626 command DoSomething { 627 g:didit = 'yes' # comment 628 # comment line 629 g:didmore = 'more' 630 } 631 DoSomething 632 call assert_equal('yes', g:didit) 633 call assert_equal('more', g:didmore) 634 unlet g:didit 635 unlet g:didmore 636 delcommand DoSomething 637 638 command DoMap { 639 echo [1, 2, 3]->map((_, v) => v + 1) 640 } 641 DoMap 642 delcommand DoMap 643 644 let lines =<< trim END 645 command DoesNotEnd { 646 echo 'hello' 647 END 648 call CheckScriptFailure(lines, 'E1026:') 649 650 let lines =<< trim END 651 command BarCommand { 652 echo 'hello' | echo 'there' 653 } 654 BarCommand 655 END 656 call CheckScriptFailure(lines, 'E1231:') 657endfunc 658 659func Test_delcommand_buffer() 660 command Global echo 'global' 661 command -buffer OneBuffer echo 'one' 662 new 663 command -buffer TwoBuffer echo 'two' 664 call assert_equal(0, exists(':OneBuffer')) 665 call assert_equal(2, exists(':Global')) 666 call assert_equal(2, exists(':TwoBuffer')) 667 delcommand -buffer TwoBuffer 668 call assert_equal(0, exists(':TwoBuffer')) 669 call assert_fails('delcommand -buffer Global', 'E1237:') 670 call assert_fails('delcommand -buffer OneBuffer', 'E1237:') 671 bwipe! 672 call assert_equal(2, exists(':OneBuffer')) 673 delcommand -buffer OneBuffer 674 call assert_equal(0, exists(':OneBuffer')) 675 call assert_fails('delcommand -buffer Global', 'E1237:') 676 delcommand Global 677 call assert_equal(0, exists(':Global')) 678endfunc 679 680" vim: shiftwidth=2 sts=2 expandtab 681