comparison src/testdir/test_vim9_script.vim @ 34902:d1b433ed9f07 v9.1.0312

patch 9.1.0312: heredocs are not supported for :commands Commit: https://github.com/vim/vim/commit/e74cad3321ce1dcefc1fc64f617511275b6cd930 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Apr 12 18:48:35 2024 +0200 patch 9.1.0312: heredocs are not supported for :commands Problem: heredocs are not supported for :commands (@balki) Solution: Add heredoc support (Yegappan Lakshmanan) fixes: #14491 closes: #14528 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Fri, 12 Apr 2024 19:00:06 +0200
parents af48c532bd88
children 77fae39a747b
comparison
equal deleted inserted replaced
34901:a8b617076edf 34902:d1b433ed9f07
456 " legacy func for command that's defined later 456 " legacy func for command that's defined later
457 func s:InvokeSomeCommand() 457 func s:InvokeSomeCommand()
458 SomeCommand 458 SomeCommand
459 endfunc 459 endfunc
460 460
461 def Test_autocommand_block() 461 def Test_command_block()
462 com SomeCommand { 462 com SomeCommand {
463 g:someVar = 'some' 463 g:someVar = 'some'
464 } 464 }
465 InvokeSomeCommand() 465 InvokeSomeCommand()
466 assert_equal('some', g:someVar) 466 assert_equal('some', g:someVar)
467 467
468 delcommand SomeCommand 468 delcommand SomeCommand
469 unlet g:someVar 469 unlet g:someVar
470 enddef 470 enddef
471 471
472 def Test_command_block() 472 " Test for using heredoc in a :command command block
473 def Test_command_block_heredoc()
474 var lines =<< trim CODE
475 vim9script
476 com SomeCommand {
477 g:someVar =<< trim END
478 aaa
479 bbb
480 END
481 }
482 SomeCommand
483 assert_equal(['aaa', 'bbb'], g:someVar)
484 def Foo()
485 g:someVar = []
486 SomeCommand
487 assert_equal(['aaa', 'bbb'], g:someVar)
488 enddef
489 Foo()
490 delcommand SomeCommand
491 unlet g:someVar
492 CODE
493 v9.CheckSourceSuccess( lines)
494
495 # Execute a command with heredoc in a block
496 lines =<< trim CODE
497 vim9script
498 com SomeCommand {
499 g:someVar =<< trim END
500 aaa
501 bbb
502 END
503 }
504 execute('SomeCommand')
505 assert_equal(['aaa', 'bbb'], g:someVar)
506 delcommand SomeCommand
507 unlet g:someVar
508 CODE
509 v9.CheckSourceSuccess(lines)
510
511 # heredoc evaluation
512 lines =<< trim CODE
513 vim9script
514 com SomeCommand {
515 var suffix = '---'
516 g:someVar =<< trim eval END
517 ccc{suffix}
518 ddd
519 END
520 }
521 SomeCommand
522 assert_equal(['ccc---', 'ddd'], g:someVar)
523 def Foo()
524 g:someVar = []
525 SomeCommand
526 assert_equal(['ccc---', 'ddd'], g:someVar)
527 enddef
528 Foo()
529 delcommand SomeCommand
530 unlet g:someVar
531 CODE
532 v9.CheckSourceSuccess(lines)
533
534 # command following heredoc
535 lines =<< trim CODE
536 vim9script
537 com SomeCommand {
538 var l =<< trim END
539 eee
540 fff
541 END
542 g:someVar = l
543 }
544 SomeCommand
545 assert_equal(['eee', 'fff'], g:someVar)
546 delcommand SomeCommand
547 unlet g:someVar
548 CODE
549 v9.CheckSourceSuccess(lines)
550
551 # Error in heredoc
552 lines =<< trim CODE
553 vim9script
554 com SomeCommand {
555 g:someVar =<< trim END
556 eee
557 fff
558 }
559 try
560 SomeCommand
561 catch
562 assert_match("E990: Missing end marker 'END'", v:exception)
563 endtry
564 delcommand SomeCommand
565 unlet g:someVar
566 CODE
567 v9.CheckSourceSuccess(lines)
568 enddef
569
570 def Test_autocommand_block()
473 au BufNew *.xml { 571 au BufNew *.xml {
474 g:otherVar = 'other' 572 g:otherVar = 'other'
475 } 573 }
476 split other.xml 574 split other.xml
477 assert_equal('other', g:otherVar) 575 assert_equal('other', g:otherVar)