Mercurial > vim
comparison src/testdir/test_vim9_expr.vim @ 23414:9bd3873b13e2 v8.2.2250
patch 8.2.2250: Vim9: sublist is ambiguous
Commit: https://github.com/vim/vim/commit/de4f95b04134f6dfd10f60051a5078fd903a297d
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Dec 30 20:39:21 2020 +0100
patch 8.2.2250: Vim9: sublist is ambiguous
Problem: Vim9: sublist is ambiguous.
Solution: Require white space around the colon. (closes https://github.com/vim/vim/issues/7409)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 30 Dec 2020 20:45:03 +0100 |
parents | a7cbdb9294c4 |
children | 681f042ae5ac |
comparison
equal
deleted
inserted
replaced
23413:490f599d5bbc | 23414:9bd3873b13e2 |
---|---|
1716 datalist += ['x'. | 1716 datalist += ['x'. |
1717 enddef | 1717 enddef |
1718 Main() | 1718 Main() |
1719 END | 1719 END |
1720 CheckScriptFailure(lines, 'E1127:') | 1720 CheckScriptFailure(lines, 'E1127:') |
1721 | |
1722 lines =<< trim END | |
1723 var numbers = [1, 2, 3, 4] | |
1724 var a = 1 | |
1725 var b = 2 | |
1726 END | |
1727 CheckDefAndScriptFailure(lines + ['echo numbers[1:b]'], 'E1004:', 4) | |
1728 CheckDefAndScriptFailure(lines + ['echo numbers[1: b]'], 'E1004:', 4) | |
1729 CheckDefAndScriptFailure(lines + ['echo numbers[a :b]'], 'E1004:', 4) | |
1721 enddef | 1730 enddef |
1722 | 1731 |
1723 def Test_expr7_list_vim9script() | 1732 def Test_expr7_list_vim9script() |
1724 var lines =<< trim END | 1733 var lines =<< trim END |
1725 vim9script | 1734 vim9script |
2272 g:teststring = 'abcdef' | 2281 g:teststring = 'abcdef' |
2273 assert_equal('b', g:teststring[1]) | 2282 assert_equal('b', g:teststring[1]) |
2274 assert_equal('', g:teststring[-1]) | 2283 assert_equal('', g:teststring[-1]) |
2275 assert_equal('', g:teststring[99]) | 2284 assert_equal('', g:teststring[99]) |
2276 | 2285 |
2277 assert_equal('b', g:teststring[1:1]) | 2286 assert_equal('b', g:teststring[1 : 1]) |
2278 assert_equal('bcdef', g:teststring[1:]) | 2287 assert_equal('bcdef', g:teststring[1 :]) |
2279 assert_equal('abcd', g:teststring[:3]) | 2288 assert_equal('abcd', g:teststring[: 3]) |
2280 assert_equal('cdef', g:teststring[-4:]) | 2289 assert_equal('cdef', g:teststring[-4 :]) |
2281 assert_equal('abcdef', g:teststring[-9:]) | 2290 assert_equal('abcdef', g:teststring[-9 :]) |
2282 assert_equal('abcd', g:teststring[:-3]) | 2291 assert_equal('abcd', g:teststring[: -3]) |
2283 assert_equal('', g:teststring[:-9]) | 2292 assert_equal('', g:teststring[: -9]) |
2284 | 2293 |
2285 # blob index cannot be out of range | 2294 # blob index cannot be out of range |
2286 g:testblob = 0z01ab | 2295 g:testblob = 0z01ab |
2287 assert_equal(0x01, g:testblob[0]) | 2296 assert_equal(0x01, g:testblob[0]) |
2288 assert_equal(0xab, g:testblob[1]) | 2297 assert_equal(0xab, g:testblob[1]) |
2289 assert_equal(0xab, g:testblob[-1]) | 2298 assert_equal(0xab, g:testblob[-1]) |
2290 assert_equal(0x01, g:testblob[-2]) | 2299 assert_equal(0x01, g:testblob[-2]) |
2291 | 2300 |
2292 # blob slice accepts out of range | 2301 # blob slice accepts out of range |
2293 assert_equal(0z01ab, g:testblob[0:1]) | 2302 assert_equal(0z01ab, g:testblob[0 : 1]) |
2294 assert_equal(0z01, g:testblob[0:0]) | 2303 assert_equal(0z01, g:testblob[0 : 0]) |
2295 assert_equal(0z01, g:testblob[-2:-2]) | 2304 assert_equal(0z01, g:testblob[-2 : -2]) |
2296 assert_equal(0zab, g:testblob[1:1]) | 2305 assert_equal(0zab, g:testblob[1 : 1]) |
2297 assert_equal(0zab, g:testblob[-1:-1]) | 2306 assert_equal(0zab, g:testblob[-1 : -1]) |
2298 assert_equal(0z, g:testblob[2:2]) | 2307 assert_equal(0z, g:testblob[2 : 2]) |
2299 assert_equal(0z, g:testblob[0:-3]) | 2308 assert_equal(0z, g:testblob[0 : -3]) |
2300 | 2309 |
2301 # list index cannot be out of range | 2310 # list index cannot be out of range |
2302 g:testlist = [0, 1, 2, 3] | 2311 g:testlist = [0, 1, 2, 3] |
2303 assert_equal(0, g:testlist[0]) | 2312 assert_equal(0, g:testlist[0]) |
2304 assert_equal(1, g:testlist[1]) | 2313 assert_equal(1, g:testlist[1]) |
2306 assert_equal(3, g:testlist[-1]) | 2315 assert_equal(3, g:testlist[-1]) |
2307 assert_equal(0, g:testlist[-4]) | 2316 assert_equal(0, g:testlist[-4]) |
2308 assert_equal(1, g:testlist[g:theone]) | 2317 assert_equal(1, g:testlist[g:theone]) |
2309 | 2318 |
2310 # list slice accepts out of range | 2319 # list slice accepts out of range |
2311 assert_equal([0], g:testlist[0:0]) | 2320 assert_equal([0], g:testlist[0 : 0]) |
2312 assert_equal([3], g:testlist[3:3]) | 2321 assert_equal([3], g:testlist[3 : 3]) |
2313 assert_equal([0, 1], g:testlist[0:1]) | 2322 assert_equal([0, 1], g:testlist[0 : 1]) |
2314 assert_equal([0, 1, 2, 3], g:testlist[0:3]) | 2323 assert_equal([0, 1, 2, 3], g:testlist[0 : 3]) |
2315 assert_equal([0, 1, 2, 3], g:testlist[0:9]) | 2324 assert_equal([0, 1, 2, 3], g:testlist[0 : 9]) |
2316 assert_equal([], g:testlist[-1:1]) | 2325 assert_equal([], g:testlist[-1 : 1]) |
2317 assert_equal([1], g:testlist[-3:1]) | 2326 assert_equal([1], g:testlist[-3 : 1]) |
2318 assert_equal([0, 1], g:testlist[-4:1]) | 2327 assert_equal([0, 1], g:testlist[-4 : 1]) |
2319 assert_equal([0, 1], g:testlist[-9:1]) | 2328 assert_equal([0, 1], g:testlist[-9 : 1]) |
2320 assert_equal([1, 2, 3], g:testlist[1:-1]) | 2329 assert_equal([1, 2, 3], g:testlist[1 : -1]) |
2321 assert_equal([1], g:testlist[1:-3]) | 2330 assert_equal([1], g:testlist[1 : -3]) |
2322 assert_equal([], g:testlist[1:-4]) | 2331 assert_equal([], g:testlist[1 : -4]) |
2323 assert_equal([], g:testlist[1:-9]) | 2332 assert_equal([], g:testlist[1 : -9]) |
2324 | 2333 |
2325 g:testdict = {a: 1, b: 2} | 2334 g:testdict = {a: 1, b: 2} |
2326 assert_equal(1, g:testdict['a']) | 2335 assert_equal(1, g:testdict['a']) |
2327 assert_equal(2, g:testdict['b']) | 2336 assert_equal(2, g:testdict['b']) |
2328 END | 2337 END |
2338 CheckDefExecFailure(['echo g:testlist[4]'], 'E684:', 1) | 2347 CheckDefExecFailure(['echo g:testlist[4]'], 'E684:', 1) |
2339 CheckScriptFailure(['vim9script', 'echo g:testlist[4]'], 'E684:', 2) | 2348 CheckScriptFailure(['vim9script', 'echo g:testlist[4]'], 'E684:', 2) |
2340 CheckDefExecFailure(['echo g:testlist[-5]'], 'E684:', 1) | 2349 CheckDefExecFailure(['echo g:testlist[-5]'], 'E684:', 1) |
2341 CheckScriptFailure(['vim9script', 'echo g:testlist[-5]'], 'E684:', 2) | 2350 CheckScriptFailure(['vim9script', 'echo g:testlist[-5]'], 'E684:', 2) |
2342 | 2351 |
2343 CheckDefExecFailure(['echo g:testdict["a":"b"]'], 'E719:', 1) | 2352 CheckDefExecFailure(['echo g:testdict["a" : "b"]'], 'E719:', 1) |
2344 CheckScriptFailure(['vim9script', 'echo g:testdict["a":"b"]'], 'E719:', 2) | 2353 CheckScriptFailure(['vim9script', 'echo g:testdict["a" : "b"]'], 'E719:', 2) |
2345 CheckDefExecFailure(['echo g:testdict[1]'], 'E716:', 1) | 2354 CheckDefExecFailure(['echo g:testdict[1]'], 'E716:', 1) |
2346 CheckScriptFailure(['vim9script', 'echo g:testdict[1]'], 'E716:', 2) | 2355 CheckScriptFailure(['vim9script', 'echo g:testdict[1]'], 'E716:', 2) |
2347 | 2356 |
2348 unlet g:teststring | 2357 unlet g:teststring |
2349 unlet g:testblob | 2358 unlet g:testblob |
2744 assert_equal('ë', text[4]) | 2753 assert_equal('ë', text[4]) |
2745 assert_equal('f', text[5]) | 2754 assert_equal('f', text[5]) |
2746 assert_equal('', text[6]) | 2755 assert_equal('', text[6]) |
2747 assert_equal('', text[999]) | 2756 assert_equal('', text[999]) |
2748 | 2757 |
2749 assert_equal('ábçdëf', text[0:-1]) | 2758 assert_equal('ábçdëf', text[0 : -1]) |
2750 assert_equal('ábçdëf', text[0 :-1]) | 2759 assert_equal('ábçdëf', text[0 : -1]) |
2751 assert_equal('ábçdëf', text[0: -1]) | 2760 assert_equal('ábçdëf', text[0 : -1]) |
2752 assert_equal('ábçdëf', text[0 : -1]) | 2761 assert_equal('ábçdëf', text[0 : -1]) |
2753 assert_equal('ábçdëf', text[0 | 2762 assert_equal('ábçdëf', text[0 |
2754 :-1]) | 2763 : -1]) |
2755 assert_equal('ábçdëf', text[0: | 2764 assert_equal('ábçdëf', text[0 : |
2756 -1]) | 2765 -1]) |
2757 assert_equal('ábçdëf', text[0 : -1 | 2766 assert_equal('ábçdëf', text[0 : -1 |
2758 ]) | 2767 ]) |
2759 assert_equal('bçdëf', text[1:-1]) | 2768 assert_equal('bçdëf', text[1 : -1]) |
2760 assert_equal('çdëf', text[2:-1]) | 2769 assert_equal('çdëf', text[2 : -1]) |
2761 assert_equal('dëf', text[3:-1]) | 2770 assert_equal('dëf', text[3 : -1]) |
2762 assert_equal('ëf', text[4:-1]) | 2771 assert_equal('ëf', text[4 : -1]) |
2763 assert_equal('f', text[5:-1]) | 2772 assert_equal('f', text[5 : -1]) |
2764 assert_equal('', text[6:-1]) | 2773 assert_equal('', text[6 : -1]) |
2765 assert_equal('', text[999:-1]) | 2774 assert_equal('', text[999 : -1]) |
2766 | 2775 |
2767 assert_equal('ábçd', text[:3]) | 2776 assert_equal('ábçd', text[: 3]) |
2768 assert_equal('bçdëf', text[1:]) | 2777 assert_equal('bçdëf', text[1 :]) |
2769 assert_equal('ábçdëf', text[:]) | 2778 assert_equal('ábçdëf', text[:]) |
2770 END | 2779 END |
2771 CheckDefSuccess(lines) | 2780 CheckDefSuccess(lines) |
2772 CheckScriptSuccess(['vim9script'] + lines) | 2781 CheckScriptSuccess(['vim9script'] + lines) |
2773 | 2782 |
2774 lines =<< trim END | 2783 lines =<< trim END |
2775 var d = 'asdf'[1: | 2784 var d = 'asdf'[1 : |
2776 END | 2785 END |
2777 CheckDefFailure(lines, 'E1097:', 3) | 2786 CheckDefFailure(lines, 'E1097:', 3) |
2778 lines =<< trim END | 2787 lines =<< trim END |
2779 var d = 'asdf'[1:xxx] | 2788 var d = 'asdf'[1 : xxx] |
2780 END | 2789 END |
2781 CheckDefFailure(lines, 'E1001:', 1) | 2790 CheckDefFailure(lines, 'E1001:', 1) |
2782 lines =<< trim END | 2791 lines =<< trim END |
2783 var d = 'asdf'[1:2 | 2792 var d = 'asdf'[1 : 2 |
2784 END | 2793 END |
2785 CheckDefFailure(lines, 'E1097:', 3) | 2794 CheckDefFailure(lines, 'E1097:', 3) |
2786 lines =<< trim END | 2795 lines =<< trim END |
2787 var d = 'asdf'[1:2 | 2796 var d = 'asdf'[1 : 2 |
2788 echo d | 2797 echo d |
2789 END | 2798 END |
2790 CheckDefFailure(lines, 'E111:', 2) | 2799 CheckDefFailure(lines, 'E111:', 2) |
2791 lines =<< trim END | 2800 lines =<< trim END |
2792 var d = 'asdf'['1'] | 2801 var d = 'asdf'['1'] |
2793 echo d | 2802 echo d |
2794 END | 2803 END |
2795 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) | 2804 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) |
2796 lines =<< trim END | 2805 lines =<< trim END |
2797 var d = 'asdf'['1':2] | 2806 var d = 'asdf'['1' : 2] |
2798 echo d | 2807 echo d |
2799 END | 2808 END |
2800 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) | 2809 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) |
2801 lines =<< trim END | 2810 lines =<< trim END |
2802 var d = 'asdf'[1:'2'] | 2811 var d = 'asdf'[1 : '2'] |
2803 echo d | 2812 echo d |
2804 END | 2813 END |
2805 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) | 2814 CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got string', 1) |
2806 enddef | 2815 enddef |
2807 | 2816 |
2811 assert_equal(0, list[0]) | 2820 assert_equal(0, list[0]) |
2812 assert_equal(4, list[4]) | 2821 assert_equal(4, list[4]) |
2813 assert_equal(4, list[-1]) | 2822 assert_equal(4, list[-1]) |
2814 assert_equal(0, list[-5]) | 2823 assert_equal(0, list[-5]) |
2815 | 2824 |
2816 assert_equal([0, 1, 2, 3, 4], list[0:4]) | 2825 assert_equal([0, 1, 2, 3, 4], list[0 : 4]) |
2817 assert_equal([0, 1, 2, 3, 4], list[:]) | 2826 assert_equal([0, 1, 2, 3, 4], list[:]) |
2818 assert_equal([1, 2, 3, 4], list[1:]) | 2827 assert_equal([1, 2, 3, 4], list[1 :]) |
2819 assert_equal([2, 3, 4], list[2:-1]) | 2828 assert_equal([2, 3, 4], list[2 : -1]) |
2820 assert_equal([4], list[4:-1]) | 2829 assert_equal([4], list[4 : -1]) |
2821 assert_equal([], list[5:-1]) | 2830 assert_equal([], list[5 : -1]) |
2822 assert_equal([], list[999:-1]) | 2831 assert_equal([], list[999 : -1]) |
2823 assert_equal([1, 2, 3, 4], list[g:theone:g:thefour]) | 2832 assert_equal([1, 2, 3, 4], list[g:theone : g:thefour]) |
2824 | 2833 |
2825 assert_equal([0, 1, 2, 3], list[0:3]) | 2834 assert_equal([0, 1, 2, 3], list[0 : 3]) |
2826 assert_equal([0], list[0:0]) | 2835 assert_equal([0], list[0 : 0]) |
2827 assert_equal([0, 1, 2, 3, 4], list[0:-1]) | 2836 assert_equal([0, 1, 2, 3, 4], list[0 : -1]) |
2828 assert_equal([0, 1, 2], list[0:-3]) | 2837 assert_equal([0, 1, 2], list[0 : -3]) |
2829 assert_equal([0], list[0:-5]) | 2838 assert_equal([0], list[0 : -5]) |
2830 assert_equal([], list[0:-6]) | 2839 assert_equal([], list[0 : -6]) |
2831 assert_equal([], list[0:-99]) | 2840 assert_equal([], list[0 : -99]) |
2832 END | 2841 END |
2833 CheckDefSuccess(lines) | 2842 CheckDefSuccess(lines) |
2834 CheckScriptSuccess(['vim9script'] + lines) | 2843 CheckScriptSuccess(['vim9script'] + lines) |
2835 | 2844 |
2836 lines = ['var l = [0, 1, 2]', 'echo l[g:astring : g:theone]'] | 2845 lines = ['var l = [0, 1, 2]', 'echo l[g:astring : g:theone]'] |