Mercurial > vim
comparison src/testdir/test_vim9_script.vim @ 23072:4b398a229b0b v8.2.2082
patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Commit: https://github.com/vim/vim/commit/e0de171ecd2ff7acd56deda2cf81f0d13a69c803
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Dec 2 17:36:54 2020 +0100
patch 8.2.2082: Vim9: can still use the depricated #{} dict syntax
Problem: Vim9: can still use the depricated #{} dict syntax.
Solution: Remove support for #{} in Vim9 script. (closes https://github.com/vim/vim/issues/7406, closes https://github.com/vim/vim/issues/7405)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 02 Dec 2020 17:45:05 +0100 |
parents | 2f034cb0a046 |
children | 49c9aa9e40d4 |
comparison
equal
deleted
inserted
replaced
23071:20dac5998fa6 | 23072:4b398a229b0b |
---|---|
175 # constlist[1][1] = 88 | 175 # constlist[1][1] = 88 |
176 var cl = constlist[1] | 176 var cl = constlist[1] |
177 cl[1] = 88 | 177 cl[1] = 88 |
178 constlist->assert_equal([1, [77, 88], 3]) | 178 constlist->assert_equal([1, [77, 88], 3]) |
179 | 179 |
180 var vardict = #{five: 5, six: 6} | 180 var vardict = {five: 5, six: 6} |
181 const constdict = #{one: 1, two: vardict, three: 3} | 181 const constdict = {one: 1, two: vardict, three: 3} |
182 vardict['five'] = 55 | 182 vardict['five'] = 55 |
183 # TODO: does not work yet | 183 # TODO: does not work yet |
184 # constdict['two']['six'] = 66 | 184 # constdict['two']['six'] = 66 |
185 var cd = constdict['two'] | 185 var cd = constdict['two'] |
186 cd['six'] = 66 | 186 cd['six'] = 66 |
187 constdict->assert_equal(#{one: 1, two: #{five: 55, six: 66}, three: 3}) | 187 constdict->assert_equal({one: 1, two: {five: 55, six: 66}, three: 3}) |
188 END | 188 END |
189 CheckDefAndScriptSuccess(lines) | 189 CheckDefAndScriptSuccess(lines) |
190 enddef | 190 enddef |
191 | 191 |
192 def Test_const_bang() | 192 def Test_const_bang() |
210 END | 210 END |
211 CheckDefExecFailure(lines, 'E1118:', 2) | 211 CheckDefExecFailure(lines, 'E1118:', 2) |
212 CheckScriptFailure(['vim9script'] + lines, 'E684:', 3) | 212 CheckScriptFailure(['vim9script'] + lines, 'E684:', 3) |
213 | 213 |
214 lines =<< trim END | 214 lines =<< trim END |
215 const dd = #{one: 1, two: 2} | 215 const dd = {one: 1, two: 2} |
216 dd["one"] = 99 | 216 dd["one"] = 99 |
217 END | 217 END |
218 CheckDefExecFailure(lines, 'E1121:', 2) | 218 CheckDefExecFailure(lines, 'E1121:', 2) |
219 CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) | 219 CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) |
220 | 220 |
221 lines =<< trim END | 221 lines =<< trim END |
222 const dd = #{one: 1, two: 2} | 222 const dd = {one: 1, two: 2} |
223 dd["three"] = 99 | 223 dd["three"] = 99 |
224 END | 224 END |
225 CheckDefExecFailure(lines, 'E1120:') | 225 CheckDefExecFailure(lines, 'E1120:') |
226 CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) | 226 CheckScriptFailure(['vim9script'] + lines, 'E741:', 3) |
227 enddef | 227 enddef |
383 catch /E121:/ | 383 catch /E121:/ |
384 n = 121 | 384 n = 121 |
385 endtry | 385 endtry |
386 assert_equal(121, n) | 386 assert_equal(121, n) |
387 | 387 |
388 var d = #{one: 1} | 388 var d = {one: 1} |
389 try | 389 try |
390 n = d[g:astring] | 390 n = d[g:astring] |
391 catch /E716:/ | 391 catch /E716:/ |
392 n = 222 | 392 n = 222 |
393 endtry | 393 endtry |
773 exported += 3 | 773 exported += 3 |
774 g:imported_added = exported | 774 g:imported_added = exported |
775 g:imported_func = Exported() | 775 g:imported_func = Exported() |
776 | 776 |
777 def GetExported(): string | 777 def GetExported(): string |
778 var local_dict = #{ref: Exported} | 778 var local_dict = {ref: Exported} |
779 return local_dict.ref() | 779 return local_dict.ref() |
780 enddef | 780 enddef |
781 g:funcref_result = GetExported() | 781 g:funcref_result = GetExported() |
782 | 782 |
783 import {exp_name} from './Xexport.vim' | 783 import {exp_name} from './Xexport.vim' |
1131 return 0 | 1131 return 0 |
1132 enddef | 1132 enddef |
1133 END | 1133 END |
1134 writefile(export, 'XexportCmd.vim') | 1134 writefile(export, 'XexportCmd.vim') |
1135 | 1135 |
1136 var buf = RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', #{ | 1136 var buf = RunVimInTerminal('-c "import Foo from ''./XexportCmd.vim''"', { |
1137 rows: 6, wait_for_ruler: 0}) | 1137 rows: 6, wait_for_ruler: 0}) |
1138 WaitForAssert({-> assert_match('^E1094:', term_getline(buf, 5))}) | 1138 WaitForAssert({-> assert_match('^E1094:', term_getline(buf, 5))}) |
1139 | 1139 |
1140 delete('XexportCmd.vim') | 1140 delete('XexportCmd.vim') |
1141 StopVimInTerminal(buf) | 1141 StopVimInTerminal(buf) |
1731 | 1731 |
1732 var n = true | 1732 var n = true |
1733 execute 'echomsg' (n ? '"true"' : '"no"') | 1733 execute 'echomsg' (n ? '"true"' : '"no"') |
1734 assert_match('^true$', Screenline(&lines)) | 1734 assert_match('^true$', Screenline(&lines)) |
1735 | 1735 |
1736 echomsg [1, 2, 3] #{a: 1, b: 2} | 1736 echomsg [1, 2, 3] {a: 1, b: 2} |
1737 assert_match('^\[1, 2, 3\] {''a'': 1, ''b'': 2}$', Screenline(&lines)) | 1737 assert_match('^\[1, 2, 3\] {''a'': 1, ''b'': 2}$', Screenline(&lines)) |
1738 | 1738 |
1739 CheckDefFailure(['execute xxx'], 'E1001:', 1) | 1739 CheckDefFailure(['execute xxx'], 'E1001:', 1) |
1740 CheckDefExecFailure(['execute "tabnext " .. 8'], 'E475:', 1) | 1740 CheckDefExecFailure(['execute "tabnext " .. 8'], 'E475:', 1) |
1741 CheckDefFailure(['execute "cmd"# comment'], 'E488:', 1) | 1741 CheckDefFailure(['execute "cmd"# comment'], 'E488:', 1) |
2022 'three', | 2022 'three', |
2023 ] # comment | 2023 ] # comment |
2024 assert_equal(['one', 'two', 'three'], mylist) | 2024 assert_equal(['one', 'two', 'three'], mylist) |
2025 | 2025 |
2026 var mydict = { | 2026 var mydict = { |
2027 'one': 1, | 2027 ['one']: 1, |
2028 'two': 2, | 2028 ['two']: 2, |
2029 'three': | 2029 ['three']: |
2030 3, | 2030 3, |
2031 } # comment | 2031 } # comment |
2032 assert_equal({'one': 1, 'two': 2, 'three': 3}, mydict) | 2032 assert_equal({one: 1, two: 2, three: 3}, mydict) |
2033 mydict = #{ | 2033 mydict = { |
2034 one: 1, # comment | 2034 one: 1, # comment |
2035 two: # comment | 2035 two: # comment |
2036 2, # comment | 2036 2, # comment |
2037 three: 3 # comment | 2037 three: 3 # comment |
2038 } | 2038 } |
2039 assert_equal(#{one: 1, two: 2, three: 3}, mydict) | 2039 assert_equal({one: 1, two: 2, three: 3}, mydict) |
2040 mydict = #{ | 2040 mydict = { |
2041 one: 1, | 2041 one: 1, |
2042 two: | 2042 two: |
2043 2, | 2043 2, |
2044 three: 3 | 2044 three: 3 |
2045 } | 2045 } |
2046 assert_equal(#{one: 1, two: 2, three: 3}, mydict) | 2046 assert_equal({one: 1, two: 2, three: 3}, mydict) |
2047 | 2047 |
2048 assert_equal( | 2048 assert_equal( |
2049 ['one', 'two', 'three'], | 2049 ['one', 'two', 'three'], |
2050 split('one two three') | 2050 split('one two three') |
2051 ) | 2051 ) |
2862 call writefile(['errors: ' .. string(v:errors)], 'Xdidcmd') | 2862 call writefile(['errors: ' .. string(v:errors)], 'Xdidcmd') |
2863 endfunc | 2863 endfunc |
2864 END | 2864 END |
2865 writefile([''], 'Xdidcmd') | 2865 writefile([''], 'Xdidcmd') |
2866 writefile(lines, 'XcallFunc') | 2866 writefile(lines, 'XcallFunc') |
2867 var buf = RunVimInTerminal('-S XcallFunc', #{rows: 6}) | 2867 var buf = RunVimInTerminal('-S XcallFunc', {rows: 6}) |
2868 # define Afunc() on the command line | 2868 # define Afunc() on the command line |
2869 term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>") | 2869 term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>") |
2870 term_sendkeys(buf, ":call CheckAndQuit()\<CR>") | 2870 term_sendkeys(buf, ":call CheckAndQuit()\<CR>") |
2871 WaitForAssert({-> assert_equal(['errors: []'], readfile('Xdidcmd'))}) | 2871 WaitForAssert({-> assert_equal(['errors: []'], readfile('Xdidcmd'))}) |
2872 | 2872 |
2957 [x, y] = [''] | 2957 [x, y] = [''] |
2958 catch | 2958 catch |
2959 g:caught = 'yes' | 2959 g:caught = 'yes' |
2960 endtry | 2960 endtry |
2961 enddef | 2961 enddef |
2962 popup_menu('popup', #{callback: Callback}) | 2962 popup_menu('popup', {callback: Callback}) |
2963 feedkeys("\r", 'xt') | 2963 feedkeys("\r", 'xt') |
2964 END | 2964 END |
2965 CheckScriptSuccess(lines) | 2965 CheckScriptSuccess(lines) |
2966 | 2966 |
2967 unlet g:caught | 2967 unlet g:caught |
2979 enddef | 2979 enddef |
2980 def Exit_cb(...l: any) | 2980 def Exit_cb(...l: any) |
2981 sleep 1m | 2981 sleep 1m |
2982 source += l | 2982 source += l |
2983 enddef | 2983 enddef |
2984 var myjob = job_start('echo burp', #{out_cb: Out_cb, exit_cb: Exit_cb, mode: 'raw'}) | 2984 var myjob = job_start('echo burp', {out_cb: Out_cb, exit_cb: Exit_cb, mode: 'raw'}) |
2985 sleep 100m | 2985 sleep 100m |
2986 END | 2986 END |
2987 writefile(lines, 'Xdef') | 2987 writefile(lines, 'Xdef') |
2988 assert_fails('so Xdef', ['E684:', 'E1012:']) | 2988 assert_fails('so Xdef', ['E684:', 'E1012:']) |
2989 delete('Xdef') | 2989 delete('Xdef') |