comparison src/testdir/test_usercommands.vim @ 28181:2961a18f9cbf v8.2.4616

patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain Commit: https://github.com/vim/vim/commit/98b7fe725ec342d28d7c86293098b233c57c4af9 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 23 21:36:27 2022 +0000 patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain Problem: Vim9: Declarations in a {} block of a user command do not use Vim9 rules if defined in a legacy script. (Yegappan Lakshmanan) Solution: Pretend the script is Vim9 script.
author Bram Moolenaar <Bram@vim.org>
date Wed, 23 Mar 2022 22:45:06 +0100
parents 010fa62d6fe2
children 9a7a2908e1a8
comparison
equal deleted inserted replaced
28180:d56d48f416b1 28181:2961a18f9cbf
796 call assert_equal('Hello.', getline(1)) 796 call assert_equal('Hello.', getline(1))
797 bw! 797 bw!
798 delcommand SubJapanesePeriodToDot 798 delcommand SubJapanesePeriodToDot
799 endfunc 799 endfunc
800 800
801 " Declaring a variable in a {} uses Vim9 script rules, even when defined in a
802 " legacy script.
803 func Test_block_declaration_legacy_script()
804 let lines =<< trim END
805 command -range Rename {
806 var save = @a
807 @a = 'something'
808 g:someExpr = @a
809 @a = save
810 }
811 END
812 call writefile(lines, 'Xlegacy')
813 source Xlegacy
814
815 let lines =<< trim END
816 let @a = 'saved'
817 Rename
818 call assert_equal('something', g:someExpr)
819 call assert_equal('saved', @a)
820
821 let g:someExpr = 'xxx'
822 let @a = 'also'
823 Rename
824 call assert_equal('something', g:someExpr)
825 call assert_equal('also', @a)
826 END
827 call writefile(lines, 'Xother')
828 source Xother
829
830 unlet g:someExpr
831 call delete('Xlegacy')
832 call delete('Xother')
833 delcommand Rename
834 endfunc
835
836
801 " vim: shiftwidth=2 sts=2 expandtab 837 " vim: shiftwidth=2 sts=2 expandtab