comparison src/testdir/test_vim9_assign.vim @ 26650:a07323eb647f v8.2.3854

patch 8.2.3854: Vim9: inconsistent arguments for test functions Commit: https://github.com/vim/vim/commit/86b3ab4fa0de3e8884ab6a6ced2a70592b937d0f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 19 18:33:23 2021 +0000 patch 8.2.3854: Vim9: inconsistent arguments for test functions Problem: Vim9: inconsistent arguments for test functions. Solution: When :def function and script have different arguments use a list with two items instead of a separate function.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Dec 2021 19:45:03 +0100
parents 57bc1001160b
children 434eaef2ac62
comparison
equal deleted inserted replaced
26649:8a10ad703e92 26650:a07323eb647f
278 278
279 lines =<< trim END 279 lines =<< trim END
280 var s = '-' 280 var s = '-'
281 s ..= [1, 2] 281 s ..= [1, 2]
282 END 282 END
283 CheckDefAndScriptFailure2(lines, 'E1105: Cannot convert list to string', 'E734: Wrong variable type for .=', 2) 283 CheckDefAndScriptFailure(lines, ['E1105: Cannot convert list to string', 'E734: Wrong variable type for .='], 2)
284 lines =<< trim END 284 lines =<< trim END
285 var s = '-' 285 var s = '-'
286 s ..= {a: 2} 286 s ..= {a: 2}
287 END 287 END
288 CheckDefAndScriptFailure2(lines, 'E1105: Cannot convert dict to string', 'E734: Wrong variable type for .=', 2) 288 CheckDefAndScriptFailure(lines, ['E1105: Cannot convert dict to string', 'E734: Wrong variable type for .='], 2)
289 enddef 289 enddef
290 290
291 def Test_assign_register() 291 def Test_assign_register()
292 var lines =<< trim END 292 var lines =<< trim END
293 @c = 'areg' 293 @c = 'areg'
491 + 2 491 + 2
492 + 3 492 + 3
493 + 4 493 + 4
494 + 5 494 + 5
495 END 495 END
496 CheckDefExecAndScriptFailure2(lines, 'E1148:', 'E1203:', 2) 496 CheckDefExecAndScriptFailure(lines, ['E1148:', 'E1203:'], 2)
497 enddef 497 enddef
498 498
499 def Test_assign_index() 499 def Test_assign_index()
500 # list of list 500 # list of list
501 var l1: list<number> 501 var l1: list<number>
781 assert_equal(6, v2) 781 assert_equal(6, v2)
782 782
783 var lines =<< trim END 783 var lines =<< trim END
784 var [v1, v2] = [1] 784 var [v1, v2] = [1]
785 END 785 END
786 CheckDefExecAndScriptFailure2(lines, 'E1093: Expected 2 items but got 1', 'E688:') 786 CheckDefExecAndScriptFailure(lines, ['E1093: Expected 2 items but got 1', 'E688:'])
787 lines =<< trim END 787 lines =<< trim END
788 var testlist = [1] 788 var testlist = [1]
789 var [v1, v2] = testlist 789 var [v1, v2] = testlist
790 END 790 END
791 CheckDefExecAndScriptFailure2(lines, 'E1093: Expected 2 items but got 1', 'E688:') 791 CheckDefExecAndScriptFailure(lines, ['E1093: Expected 2 items but got 1', 'E688:'])
792 lines =<< trim END 792 lines =<< trim END
793 var [v1, v2] = [1, 2, 3] 793 var [v1, v2] = [1, 2, 3]
794 END 794 END
795 CheckDefExecAndScriptFailure2(lines, 'E1093: Expected 2 items but got 3', 'E687:') 795 CheckDefExecAndScriptFailure(lines, ['E1093: Expected 2 items but got 3', 'E687:'])
796 lines =<< trim END 796 lines =<< trim END
797 var testlist = [1, 2, 3] 797 var testlist = [1, 2, 3]
798 var [v1, v2] = testlist 798 var [v1, v2] = testlist
799 END 799 END
800 CheckDefExecAndScriptFailure2(lines, 'E1093: Expected 2 items but got 3', 'E687:') 800 CheckDefExecAndScriptFailure(lines, ['E1093: Expected 2 items but got 3', 'E687:'])
801 801
802 var [vnr, vstr] = [123, 'text'] 802 var [vnr, vstr] = [123, 'text']
803 vnr += 3 803 vnr += 3
804 assert_equal(126, vnr) 804 assert_equal(126, vnr)
805 vstr ..= 'end' 805 vstr ..= 'end'
817 assert_equal(['foo', 'bar'], vlist) 817 assert_equal(['foo', 'bar'], vlist)
818 818
819 lines =<< trim END 819 lines =<< trim END
820 var [vnr2: number, vstr2: number] = [123, 'text'] 820 var [vnr2: number, vstr2: number] = [123, 'text']
821 END 821 END
822 CheckDefExecAndScriptFailure2(lines, 'E1163: Variable 2: type mismatch, expected number but got string', 'E1012: Type mismatch; expected number but got string') 822 CheckDefExecAndScriptFailure(lines, ['E1163: Variable 2: type mismatch, expected number but got string', 'E1012: Type mismatch; expected number but got string'])
823 lines =<< trim END 823 lines =<< trim END
824 var testlist = [234, 'text'] 824 var testlist = [234, 'text']
825 var [vnr2: number, vstr2: number] = testlist 825 var [vnr2: number, vstr2: number] = testlist
826 END 826 END
827 CheckDefExecAndScriptFailure2(lines, 'E1163: Variable 2: type mismatch, expected number but got string', 'E1012: Type mismatch; expected number but got string') 827 CheckDefExecAndScriptFailure(lines, ['E1163: Variable 2: type mismatch, expected number but got string', 'E1012: Type mismatch; expected number but got string'])
828 enddef 828 enddef
829 829
830 def PartFuncBool(b: bool): string 830 def PartFuncBool(b: bool): string
831 return 'done' 831 return 'done'
832 enddef 832 enddef
987 987
988 lines =<< trim END 988 lines =<< trim END
989 var n: any 989 var n: any
990 n.key = 5 990 n.key = 5
991 END 991 END
992 CheckDefExecAndScriptFailure2(lines, 'E1148:', 'E1203: Dot can only be used on a dictionary: n.key = 5', 2) 992 CheckDefExecAndScriptFailure(lines, ['E1148:', 'E1203: Dot can only be used on a dictionary: n.key = 5'], 2)
993 enddef 993 enddef
994 994
995 def Test_assignment_local() 995 def Test_assignment_local()
996 # Test in a separated file in order not to the current buffer/window/tab is 996 # Test in a separated file in order not to the current buffer/window/tab is
997 # changed. 997 # changed.
1455 def Test_assign_with_op_fails() 1455 def Test_assign_with_op_fails()
1456 var lines =<< trim END 1456 var lines =<< trim END
1457 var s = 'abc' 1457 var s = 'abc'
1458 s[1] += 'x' 1458 s[1] += 'x'
1459 END 1459 END
1460 CheckDefAndScriptFailure2(lines, 'E1141:', 'E689:', 2) 1460 CheckDefAndScriptFailure(lines, ['E1141:', 'E689:'], 2)
1461 1461
1462 lines =<< trim END 1462 lines =<< trim END
1463 var s = 'abc' 1463 var s = 'abc'
1464 s[1] ..= 'x' 1464 s[1] ..= 'x'
1465 END 1465 END
1466 CheckDefAndScriptFailure2(lines, 'E1141:', 'E689:', 2) 1466 CheckDefAndScriptFailure(lines, ['E1141:', 'E689:'], 2)
1467 1467
1468 lines =<< trim END 1468 lines =<< trim END
1469 var dd: dict<dict<list<any>>> 1469 var dd: dict<dict<list<any>>>
1470 dd.a = {} 1470 dd.a = {}
1471 dd.a.b += [1] 1471 dd.a.b += [1]