comparison src/testdir/test_vim9_expr.vim @ 21831:d8422de73113 v8.2.1465

patch 8.2.1465: Vim9: subscript not handled properly Commit: https://github.com/vim/vim/commit/56acb0943ede35cd9d2f6667cde2442819ccbf59 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 16 14:48:19 2020 +0200 patch 8.2.1465: Vim9: subscript not handled properly Problem: Vim9: subscript not handled properly. Solution: Adjust error message. Remove dead code. Disallow string to number conversion in scripts.
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Aug 2020 15:00:05 +0200
parents af5db9b6d210
children e3f9528bddda
comparison
equal deleted inserted replaced
21830:bef87368c676 21831:d8422de73113
382 call CheckDefFailure(["let x = 1&&2"], msg) 382 call CheckDefFailure(["let x = 1&&2"], msg)
383 call CheckDefFailure(["let x = 1 &&2"], msg) 383 call CheckDefFailure(["let x = 1 &&2"], msg)
384 call CheckDefFailure(["let x = 1&& 2"], msg) 384 call CheckDefFailure(["let x = 1&& 2"], msg)
385 endfunc 385 endfunc
386 386
387 " global variables to use for tests with the "any" type
387 let atrue = v:true 388 let atrue = v:true
388 let afalse = v:false 389 let afalse = v:false
389 let anone = v:none 390 let anone = v:none
390 let anull = v:null 391 let anull = v:null
391 let anint = 10 392 let anint = 10
392 let alsoint = 4 393 let theone = 1
394 let thefour = 4
393 if has('float') 395 if has('float')
394 let afloat = 0.1 396 let afloat = 0.1
395 endif 397 endif
396 let astring = 'asdf' 398 let astring = 'asdf'
397 let ablob = 0z01ab 399 let ablob = 0z01ab
899 " test addition, subtraction, concatenation 901 " test addition, subtraction, concatenation
900 def Test_expr5() 902 def Test_expr5()
901 assert_equal(66, 60 + 6) 903 assert_equal(66, 60 + 6)
902 assert_equal(70, 60 + 904 assert_equal(70, 60 +
903 g:anint) 905 g:anint)
904 assert_equal(9, g:alsoint 906 assert_equal(9, g:thefour
905 + 5) 907 + 5)
906 assert_equal(14, g:alsoint + g:anint) 908 assert_equal(14, g:thefour + g:anint)
907 assert_equal([1, 2, 3, 4], [1] + g:alist) 909 assert_equal([1, 2, 3, 4], [1] + g:alist)
908 910
909 assert_equal(54, 60 - 6) 911 assert_equal(54, 60 - 6)
910 assert_equal(50, 60 - 912 assert_equal(50, 60 -
911 g:anint) 913 g:anint)
912 assert_equal(-1, g:alsoint 914 assert_equal(-1, g:thefour
913 - 5) 915 - 5)
914 assert_equal(-6, g:alsoint - g:anint) 916 assert_equal(-6, g:thefour - g:anint)
915 917
916 assert_equal('hello', 'hel' .. 'lo') 918 assert_equal('hello', 'hel' .. 'lo')
917 assert_equal('hello 123', 'hello ' .. 919 assert_equal('hello 123', 'hello ' ..
918 123) 920 123)
919 assert_equal('hello 123', 'hello ' 921 assert_equal('hello 123', 'hello '
1134 1136
1135 " test multiply, divide, modulo 1137 " test multiply, divide, modulo
1136 def Test_expr6() 1138 def Test_expr6()
1137 assert_equal(36, 6 * 6) 1139 assert_equal(36, 6 * 6)
1138 assert_equal(24, 6 * 1140 assert_equal(24, 6 *
1139 g:alsoint) 1141 g:thefour)
1140 assert_equal(24, g:alsoint 1142 assert_equal(24, g:thefour
1141 * 6) 1143 * 6)
1142 assert_equal(40, g:anint * g:alsoint) 1144 assert_equal(40, g:anint * g:thefour)
1143 1145
1144 assert_equal(10, 60 / 6) 1146 assert_equal(10, 60 / 6)
1145 assert_equal(6, 60 / 1147 assert_equal(6, 60 /
1146 g:anint) 1148 g:anint)
1147 assert_equal(1, g:anint / 6) 1149 assert_equal(1, g:anint / 6)
1148 assert_equal(2, g:anint 1150 assert_equal(2, g:anint
1149 / g:alsoint) 1151 / g:thefour)
1150 1152
1151 assert_equal(5, 11 % 6) 1153 assert_equal(5, 11 % 6)
1152 assert_equal(4, g:anint % 6) 1154 assert_equal(4, g:anint % 6)
1153 assert_equal(3, 13 % 1155 assert_equal(3, 13 %
1154 g:anint) 1156 g:anint)
1155 assert_equal(2, g:anint 1157 assert_equal(2, g:anint
1156 % g:alsoint) 1158 % g:thefour)
1157 1159
1158 assert_equal(4, 6 * 4 / 6) 1160 assert_equal(4, 6 * 4 / 6)
1159 1161
1160 let x = [2] 1162 let x = [2]
1161 let y = [3] 1163 let y = [3]
1321 let $TESTVAR = 'testvar' 1323 let $TESTVAR = 'testvar'
1322 1324
1323 " type casts 1325 " type casts
1324 def Test_expr7t() 1326 def Test_expr7t()
1325 let ls: list<string> = ['a', <string>g:string_empty] 1327 let ls: list<string> = ['a', <string>g:string_empty]
1326 let ln: list<number> = [<number>g:anint, <number>g:alsoint] 1328 let ln: list<number> = [<number>g:anint, <number>g:thefour]
1327 let nr = <number>234 1329 let nr = <number>234
1328 assert_equal(234, nr) 1330 assert_equal(234, nr)
1329 1331
1330 call CheckDefFailure(["let x = <nr>123"], 'E1010:') 1332 call CheckDefFailure(["let x = <nr>123"], 'E1010:')
1331 call CheckDefFailure(["let x = <number >123"], 'E1068:') 1333 call CheckDefFailure(["let x = <number >123"], 'E1068:')
1446 strings = ['x'] 1448 strings = ['x']
1447 strings = [] 1449 strings = []
1448 1450
1449 let mixed: list<any> = [1, 'b', false,] 1451 let mixed: list<any> = [1, 'b', false,]
1450 assert_equal(g:list_mixed, mixed) 1452 assert_equal(g:list_mixed, mixed)
1451 assert_equal('b', g:list_mixed[1]) 1453 assert_equal('b', mixed[1])
1452 1454
1453 echo [1, 1455 echo [1,
1454 2] [3, 1456 2] [3,
1455 4] 1457 4]
1456 1458
1457 call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:') 1459 call CheckDefFailure(["let x = 1234[3]"], 'E1107:')
1460 call CheckDefExecFailure(["let x = g:anint[3]"], 'E1029:')
1461
1458 call CheckDefFailure(["let x = g:list_mixed[xxx]"], 'E1001:') 1462 call CheckDefFailure(["let x = g:list_mixed[xxx]"], 'E1001:')
1459 1463
1460 call CheckDefFailure(["let x = [1,2,3]"], 'E1069:') 1464 call CheckDefFailure(["let x = [1,2,3]"], 'E1069:')
1461 call CheckDefFailure(["let x = [1 ,2, 3]"], 'E1068:') 1465 call CheckDefFailure(["let x = [1 ,2, 3]"], 'E1068:')
1462 1466
2134 assert_equal([1, 2, 3, 4], list[1:]) 2138 assert_equal([1, 2, 3, 4], list[1:])
2135 assert_equal([2, 3, 4], list[2:-1]) 2139 assert_equal([2, 3, 4], list[2:-1])
2136 assert_equal([4], list[4:-1]) 2140 assert_equal([4], list[4:-1])
2137 assert_equal([], list[5:-1]) 2141 assert_equal([], list[5:-1])
2138 assert_equal([], list[999:-1]) 2142 assert_equal([], list[999:-1])
2143 assert_equal([1, 2, 3, 4], list[g:theone:g:thefour])
2139 2144
2140 assert_equal([0, 1, 2, 3], list[0:3]) 2145 assert_equal([0, 1, 2, 3], list[0:3])
2141 assert_equal([0], list[0:0]) 2146 assert_equal([0], list[0:0])
2142 assert_equal([0, 1, 2, 3, 4], list[0:-1]) 2147 assert_equal([0, 1, 2, 3, 4], list[0:-1])
2143 assert_equal([0, 1, 2], list[0:-3]) 2148 assert_equal([0, 1, 2], list[0:-3])
2145 assert_equal([], list[0:-6]) 2150 assert_equal([], list[0:-6])
2146 assert_equal([], list[0:-99]) 2151 assert_equal([], list[0:-99])
2147 END 2152 END
2148 CheckDefSuccess(lines) 2153 CheckDefSuccess(lines)
2149 CheckScriptSuccess(['vim9script'] + lines) 2154 CheckScriptSuccess(['vim9script'] + lines)
2155
2156 lines = ['let l = [0, 1, 2]', 'echo l[g:astring : g:theone]']
2157 CheckDefExecFailure(lines, 'E1029:')
2158 CheckScriptFailure(['vim9script'] + lines, 'E1030:')
2150 enddef 2159 enddef
2151 2160
2152 def Test_expr7_subscript_linebreak() 2161 def Test_expr7_subscript_linebreak()
2153 let range = range( 2162 let range = range(
2154 3) 2163 3)