comparison src/testdir/test_vim9_expr.vim @ 28846:0541b9c09e21 v8.2.4946

patch 8.2.4946: Vim9: some code not covered by tests Commit: https://github.com/vim/vim/commit/7f8a3b11bfc02f24dfd877d0a81392d679008180 Author: Bram Moolenaar <Bram@vim.org> Date: Thu May 12 22:03:01 2022 +0100 patch 8.2.4946: Vim9: some code not covered by tests Problem: Vim9: some code not covered by tests. Solution: Add a few more test cases. Remove dead code.
author Bram Moolenaar <Bram@vim.org>
date Thu, 12 May 2022 23:15:03 +0200
parents bf013128ccf4
children ffd57385eef8
comparison
equal deleted inserted replaced
28845:8855a6ea2068 28846:0541b9c09e21
2149 var vv = $"some {val}" 2149 var vv = $"some {val}"
2150 assert_equal('some val', vv) 2150 assert_equal('some val', vv)
2151 vv = $'other {val}' 2151 vv = $'other {val}'
2152 assert_equal('other val', vv) 2152 assert_equal('other val', vv)
2153 2153
2154 v9.CheckDefAndScriptFailure(['var x = $"foo'], 'E114:', 1)
2155 v9.CheckDefAndScriptFailure(['var x = $"foo{xxx}"'], ['E1001: Variable not found: xxx', 'E121: Undefined variable: xxx'], 1)
2156
2154 var x = 'x' 2157 var x = 'x'
2155 var vl = 'foo xxx bar xxx baz' 2158 var vl = 'foo xxx bar xxx baz'
2156 ->split($'x{x}x') 2159 ->split($'x{x}x')
2157 ->map((_, v: string) => v =~ 'bar') 2160 ->map((_, v: string) => v =~ 'bar')
2158 assert_equal([false, true, false], vl) 2161 assert_equal([false, true, false], vl)
2816 v9.CheckDefAndScriptFailure(["var x = {['a']: xxx}"], ['E1001:', 'E121:'], 1) 2819 v9.CheckDefAndScriptFailure(["var x = {['a']: xxx}"], ['E1001:', 'E121:'], 1)
2817 v9.CheckDefAndScriptFailure(["var x = {a: 1, a: 2}"], 'E721:', 1) 2820 v9.CheckDefAndScriptFailure(["var x = {a: 1, a: 2}"], 'E721:', 1)
2818 g:key = 'x' 2821 g:key = 'x'
2819 v9.CheckDefExecAndScriptFailure(["var x = {[g:key]: 'text', [g:key]: 'text'}"], 'E721:', 1) 2822 v9.CheckDefExecAndScriptFailure(["var x = {[g:key]: 'text', [g:key]: 'text'}"], 'E721:', 1)
2820 unlet g:key 2823 unlet g:key
2824 v9.CheckDefExecAndScriptFailure(["var x = {[notexists]: 'text'}"], ['E1001:', 'E121: Undefined variable: notexists'], 1)
2821 v9.CheckDefExecAndScriptFailure(["var x = g:anint.member"], ['E715:', 'E488:'], 1) 2825 v9.CheckDefExecAndScriptFailure(["var x = g:anint.member"], ['E715:', 'E488:'], 1)
2822 v9.CheckDefExecAndScriptFailure(["var x = g:dict_empty.member"], 'E716:', 1) 2826 v9.CheckDefExecAndScriptFailure(["var x = g:dict_empty.member"], 'E716:', 1)
2823 2827
2824 v9.CheckDefExecAndScriptFailure(['var x: dict<number> = {a: 234, b: "1"}'], 'E1012:', 1) 2828 v9.CheckDefExecAndScriptFailure(['var x: dict<number> = {a: 234, b: "1"}'], 'E1012:', 1)
2825 v9.CheckDefExecAndScriptFailure(['var x: dict<number> = {a: "x", b: 134}'], 'E1012:', 1) 2829 v9.CheckDefExecAndScriptFailure(['var x: dict<number> = {a: "x", b: 134}'], 'E1012:', 1)
3368 'two' 3372 'two'
3369 ) 3373 )
3370 assert_equal('onetwo', s) 3374 assert_equal('onetwo', s)
3371 END 3375 END
3372 v9.CheckDefAndScriptSuccess(lines) 3376 v9.CheckDefAndScriptSuccess(lines)
3377
3378 v9.CheckDefAndScriptFailure(['echo ('], ['E1097: Line incomplete', 'E15: Invalid expression: "("'])
3379 v9.CheckDefAndScriptFailure(['echo (123]'], "E110: Missing ')'", 1)
3373 enddef 3380 enddef
3374 3381
3375 def Test_expr8_negate_add() 3382 def Test_expr8_negate_add()
3376 var lines =<< trim END 3383 var lines =<< trim END
3377 assert_equal(-99, -99) 3384 assert_equal(-99, -99)
3478 v9.CheckDefAndScriptFailure(["var x = 'yes'->g:Echo"], 'E107:', 1) 3485 v9.CheckDefAndScriptFailure(["var x = 'yes'->g:Echo"], 'E107:', 1)
3479 v9.CheckDefAndScriptFailure([ 3486 v9.CheckDefAndScriptFailure([
3480 "var x = substitute ('x', 'x', 'x', 'x')" 3487 "var x = substitute ('x', 'x', 'x', 'x')"
3481 ], ['E1001:', 'E121:'], 1) 3488 ], ['E1001:', 'E121:'], 1)
3482 v9.CheckDefAndScriptFailure(["var Ref = function('len' [1, 2])"], ['E1123:', 'E116:'], 1) 3489 v9.CheckDefAndScriptFailure(["var Ref = function('len' [1, 2])"], ['E1123:', 'E116:'], 1)
3490 v9.CheckDefAndScriptFailure(["echo match(['foo'] , 'foo')"], 'E1068:', 1)
3483 enddef 3491 enddef
3484 3492
3485 def g:ExistingGlobal(): string 3493 def g:ExistingGlobal(): string
3486 return 'existing' 3494 return 'existing'
3487 enddef 3495 enddef
3998 assert_equal(0z01ab, g:ablob[:]) 4006 assert_equal(0z01ab, g:ablob[:])
3999 END 4007 END
4000 v9.CheckDefAndScriptSuccess(lines) 4008 v9.CheckDefAndScriptSuccess(lines)
4001 enddef 4009 enddef
4002 4010
4011 def Test_expr8_funcref_subscript()
4012 var lines =<< trim END
4013 var l = function('len')("abc")
4014 assert_equal(3, l)
4015 END
4016 v9.CheckDefAndScriptSuccess(lines)
4017
4018 v9.CheckDefAndScriptFailure(["var l = function('len')(xxx)"], ['E1001: Variable not found: xxx', 'E121: Undefined variable: xxx'], 1)
4019 enddef
4020
4003 def Test_expr8_subscript_linebreak() 4021 def Test_expr8_subscript_linebreak()
4004 var lines =<< trim END 4022 var lines =<< trim END
4005 var range = range( 4023 var range = range(
4006 3) 4024 3)
4007 var l = range 4025 var l = range