Mercurial > vim
changeset 22866:52e64d340a98 v8.2.1980
patch 8.2.1980: Vim9: some tests are not done at the script level
Commit: https://github.com/vim/vim/commit/659bb2275e1c407709e2ac949044d6b256de5550
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 12 20:16:39 2020 +0100
patch 8.2.1980: Vim9: some tests are not done at the script level
Problem: Vim9: some tests are not done at the script level.
Solution: Use CheckDefAndScriptSuccess() in more places. Fix uncovered
problems.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 12 Nov 2020 20:30:04 +0100 |
parents | c026019f112a |
children | ed4a1aad0a9f |
files | src/eval.c src/list.c src/scriptfile.c src/testdir/test_vim9_expr.vim src/version.c |
diffstat | 5 files changed, 688 insertions(+), 675 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -3438,7 +3438,15 @@ eval7_leader( } #ifdef FEAT_FLOAT if (rettv->v_type == VAR_FLOAT) - f = !f; + { + if (in_vim9script()) + { + rettv->v_type = VAR_BOOL; + val = f == 0.0 ? VVAL_TRUE : VVAL_FALSE; + } + else + f = !f; + } else #endif {
--- a/src/list.c +++ b/src/list.c @@ -1264,7 +1264,7 @@ eval_list(char_u **arg, typval_T *rettv, had_comma = **arg == ','; if (had_comma) { - if (vim9script && !IS_WHITE_OR_NUL((*arg)[1])) + if (vim9script && !IS_WHITE_OR_NUL((*arg)[1]) && (*arg)[1] != ']') { semsg(_(e_white_space_required_after_str), ","); goto failret;
--- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -1332,7 +1332,10 @@ do_source( // set again. ht = &SCRIPT_VARS(sid); if (is_vim9) + { hashtab_free_contents(ht); + hash_init(ht); + } else { int todo = (int)ht->ht_used;
--- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -13,52 +13,55 @@ enddef " test cond ? expr : expr def Test_expr1_trinary() - assert_equal('one', true ? 'one' : 'two') - assert_equal('one', 1 ? - 'one' : - 'two') - if has('float') - assert_equal('one', !!0.1 ? 'one' : 'two') - endif - assert_equal('one', !!'x' ? 'one' : 'two') - assert_equal('one', !!'x' - ? 'one' - : 'two') - assert_equal('one', !!0z1234 ? 'one' : 'two') - assert_equal('one', !![0] ? 'one' : 'two') - assert_equal('one', !!#{x: 0} ? 'one' : 'two') - var name = 1 - assert_equal('one', name ? 'one' : 'two') + var lines =<< trim END + assert_equal('one', true ? 'one' : 'two') + assert_equal('one', 1 ? + 'one' : + 'two') + if has('float') + assert_equal('one', !!0.1 ? 'one' : 'two') + endif + assert_equal('one', !!'x' ? 'one' : 'two') + assert_equal('one', !!'x' + ? 'one' + : 'two') + assert_equal('one', !!0z1234 ? 'one' : 'two') + assert_equal('one', !![0] ? 'one' : 'two') + assert_equal('one', !!#{x: 0} ? 'one' : 'two') + var name = 1 + assert_equal('one', name ? 'one' : 'two') - assert_equal('two', false ? 'one' : 'two') - assert_equal('two', 0 ? 'one' : 'two') - if has('float') - assert_equal('two', !!0.0 ? 'one' : 'two') - endif - assert_equal('two', !!'' ? 'one' : 'two') - assert_equal('two', !!0z ? 'one' : 'two') - assert_equal('two', !![] ? 'one' : 'two') - assert_equal('two', !!{} ? 'one' : 'two') - name = 0 - assert_equal('two', name ? 'one' : 'two') + assert_equal('two', false ? 'one' : 'two') + assert_equal('two', 0 ? 'one' : 'two') + if has('float') + assert_equal('two', !!0.0 ? 'one' : 'two') + endif + assert_equal('two', !!'' ? 'one' : 'two') + assert_equal('two', !!0z ? 'one' : 'two') + assert_equal('two', !![] ? 'one' : 'two') + assert_equal('two', !!{} ? 'one' : 'two') + name = 0 + assert_equal('two', name ? 'one' : 'two') - # with constant condition expression is not evaluated - assert_equal('one', 1 ? 'one' : xxx) + # with constant condition expression is not evaluated + assert_equal('one', 1 ? 'one' : xxx) - var Some: func = function('len') - var Other: func = function('winnr') - var Res: func = g:atrue ? Some : Other - assert_equal(function('len'), Res) + var Some: func = function('len') + var Other: func = function('winnr') + var Res: func = g:atrue ? Some : Other + assert_equal(function('len'), Res) - var RetOne: func(string): number = function('len') - var RetTwo: func(string): number = function('winnr') - var RetThat: func = g:atrue ? RetOne : RetTwo - assert_equal(function('len'), RetThat) + var RetOne: func(string): number = function('len') + var RetTwo: func(string): number = function('winnr') + var RetThat: func = g:atrue ? RetOne : RetTwo + assert_equal(function('len'), RetThat) - var X = FuncOne - var Y = FuncTwo - var Z = g:cond ? FuncOne : FuncTwo - assert_equal(123, Z(3)) + var X = FuncOne + var Y = FuncTwo + var Z = g:cond ? FuncOne : FuncTwo + assert_equal(123, Z(3)) + END + CheckDefAndScriptSuccess(lines) enddef def Test_expr1_trinary_vimscript() @@ -225,7 +228,6 @@ def Test_expr1_falsy() call CheckDefFailure(["var x = 1??'one' : 'two'"], msg, 1) enddef -" TODO: define inside test function def Record(val: any): any g:vals->add(val) return val @@ -233,32 +235,52 @@ enddef " test || def Test_expr2() - assert_equal(true, 1 || 0) - assert_equal(true, 0 || - 0 || - 1) - assert_equal(false, 0 || 0) - assert_equal(false, 0 - || 0) - assert_equal(false, 0 || false) + var lines =<< trim END + assert_equal(true, 1 || 0) + assert_equal(true, 0 || + 0 || + 1) + assert_equal(true, 0 || + 0 || + !!7) + assert_equal(false, 0 || 0) + assert_equal(false, 0 + || 0) + assert_equal(false, 0 || false) - g:vals = [] - assert_equal(true, Record(1) || Record(3)) - assert_equal([1], g:vals) + g:vals = [] + assert_equal(true, Record(1) || Record(3)) + assert_equal([1], g:vals) + + g:vals = [] + assert_equal(true, Record(0) || Record(1)) + assert_equal([0, 1], g:vals) - g:vals = [] - assert_equal(true, Record(0) || Record(1)) - assert_equal([0, 1], g:vals) + g:vals = [] + assert_equal(true, Record(0) || Record(true)) + assert_equal([0, true], g:vals) + + g:vals = [] + assert_equal(true, Record(0) + || Record(1) + || Record(0)) + assert_equal([0, 1], g:vals) - g:vals = [] - assert_equal(true, Record(0) - || Record(1) - || Record(0)) - assert_equal([0, 1], g:vals) + g:vals = [] + assert_equal(true, Record(0) + || Record(true) + || Record(0)) + assert_equal([0, true], g:vals) - g:vals = [] - assert_equal(false, Record(0) || Record(false) || Record(0)) - assert_equal([0, false, 0], g:vals) + g:vals = [] + assert_equal(true, Record(true) || Record(false)) + assert_equal([true], g:vals) + + g:vals = [] + assert_equal(false, Record(0) || Record(false) || Record(0)) + assert_equal([0, false, 0], g:vals) + END + CheckDefAndScriptSuccess(lines) enddef def Test_expr2_vimscript() @@ -316,37 +338,6 @@ def Test_expr2_vimscript() var name = v:true|| v:true END CheckScriptFailure(lines, 'E1004:', 2) - - # check evaluating to bool - lines =<< trim END - assert_equal(true, 1 || 0) - assert_equal(true, 0 || - 0 || - !!7) - assert_equal(false, 0 || 0) - assert_equal(false, 0 - || 0) - assert_equal(false, 0 || false) - - g:vals = [] - assert_equal(true, Record(true) || Record(false)) - assert_equal([true], g:vals) - - g:vals = [] - assert_equal(true, Record(0) || Record(true)) - assert_equal([0, true], g:vals) - - g:vals = [] - assert_equal(true, Record(0) - || Record(true) - || Record(0)) - assert_equal([0, true], g:vals) - - g:vals = [] - assert_equal(false, Record(0) || Record(false) || Record(0)) - assert_equal([0, false, 0], g:vals) - END - CheckDefAndScriptSuccess(lines) enddef def Test_expr2_fails() @@ -367,36 +358,43 @@ enddef " test && def Test_expr3() - assert_equal(false, 1 && 0) - assert_equal(false, 0 && - 0 && - 1) - assert_equal(true, 1 - && true - && 1) - assert_equal(false, 0 && 0) - assert_equal(false, 0 && false) - assert_equal(true, 1 && true) + var lines =<< trim END + assert_equal(false, 1 && 0) + assert_equal(false, 0 && + 0 && + 1) + assert_equal(true, 1 + && true + && 1) + assert_equal(false, 0 && 0) + assert_equal(false, 0 && false) + assert_equal(true, 1 && true) - g:vals = [] - assert_equal(true, Record(true) && Record(1)) - assert_equal([true, 1], g:vals) + g:vals = [] + assert_equal(true, Record(true) && Record(1)) + assert_equal([true, 1], g:vals) - g:vals = [] - assert_equal(false, Record(0) && Record(1)) - assert_equal([0], g:vals) + g:vals = [] + assert_equal(true, Record(1) && Record(true)) + assert_equal([1, true], g:vals) - g:vals = [] - assert_equal(false, Record(0) && Record(4) && Record(0)) - assert_equal([0], g:vals) + g:vals = [] + assert_equal(false, Record(0) && Record(1)) + assert_equal([0], g:vals) - g:vals = [] - assert_equal(false, Record(1) && Record(true) && Record(0)) - assert_equal([1, true, 0], g:vals) + g:vals = [] + assert_equal(false, Record(0) && Record(1) && Record(0)) + assert_equal([0], g:vals) - g:vals = [] - assert_equal(false, Record(1) && Record(true) && Record(0)) - assert_equal([1, true, 0], g:vals) + g:vals = [] + assert_equal(false, Record(0) && Record(4) && Record(0)) + assert_equal([0], g:vals) + + g:vals = [] + assert_equal(false, Record(1) && Record(true) && Record(0)) + assert_equal([1, true, 0], g:vals) + END + CheckDefAndScriptSuccess(lines) enddef def Test_expr3_vimscript() @@ -454,38 +452,6 @@ def Test_expr3_vimscript() var name = v:true&& v:true END CheckScriptFailure(lines, 'E1004:', 2) - - # check keeping the value - lines =<< trim END - vim9script - assert_equal(false, 1 && 0) - assert_equal(false, 0 && - 0 && - 1) - assert_equal(true, 1 - && true - && 1) - assert_equal(false, 0 && 0) - assert_equal(false, 0 && false) - assert_equal(false, 1 && 0) - - g:vals = [] - assert_equal(true, Record(1) && Record(true)) - assert_equal([1, true], g:vals) - - g:vals = [] - assert_equal(false, Record(0) && Record(1)) - assert_equal([0], g:vals) - - g:vals = [] - assert_equal(false, Record(0) && Record(1) && Record(0)) - assert_equal([0], g:vals) - - g:vals = [] - assert_equal(false, Record(1) && Record(true) && Record(0)) - assert_equal([1, true, 0], g:vals) - END - CheckScriptSuccess(lines) enddef func Test_expr3_fails() @@ -495,6 +461,8 @@ func Test_expr3_fails() call CheckDefFailure(["var x = 1&& 2"], msg, 1) call CheckDefFailure(["if 'yes' && 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 1) + + call CheckDefExecFailure(['assert_equal(false, Record(1) && Record(4) && Record(0))'], 'E1023: Using a Number as a Bool: 4', 1) endfunc " global variables to use for tests with the "any" type @@ -515,307 +483,345 @@ let adict = #{aaa: 2, bbb: 8} " test == comperator def Test_expr4_equal() - var trueVar = true - var falseVar = false - assert_equal(true, true == true) - assert_equal(false, true == - false) - assert_equal(true, true - == trueVar) - assert_equal(false, true == falseVar) - assert_equal(true, true == g:atrue) - assert_equal(false, g:atrue == false) + var lines =<< trim END + var trueVar = true + var falseVar = false + assert_equal(true, true == true) + assert_equal(false, true == + false) + assert_equal(true, true + == trueVar) + assert_equal(false, true == falseVar) + assert_equal(true, true == g:atrue) + assert_equal(false, g:atrue == false) + + assert_equal(true, v:none == v:none) + assert_equal(false, v:none == v:null) + assert_equal(true, g:anone == v:none) + assert_equal(false, v:none == g:anull) - assert_equal(true, v:none == v:none) - assert_equal(false, v:none == v:null) - assert_equal(true, g:anone == v:none) - assert_equal(false, v:none == g:anull) + var nr0 = 0 + var nr61 = 61 + assert_equal(false, 2 == 0) + assert_equal(false, 2 == nr0) + assert_equal(true, 61 == 61) + assert_equal(true, 61 == nr61) + assert_equal(true, g:anint == 10) + assert_equal(false, 61 == g:anint) - var nr0 = 0 - var nr61 = 61 - assert_equal(false, 2 == 0) - assert_equal(false, 2 == nr0) - assert_equal(true, 61 == 61) - assert_equal(true, 61 == nr61) - assert_equal(true, g:anint == 10) - assert_equal(false, 61 == g:anint) + if has('float') + var ff = 0.3 + assert_equal(true, ff == 0.3) + assert_equal(false, 0.4 == ff) + assert_equal(true, 0.1 == g:afloat) + assert_equal(false, g:afloat == 0.3) + + ff = 3.0 + assert_equal(true, ff == 3) + assert_equal(true, 3 == ff) + ff = 3.1 + assert_equal(false, ff == 3) + assert_equal(false, 3 == ff) + endif + + assert_equal(true, 'abc' == 'abc') + assert_equal(false, 'xyz' == 'abc') + assert_equal(true, g:astring == 'asdf') + assert_equal(false, 'xyz' == g:astring) - if has('float') - var ff = 0.3 - assert_equal(true, ff == 0.3) - assert_equal(false, 0.4 == ff) - assert_equal(true, 0.1 == g:afloat) - assert_equal(false, g:afloat == 0.3) + assert_equal(false, 'abc' == 'aBc') + assert_equal(false, 'abc' ==# 'aBc') + assert_equal(true, 'abc' ==? 'aBc') - ff = 3.0 - assert_equal(true, ff == 3) - assert_equal(true, 3 == ff) - ff = 3.1 - assert_equal(false, ff == 3) - assert_equal(false, 3 == ff) - endif + assert_equal(false, 'abc' == 'ABC') + set ignorecase + assert_equal(false, 'abc' == 'ABC') + assert_equal(false, 'abc' ==# 'ABC') + assert_equal(true, 'abc' ==? 'ABC') + set noignorecase + + var bb = 0z3f + assert_equal(true, 0z3f == bb) + assert_equal(false, bb == 0z4f) + assert_equal(true, g:ablob == 0z01ab) + assert_equal(false, 0z3f == g:ablob) - assert_equal(true, 'abc' == 'abc') - assert_equal(false, 'xyz' == 'abc') - assert_equal(true, g:astring == 'asdf') - assert_equal(false, 'xyz' == g:astring) + assert_equal(true, [1, 2, 3] == [1, 2, 3]) + assert_equal(false, [1, 2, 3] == [2, 3, 1]) + assert_equal(true, [2, 3, 4] == g:alist) + assert_equal(false, g:alist == [2, 3, 1]) + assert_equal(false, [1, 2, 3] == []) + assert_equal(false, [1, 2, 3] == ['1', '2', '3']) + + assert_equal(true, #{one: 1, two: 2} == #{one: 1, two: 2}) + assert_equal(false, #{one: 1, two: 2} == #{one: 2, two: 2}) + assert_equal(false, #{one: 1, two: 2} == #{two: 2}) + assert_equal(false, #{one: 1, two: 2} == #{}) + assert_equal(true, g:adict == #{bbb: 8, aaa: 2}) + assert_equal(false, #{ccc: 9, aaa: 2} == g:adict) - assert_equal(false, 'abc' == 'aBc') - assert_equal(false, 'abc' ==# 'aBc') - assert_equal(true, 'abc' ==? 'aBc') + assert_equal(true, function('g:Test_expr4_equal') == function('g:Test_expr4_equal')) + assert_equal(false, function('g:Test_expr4_equal') == function('g:Test_expr4_is')) + + assert_equal(true, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_equal', [123])) + assert_equal(false, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_is', [123])) + assert_equal(false, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_equal', [999])) - assert_equal(false, 'abc' == 'ABC') - set ignorecase - assert_equal(false, 'abc' == 'ABC') - assert_equal(false, 'abc' ==# 'ABC') - set noignorecase + var OneFunc: func + var TwoFunc: func + OneFunc = function('len') + TwoFunc = function('len') + assert_equal(true, OneFunc('abc') == TwoFunc('123')) + END + CheckDefAndScriptSuccess(lines) CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1) CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 4) - - var bb = 0z3f - assert_equal(true, 0z3f == bb) - assert_equal(false, bb == 0z4f) - assert_equal(true, g:ablob == 0z01ab) - assert_equal(false, 0z3f == g:ablob) - - assert_equal(true, [1, 2, 3] == [1, 2, 3]) - assert_equal(false, [1, 2, 3] == [2, 3, 1]) - assert_equal(true, [2, 3, 4] == g:alist) - assert_equal(false, g:alist == [2, 3, 1]) - assert_equal(false, [1, 2, 3] == []) - assert_equal(false, [1, 2, 3] == ['1', '2', '3']) - - assert_equal(true, #{one: 1, two: 2} == #{one: 1, two: 2}) - assert_equal(false, #{one: 1, two: 2} == #{one: 2, two: 2}) - assert_equal(false, #{one: 1, two: 2} == #{two: 2}) - assert_equal(false, #{one: 1, two: 2} == #{}) - assert_equal(true, g:adict == #{bbb: 8, aaa: 2}) - assert_equal(false, #{ccc: 9, aaa: 2} == g:adict) - - assert_equal(true, function('g:Test_expr4_equal') == function('g:Test_expr4_equal')) - assert_equal(false, function('g:Test_expr4_equal') == function('g:Test_expr4_is')) - - assert_equal(true, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_equal', [123])) - assert_equal(false, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_is', [123])) - assert_equal(false, function('g:Test_expr4_equal', [123]) == function('g:Test_expr4_equal', [999])) - - var OneFunc: func - var TwoFunc: func - OneFunc = function('len') - TwoFunc = function('len') - assert_equal(true, OneFunc('abc') == TwoFunc('123')) enddef " test != comperator def Test_expr4_notequal() - var trueVar = true - var falseVar = false - assert_equal(false, true != true) - assert_equal(true, true != - false) - assert_equal(false, true - != trueVar) - assert_equal(true, true != falseVar) - assert_equal(false, true != g:atrue) - assert_equal(true, g:atrue != false) + var lines =<< trim END + var trueVar = true + var falseVar = false + assert_equal(false, true != true) + assert_equal(true, true != + false) + assert_equal(false, true + != trueVar) + assert_equal(true, true != falseVar) + assert_equal(false, true != g:atrue) + assert_equal(true, g:atrue != false) - assert_equal(false, v:none != v:none) - assert_equal(true, v:none != v:null) - assert_equal(false, g:anone != v:none) - assert_equal(true, v:none != g:anull) + assert_equal(false, v:none != v:none) + assert_equal(true, v:none != v:null) + assert_equal(false, g:anone != v:none) + assert_equal(true, v:none != g:anull) - var nr55 = 55 - var nr0 = 55 - assert_equal(true, 2 != 0) - assert_equal(true, 2 != nr0) - assert_equal(false, 55 != 55) - assert_equal(false, 55 != nr55) - assert_equal(false, g:anint != 10) - assert_equal(true, 61 != g:anint) + var nr55 = 55 + var nr0 = 55 + assert_equal(true, 2 != 0) + assert_equal(true, 2 != nr0) + assert_equal(false, 55 != 55) + assert_equal(false, 55 != nr55) + assert_equal(false, g:anint != 10) + assert_equal(true, 61 != g:anint) - if has('float') - var ff = 0.3 - assert_equal(false, 0.3 != ff) - assert_equal(true, 0.4 != ff) - assert_equal(false, 0.1 != g:afloat) - assert_equal(true, g:afloat != 0.3) + if has('float') + var ff = 0.3 + assert_equal(false, 0.3 != ff) + assert_equal(true, 0.4 != ff) + assert_equal(false, 0.1 != g:afloat) + assert_equal(true, g:afloat != 0.3) + + ff = 3.0 + assert_equal(false, ff != 3) + assert_equal(false, 3 != ff) + ff = 3.1 + assert_equal(true, ff != 3) + assert_equal(true, 3 != ff) + endif - ff = 3.0 - assert_equal(false, ff != 3) - assert_equal(false, 3 != ff) - ff = 3.1 - assert_equal(true, ff != 3) - assert_equal(true, 3 != ff) - endif + assert_equal(false, 'abc' != 'abc') + assert_equal(true, 'xyz' != 'abc') + assert_equal(false, g:astring != 'asdf') + assert_equal(true, 'xyz' != g:astring) - assert_equal(false, 'abc' != 'abc') - assert_equal(true, 'xyz' != 'abc') - assert_equal(false, g:astring != 'asdf') - assert_equal(true, 'xyz' != g:astring) + assert_equal(true, 'abc' != 'ABC') + set ignorecase + assert_equal(true, 'abc' != 'ABC') + assert_equal(true, 'abc' !=# 'ABC') + assert_equal(false, 'abc' !=? 'ABC') + set noignorecase - assert_equal(true, 'abc' != 'ABC') - set ignorecase - assert_equal(true, 'abc' != 'ABC') - set noignorecase + var bb = 0z3f + assert_equal(false, 0z3f != bb) + assert_equal(true, bb != 0z4f) + assert_equal(false, g:ablob != 0z01ab) + assert_equal(true, 0z3f != g:ablob) - var bb = 0z3f - assert_equal(false, 0z3f != bb) - assert_equal(true, bb != 0z4f) - assert_equal(false, g:ablob != 0z01ab) - assert_equal(true, 0z3f != g:ablob) - - assert_equal(false, [1, 2, 3] != [1, 2, 3]) - assert_equal(true, [1, 2, 3] != [2, 3, 1]) - assert_equal(false, [2, 3, 4] != g:alist) - assert_equal(true, g:alist != [2, 3, 1]) - assert_equal(true, [1, 2, 3] != []) - assert_equal(true, [1, 2, 3] != ['1', '2', '3']) + assert_equal(false, [1, 2, 3] != [1, 2, 3]) + assert_equal(true, [1, 2, 3] != [2, 3, 1]) + assert_equal(false, [2, 3, 4] != g:alist) + assert_equal(true, g:alist != [2, 3, 1]) + assert_equal(true, [1, 2, 3] != []) + assert_equal(true, [1, 2, 3] != ['1', '2', '3']) - assert_equal(false, #{one: 1, two: 2} != #{one: 1, two: 2}) - assert_equal(true, #{one: 1, two: 2} != #{one: 2, two: 2}) - assert_equal(true, #{one: 1, two: 2} != #{two: 2}) - assert_equal(true, #{one: 1, two: 2} != #{}) - assert_equal(false, g:adict != #{bbb: 8, aaa: 2}) - assert_equal(true, #{ccc: 9, aaa: 2} != g:adict) + assert_equal(false, #{one: 1, two: 2} != #{one: 1, two: 2}) + assert_equal(true, #{one: 1, two: 2} != #{one: 2, two: 2}) + assert_equal(true, #{one: 1, two: 2} != #{two: 2}) + assert_equal(true, #{one: 1, two: 2} != #{}) + assert_equal(false, g:adict != #{bbb: 8, aaa: 2}) + assert_equal(true, #{ccc: 9, aaa: 2} != g:adict) - assert_equal(false, function('g:Test_expr4_equal') != function('g:Test_expr4_equal')) - assert_equal(true, function('g:Test_expr4_equal') != function('g:Test_expr4_is')) + assert_equal(false, function('g:Test_expr4_equal') != function('g:Test_expr4_equal')) + assert_equal(true, function('g:Test_expr4_equal') != function('g:Test_expr4_is')) - assert_equal(false, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_equal', [123])) - assert_equal(true, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_is', [123])) - assert_equal(true, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_equal', [999])) + assert_equal(false, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_equal', [123])) + assert_equal(true, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_is', [123])) + assert_equal(true, function('g:Test_expr4_equal', [123]) != function('g:Test_expr4_equal', [999])) + END + CheckDefAndScriptSuccess(lines) enddef " test > comperator def Test_expr4_greater() - assert_true(2 > 0) - assert_true(2 > - 1) - assert_false(2 > 2) - assert_false(2 > 3) - var nr2 = 2 - assert_true(nr2 > 0) - assert_true(nr2 > - 1) - assert_false(nr2 > 2) - assert_false(nr2 - > 3) - if has('float') - var ff = 2.0 - assert_true(ff > 0.0) - assert_true(ff > 1.0) - assert_false(ff > 2.0) - assert_false(ff > 3.0) - endif + var lines =<< trim END + assert_true(2 > 0) + assert_true(2 > + 1) + assert_false(2 > 2) + assert_false(2 > 3) + var nr2 = 2 + assert_true(nr2 > 0) + assert_true(nr2 > + 1) + assert_false(nr2 > 2) + assert_false(nr2 + > 3) + if has('float') + var ff = 2.0 + assert_true(ff > 0.0) + assert_true(ff > 1.0) + assert_false(ff > 2.0) + assert_false(ff > 3.0) + endif + END + CheckDefAndScriptSuccess(lines) enddef " test >= comperator def Test_expr4_greaterequal() - assert_true(2 >= 0) - assert_true(2 >= - 2) - assert_false(2 >= 3) - var nr2 = 2 - assert_true(nr2 >= 0) - assert_true(nr2 >= 2) - assert_false(nr2 >= 3) - if has('float') - var ff = 2.0 - assert_true(ff >= 0.0) - assert_true(ff >= 2.0) - assert_false(ff >= 3.0) - endif + var lines =<< trim END + assert_true(2 >= 0) + assert_true(2 >= + 2) + assert_false(2 >= 3) + var nr2 = 2 + assert_true(nr2 >= 0) + assert_true(nr2 >= 2) + assert_false(nr2 >= 3) + if has('float') + var ff = 2.0 + assert_true(ff >= 0.0) + assert_true(ff >= 2.0) + assert_false(ff >= 3.0) + endif + END + CheckDefAndScriptSuccess(lines) enddef " test < comperator def Test_expr4_smaller() - assert_false(2 < 0) - assert_false(2 < - 2) - assert_true(2 - < 3) - var nr2 = 2 - assert_false(nr2 < 0) - assert_false(nr2 < 2) - assert_true(nr2 < 3) - if has('float') - var ff = 2.0 - assert_false(ff < 0.0) - assert_false(ff < 2.0) - assert_true(ff < 3.0) - endif + var lines =<< trim END + assert_false(2 < 0) + assert_false(2 < + 2) + assert_true(2 + < 3) + var nr2 = 2 + assert_false(nr2 < 0) + assert_false(nr2 < 2) + assert_true(nr2 < 3) + if has('float') + var ff = 2.0 + assert_false(ff < 0.0) + assert_false(ff < 2.0) + assert_true(ff < 3.0) + endif + END + CheckDefAndScriptSuccess(lines) enddef " test <= comperator def Test_expr4_smallerequal() - assert_false(2 <= 0) - assert_false(2 <= - 1) - assert_true(2 - <= 2) - assert_true(2 <= 3) - var nr2 = 2 - assert_false(nr2 <= 0) - assert_false(nr2 <= 1) - assert_true(nr2 <= 2) - assert_true(nr2 <= 3) - if has('float') - var ff = 2.0 - assert_false(ff <= 0.0) - assert_false(ff <= 1.0) - assert_true(ff <= 2.0) - assert_true(ff <= 3.0) - endif + var lines =<< trim END + assert_false(2 <= 0) + assert_false(2 <= + 1) + assert_true(2 + <= 2) + assert_true(2 <= 3) + var nr2 = 2 + assert_false(nr2 <= 0) + assert_false(nr2 <= 1) + assert_true(nr2 <= 2) + assert_true(nr2 <= 3) + if has('float') + var ff = 2.0 + assert_false(ff <= 0.0) + assert_false(ff <= 1.0) + assert_true(ff <= 2.0) + assert_true(ff <= 3.0) + endif + END + CheckDefAndScriptSuccess(lines) enddef " test =~ comperator def Test_expr4_match() - assert_equal(false, '2' =~ '0') - assert_equal(false, '' - =~ '0') - assert_equal(true, '2' =~ - '[0-9]') + var lines =<< trim END + assert_equal(false, '2' =~ '0') + assert_equal(false, '' + =~ '0') + assert_equal(true, '2' =~ + '[0-9]') + set ignorecase + assert_equal(false, 'abc' =~ 'ABC') + assert_equal(false, 'abc' =~# 'ABC') + assert_equal(true, 'abc' =~? 'ABC') + set noignorecase + END + CheckDefAndScriptSuccess(lines) enddef " test !~ comperator def Test_expr4_nomatch() - assert_equal(true, '2' !~ '0') - assert_equal(true, '' - !~ '0') - assert_equal(false, '2' !~ - '[0-9]') + var lines =<< trim END + assert_equal(true, '2' !~ '0') + assert_equal(true, '' + !~ '0') + assert_equal(false, '2' !~ + '[0-9]') + END + CheckDefAndScriptSuccess(lines) enddef " test is comperator def Test_expr4_is() - var mylist = [2] - assert_false(mylist is [2]) - var other = mylist - assert_true(mylist is - other) + var lines =<< trim END + var mylist = [2] + assert_false(mylist is [2]) + var other = mylist + assert_true(mylist is + other) - var myblob = 0z1234 - assert_false(myblob - is 0z1234) - var otherblob = myblob - assert_true(myblob is otherblob) + var myblob = 0z1234 + assert_false(myblob + is 0z1234) + var otherblob = myblob + assert_true(myblob is otherblob) + END + CheckDefAndScriptSuccess(lines) enddef " test isnot comperator def Test_expr4_isnot() - var mylist = [2] - assert_true('2' isnot '0') - assert_true(mylist isnot [2]) - var other = mylist - assert_false(mylist isnot - other) + var lines =<< trim END + var mylist = [2] + assert_true('2' isnot '0') + assert_true(mylist isnot [2]) + var other = mylist + assert_false(mylist isnot + other) - var myblob = 0z1234 - assert_true(myblob - isnot 0z1234) - var otherblob = myblob - assert_false(myblob isnot otherblob) + var myblob = 0z1234 + assert_true(myblob + isnot 0z1234) + var otherblob = myblob + assert_false(myblob isnot otherblob) + END + CheckDefAndScriptSuccess(lines) enddef def RetVoid() @@ -896,25 +902,6 @@ def Test_expr4_vim9script() END CheckScriptFailure(lines, 'Cannot use "is" with number', 2) - # check 'ignorecase' not being used - lines =<< trim END - vim9script - set ignorecase - assert_equal(false, 'abc' == 'ABC') - assert_equal(false, 'abc' ==# 'ABC') - assert_equal(true, 'abc' ==? 'ABC') - - assert_equal(true, 'abc' != 'ABC') - assert_equal(true, 'abc' !=# 'ABC') - assert_equal(false, 'abc' !=? 'ABC') - - assert_equal(false, 'abc' =~ 'ABC') - assert_equal(false, 'abc' =~# 'ABC') - assert_equal(true, 'abc' =~? 'ABC') - set noignorecase - END - CheckScriptSuccess(lines) - # check missing white space lines =<< trim END vim9script @@ -1032,55 +1019,58 @@ endfunc " test addition, subtraction, concatenation def Test_expr5() - assert_equal(66, 60 + 6) - assert_equal(70, 60 + - g:anint) - assert_equal(9, g:thefour - + 5) - assert_equal(14, g:thefour + g:anint) - assert_equal([1, 2, 3, 4], [1] + g:alist) + var lines =<< trim END + assert_equal(66, 60 + 6) + assert_equal(70, 60 + + g:anint) + assert_equal(9, g:thefour + + 5) + assert_equal(14, g:thefour + g:anint) + assert_equal([1, 2, 3, 4], [1] + g:alist) - assert_equal(54, 60 - 6) - assert_equal(50, 60 - - g:anint) - assert_equal(-1, g:thefour - - 5) - assert_equal(-6, g:thefour - g:anint) + assert_equal(54, 60 - 6) + assert_equal(50, 60 - + g:anint) + assert_equal(-1, g:thefour + - 5) + assert_equal(-6, g:thefour - g:anint) - assert_equal('hello', 'hel' .. 'lo') - assert_equal('hello 123', 'hello ' .. - 123) - assert_equal('hello 123', 'hello ' - .. 123) - assert_equal('123 hello', 123 .. ' hello') - assert_equal('123456', 123 .. 456) + assert_equal('hello', 'hel' .. 'lo') + assert_equal('hello 123', 'hello ' .. + 123) + assert_equal('hello 123', 'hello ' + .. 123) + assert_equal('123 hello', 123 .. ' hello') + assert_equal('123456', 123 .. 456) - assert_equal('av:true', 'a' .. true) - assert_equal('av:false', 'a' .. false) - assert_equal('av:null', 'a' .. v:null) - assert_equal('av:none', 'a' .. v:none) - if has('float') - assert_equal('a0.123', 'a' .. 0.123) - endif + assert_equal('av:true', 'a' .. true) + assert_equal('av:false', 'a' .. false) + assert_equal('av:null', 'a' .. v:null) + assert_equal('av:none', 'a' .. v:none) + if has('float') + assert_equal('a0.123', 'a' .. 0.123) + endif - assert_equal([1, 2, 3, 4], [1, 2] + [3, 4]) - assert_equal(0z11223344, 0z1122 + 0z3344) - assert_equal(0z112201ab, 0z1122 - + g:ablob) - assert_equal(0z01ab3344, g:ablob + 0z3344) - assert_equal(0z01ab01ab, g:ablob + g:ablob) + assert_equal([1, 2, 3, 4], [1, 2] + [3, 4]) + assert_equal(0z11223344, 0z1122 + 0z3344) + assert_equal(0z112201ab, 0z1122 + + g:ablob) + assert_equal(0z01ab3344, g:ablob + 0z3344) + assert_equal(0z01ab01ab, g:ablob + g:ablob) - # concatenate non-constant to constant - var save_path = &path - &path = 'b' - assert_equal('ab', 'a' .. &path) - &path = save_path + # concatenate non-constant to constant + var save_path = &path + &path = 'b' + assert_equal('ab', 'a' .. &path) + &path = save_path - @b = 'b' - assert_equal('ab', 'a' .. @b) + @b = 'b' + assert_equal('ab', 'a' .. @b) - $ENVVAR = 'env' - assert_equal('aenv', 'a' .. $ENVVAR) + $ENVVAR = 'env' + assert_equal('aenv', 'a' .. $ENVVAR) + END + CheckDefAndScriptSuccess(lines) enddef def Test_expr5_vim9script() @@ -1196,19 +1186,6 @@ def Test_expr5_vim9script() END CheckScriptFailure(lines, 'E1004:', 2) - # check valid string concatenation - lines =<< trim END - vim9script - assert_equal('one123', 'one' .. 123) - assert_equal('onev:true', 'one' .. true) - assert_equal('onev:null', 'one' .. v:null) - assert_equal('onev:none', 'one' .. v:none) - if has('float') - assert_equal('a0.123', 'a' .. 0.123) - endif - END - CheckScriptSuccess(lines) - # check invalid string concatenation lines =<< trim END vim9script @@ -1258,24 +1235,27 @@ def Test_expr5_float() if !has('float') MissingFeature 'float' else - assert_equal(66.0, 60.0 + 6.0) - assert_equal(66.0, 60.0 + 6) - assert_equal(66.0, 60 + - 6.0) - assert_equal(5.1, g:afloat - + 5) - assert_equal(8.1, 8 + g:afloat) - assert_equal(10.1, g:anint + g:afloat) - assert_equal(10.1, g:afloat + g:anint) + var lines =<< trim END + assert_equal(66.0, 60.0 + 6.0) + assert_equal(66.0, 60.0 + 6) + assert_equal(66.0, 60 + + 6.0) + assert_equal(5.1, g:afloat + + 5) + assert_equal(8.1, 8 + g:afloat) + assert_equal(10.1, g:anint + g:afloat) + assert_equal(10.1, g:afloat + g:anint) - assert_equal(54.0, 60.0 - 6.0) - assert_equal(54.0, 60.0 - - 6) - assert_equal(54.0, 60 - 6.0) - assert_equal(-4.9, g:afloat - 5) - assert_equal(7.9, 8 - g:afloat) - assert_equal(9.9, g:anint - g:afloat) - assert_equal(-9.9, g:afloat - g:anint) + assert_equal(54.0, 60.0 - 6.0) + assert_equal(54.0, 60.0 + - 6) + assert_equal(54.0, 60 - 6.0) + assert_equal(-4.9, g:afloat - 5) + assert_equal(7.9, 8 - g:afloat) + assert_equal(9.9, g:anint - g:afloat) + assert_equal(-9.9, g:afloat - g:anint) + END + CheckDefAndScriptSuccess(lines) endif enddef @@ -1319,41 +1299,44 @@ endfunc " test multiply, divide, modulo def Test_expr6() - assert_equal(36, 6 * 6) - assert_equal(24, 6 * - g:thefour) - assert_equal(24, g:thefour - * 6) - assert_equal(40, g:anint * g:thefour) + var lines =<< trim END + assert_equal(36, 6 * 6) + assert_equal(24, 6 * + g:thefour) + assert_equal(24, g:thefour + * 6) + assert_equal(40, g:anint * g:thefour) - assert_equal(10, 60 / 6) - assert_equal(6, 60 / - g:anint) - assert_equal(1, g:anint / 6) - assert_equal(2, g:anint - / g:thefour) + assert_equal(10, 60 / 6) + assert_equal(6, 60 / + g:anint) + assert_equal(1, g:anint / 6) + assert_equal(2, g:anint + / g:thefour) - assert_equal(5, 11 % 6) - assert_equal(4, g:anint % 6) - assert_equal(3, 13 % - g:anint) - assert_equal(2, g:anint - % g:thefour) + assert_equal(5, 11 % 6) + assert_equal(4, g:anint % 6) + assert_equal(3, 13 % + g:anint) + assert_equal(2, g:anint + % g:thefour) - assert_equal(4, 6 * 4 / 6) + assert_equal(4, 6 * 4 / 6) - var x = [2] - var y = [3] - assert_equal(5, x[0] + y[0]) - assert_equal(6, x[0] * y[0]) - if has('float') - var xf = [2.0] - var yf = [3.0] - assert_equal(5.0, xf[0] - + yf[0]) - assert_equal(6.0, xf[0] - * yf[0]) - endif + var x = [2] + var y = [3] + assert_equal(5, x[0] + y[0]) + assert_equal(6, x[0] * y[0]) + if has('float') + var xf = [2.0] + var yf = [3.0] + assert_equal(5.0, xf[0] + + yf[0]) + assert_equal(6.0, xf[0] + * yf[0]) + endif + END + CheckDefAndScriptSuccess(lines) CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1) enddef @@ -1419,29 +1402,32 @@ def Test_expr6_float() if !has('float') MissingFeature 'float' else - assert_equal(36.0, 6.0 * 6) - assert_equal(36.0, 6 * - 6.0) - assert_equal(36.0, 6.0 * 6.0) - assert_equal(1.0, g:afloat * g:anint) + var lines =<< trim END + assert_equal(36.0, 6.0 * 6) + assert_equal(36.0, 6 * + 6.0) + assert_equal(36.0, 6.0 * 6.0) + assert_equal(1.0, g:afloat * g:anint) - assert_equal(10.0, 60 / 6.0) - assert_equal(10.0, 60.0 / - 6) - assert_equal(10.0, 60.0 / 6.0) - assert_equal(0.01, g:afloat / g:anint) + assert_equal(10.0, 60 / 6.0) + assert_equal(10.0, 60.0 / + 6) + assert_equal(10.0, 60.0 / 6.0) + assert_equal(0.01, g:afloat / g:anint) - assert_equal(4.0, 6.0 * 4 / 6) - assert_equal(4.0, 6 * - 4.0 / - 6) - assert_equal(4.0, 6 * 4 / 6.0) - assert_equal(4.0, 6.0 * 4.0 / 6) - assert_equal(4.0, 6 * 4.0 / 6.0) - assert_equal(4.0, 6.0 * 4 / 6.0) - assert_equal(4.0, 6.0 * 4.0 / 6.0) + assert_equal(4.0, 6.0 * 4 / 6) + assert_equal(4.0, 6 * + 4.0 / + 6) + assert_equal(4.0, 6 * 4 / 6.0) + assert_equal(4.0, 6.0 * 4.0 / 6) + assert_equal(4.0, 6 * 4.0 / 6.0) + assert_equal(4.0, 6.0 * 4 / 6.0) + assert_equal(4.0, 6.0 * 4.0 / 6.0) - assert_equal(4.0, 6.0 * 4.0 / 6.0) + assert_equal(4.0, 6.0 * 4.0 / 6.0) + END + CheckDefAndScriptSuccess(lines) endif enddef @@ -1531,12 +1517,15 @@ enddef " test low level expression def Test_expr7_number() # number constant - assert_equal(0, 0) - assert_equal(654, 0654) + var lines =<< trim END + assert_equal(0, 0) + assert_equal(654, 0654) - assert_equal(6, 0x6) - assert_equal(15, 0xf) - assert_equal(255, 0xff) + assert_equal(6, 0x6) + assert_equal(15, 0xf) + assert_equal(255, 0xff) + END + CheckDefAndScriptSuccess(lines) enddef def Test_expr7_float() @@ -1544,31 +1533,40 @@ def Test_expr7_float() if !has('float') MissingFeature 'float' else - assert_equal(g:float_zero, .0) - assert_equal(g:float_zero, 0.0) - assert_equal(g:float_neg, -9.8) - assert_equal(g:float_big, 9.9e99) + var lines =<< trim END + assert_equal(g:float_zero, .0) + assert_equal(g:float_zero, 0.0) + assert_equal(g:float_neg, -9.8) + assert_equal(g:float_big, 9.9e99) + END + CheckDefAndScriptSuccess(lines) endif enddef def Test_expr7_blob() # blob constant - assert_equal(g:blob_empty, 0z) - assert_equal(g:blob_one, 0z01) - assert_equal(g:blob_long, 0z0102.0304) + var lines =<< trim END + assert_equal(g:blob_empty, 0z) + assert_equal(g:blob_one, 0z01) + assert_equal(g:blob_long, 0z0102.0304) + END + CheckDefAndScriptSuccess(lines) CheckDefFailure(["var x = 0z123"], 'E973:', 1) enddef def Test_expr7_string() # string constant - assert_equal(g:string_empty, '') - assert_equal(g:string_empty, "") - assert_equal(g:string_short, 'x') - assert_equal(g:string_short, "x") - assert_equal(g:string_long, 'abcdefghijklm') - assert_equal(g:string_long, "abcdefghijklm") - assert_equal(g:string_special, "ab\ncd\ref\ekk") + var lines =<< trim END + assert_equal(g:string_empty, '') + assert_equal(g:string_empty, "") + assert_equal(g:string_short, 'x') + assert_equal(g:string_short, "x") + assert_equal(g:string_long, 'abcdefghijklm') + assert_equal(g:string_long, "abcdefghijklm") + assert_equal(g:string_special, "ab\ncd\ref\ekk") + END + CheckDefAndScriptSuccess(lines) CheckDefFailure(['var x = "abc'], 'E114:', 1) CheckDefFailure(["var x = 'abc"], 'E115:', 1) @@ -1587,22 +1585,32 @@ enddef def Test_expr7_special() # special constant - assert_equal(g:special_true, true) - assert_equal(g:special_false, false) - assert_equal(g:special_true, v:true) - assert_equal(g:special_false, v:false) + var lines =<< trim END + assert_equal(g:special_true, true) + assert_equal(g:special_false, false) + assert_equal(g:special_true, v:true) + assert_equal(g:special_false, v:false) + assert_equal(v:true, true) + assert_equal(v:false, false) - assert_equal(true, !false) - assert_equal(false, !true) - assert_equal(true, !0) - assert_equal(false, !1) - assert_equal(false, !!false) - assert_equal(true, !!true) - assert_equal(false, !!0) - assert_equal(true, !!1) + assert_equal(true, !false) + assert_equal(false, !true) + assert_equal(true, !0) + assert_equal(false, !1) + assert_equal(false, !!false) + assert_equal(true, !!true) + assert_equal(false, !!0) + assert_equal(true, !!1) - assert_equal(g:special_null, v:null) - assert_equal(g:special_none, v:none) + var t = true + var f = false + assert_equal(true, t) + assert_equal(false, f) + + assert_equal(g:special_null, v:null) + assert_equal(g:special_none, v:none) + END + CheckDefAndScriptSuccess(lines) CheckDefFailure(['v:true = true'], 'E46:', 1) CheckDefFailure(['v:true = false'], 'E46:', 1) @@ -1611,51 +1619,33 @@ def Test_expr7_special() CheckDefFailure(['v:none = 22'], 'E46:', 1) enddef -def Test_expr7_special_vim9script() - var lines =<< trim END - vim9script - var t = true - var f = false - assert_equal(v:true, true) - assert_equal(true, t) - assert_equal(v:false, false) - assert_equal(false, f) - assert_equal(true, !false) - assert_equal(false, !true) - assert_equal(true, !0) - assert_equal(false, !1) - assert_equal(false, !!false) - assert_equal(true, !!true) - assert_equal(false, !!0) - assert_equal(true, !!1) - END - CheckScriptSuccess(lines) -enddef - def Test_expr7_list() # list - assert_equal(g:list_empty, []) - assert_equal(g:list_empty, [ ]) + var lines =<< trim END + assert_equal(g:list_empty, []) + assert_equal(g:list_empty, [ ]) - var numbers: list<number> = [1, 2, 3] - numbers = [1] - numbers = [] + var numbers: list<number> = [1, 2, 3] + numbers = [1] + numbers = [] - var strings: list<string> = ['a', 'b', 'c'] - strings = ['x'] - strings = [] + var strings: list<string> = ['a', 'b', 'c'] + strings = ['x'] + strings = [] - var mixed: list<any> = [1, 'b', false,] - assert_equal(g:list_mixed, mixed) - assert_equal('b', mixed[1]) + var mixed: list<any> = [1, 'b', false,] + assert_equal(g:list_mixed, mixed) + assert_equal('b', mixed[1]) - echo [1, - 2] [3, - 4] + echo [1, + 2] [3, + 4] - var llstring: list<list<string>> = [['text'], []] - llstring = [[], ['text']] - llstring = [[], []] + var llstring: list<list<string>> = [['text'], []] + llstring = [[], ['text']] + llstring = [[], []] + END + CheckDefAndScriptSuccess(lines) var rangelist: list<number> = range(3) g:rangelist = range(3) @@ -1680,7 +1670,7 @@ def Test_expr7_list() CheckDefExecFailure(["var l: list<string> = [234, 'x']"], 'E1012:', 1) CheckDefExecFailure(["var l: list<string> = ['x', 123]"], 'E1012:', 1) - var lines =<< trim END + lines =<< trim END vim9script var datalist: list<string> def Main() @@ -1788,45 +1778,48 @@ def LambdaUsingArg(x: number): func enddef def Test_expr7_lambda() - var La = { -> 'result'} - assert_equal('result', La()) - assert_equal([1, 3, 5], [1, 2, 3]->map({key, val -> key + val})) + var lines =<< trim END + var La = { -> 'result'} + assert_equal('result', La()) + assert_equal([1, 3, 5], [1, 2, 3]->map({key, val -> key + val})) - # line continuation inside lambda with "cond ? expr : expr" works - var ll = range(3) - map(ll, {k, v -> v % 2 ? { - '111': 111 } : {} - }) - assert_equal([{}, {'111': 111}, {}], ll) + # line continuation inside lambda with "cond ? expr : expr" works + var ll = range(3) + map(ll, {k, v -> v % 2 ? { + '111': 111 } : {} + }) + assert_equal([{}, {'111': 111}, {}], ll) - ll = range(3) - map(ll, {k, v -> v == 8 || v - == 9 - || v % 2 ? 111 : 222 - }) - assert_equal([222, 111, 222], ll) + ll = range(3) + map(ll, {k, v -> v == 8 || v + == 9 + || v % 2 ? 111 : 222 + }) + assert_equal([222, 111, 222], ll) - ll = range(3) - map(ll, {k, v -> v != 8 && v - != 9 - && v % 2 == 0 ? 111 : 222 - }) - assert_equal([111, 222, 111], ll) + ll = range(3) + map(ll, {k, v -> v != 8 && v + != 9 + && v % 2 == 0 ? 111 : 222 + }) + assert_equal([111, 222, 111], ll) - var dl = [{'key': 0}, {'key': 22}]->filter({ _, v -> v['key'] }) - assert_equal([{'key': 22}], dl) + var dl = [{'key': 0}, {'key': 22}]->filter({ _, v -> v['key'] }) + assert_equal([{'key': 22}], dl) - dl = [{'key': 12}, {'foo': 34}] - assert_equal([{'key': 12}], filter(dl, - {_, v -> has_key(v, 'key') ? v['key'] == 12 : 0})) + dl = [{'key': 12}, {'foo': 34}] + assert_equal([{'key': 12}], filter(dl, + {_, v -> has_key(v, 'key') ? v['key'] == 12 : 0})) - assert_equal(false, LambdaWithComments()(0)) - assert_equal(true, LambdaWithComments()(1)) - assert_equal(true, LambdaWithComments()(2)) - assert_equal(false, LambdaWithComments()(3)) + assert_equal(false, LambdaWithComments()(0)) + assert_equal(true, LambdaWithComments()(1)) + assert_equal(true, LambdaWithComments()(2)) + assert_equal(false, LambdaWithComments()(3)) - assert_equal(false, LambdaUsingArg(0)()) - assert_equal(true, LambdaUsingArg(1)()) + assert_equal(false, LambdaUsingArg(0)()) + assert_equal(true, LambdaUsingArg(1)()) + END + CheckDefAndScriptSuccess(lines) CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:', 1) # error is in first line of the lambda @@ -1871,46 +1864,49 @@ enddef def Test_epxr7_funcref() var lines =<< trim END - def RetNumber(): number - return 123 - enddef - var FuncRef = RetNumber - assert_equal(123, FuncRef()) + def RetNumber(): number + return 123 + enddef + var FuncRef = RetNumber + assert_equal(123, FuncRef()) END CheckDefAndScriptSuccess(lines) enddef def Test_expr7_dict() # dictionary - assert_equal(g:dict_empty, {}) - assert_equal(g:dict_empty, { }) - assert_equal(g:dict_one, {'one': 1}) - var key = 'one' - var val = 1 - assert_equal(g:dict_one, {key: val}) + var lines =<< trim END + assert_equal(g:dict_empty, {}) + assert_equal(g:dict_empty, { }) + assert_equal(g:dict_one, {'one': 1}) + var key = 'one' + var val = 1 + assert_equal(g:dict_one, {key: val}) - var numbers: dict<number> = #{a: 1, b: 2, c: 3} - numbers = #{a: 1} - numbers = #{} + var numbers: dict<number> = #{a: 1, b: 2, c: 3} + numbers = #{a: 1} + numbers = #{} - var strings: dict<string> = #{a: 'a', b: 'b', c: 'c'} - strings = #{a: 'x'} - strings = #{} + var strings: dict<string> = #{a: 'a', b: 'b', c: 'c'} + strings = #{a: 'x'} + strings = #{} - var mixed: dict<any> = #{a: 'a', b: 42} - mixed = #{a: 'x'} - mixed = #{a: 234} - mixed = #{} + var mixed: dict<any> = #{a: 'a', b: 42} + mixed = #{a: 'x'} + mixed = #{a: 234} + mixed = #{} - var dictlist: dict<list<string>> = #{absent: [], present: ['hi']} - dictlist = #{absent: ['hi'], present: []} - dictlist = #{absent: [], present: []} + var dictlist: dict<list<string>> = #{absent: [], present: ['hi']} + dictlist = #{absent: ['hi'], present: []} + dictlist = #{absent: [], present: []} - var dictdict: dict<dict<string>> = #{one: #{a: 'text'}, two: #{}} - dictdict = #{one: #{}, two: #{a: 'text'}} - dictdict = #{one: #{}, two: #{}} + var dictdict: dict<dict<string>> = #{one: #{a: 'text'}, two: #{}} + dictdict = #{one: #{}, two: #{a: 'text'}} + dictdict = #{one: #{}, two: #{}} - assert_equal({'': 0}, {matchstr('string', 'wont match'): 0}) + assert_equal({'': 0}, {matchstr('string', 'wont match'): 0}) + END + CheckDefAndScriptSuccess(lines) CheckDefFailure(["var x = #{a:8}"], 'E1069:', 1) CheckDefFailure(["var x = #{a : 8}"], 'E1068:', 1) @@ -2311,11 +2307,15 @@ def s:Echo4Arg(arg: any): string enddef def Test_expr7_call() - assert_equal('yes', 'yes'->Echo()) + var lines =<< trim END + assert_equal('yes', 'yes'->Echo()) + assert_equal(true, !range(5)->empty()) + assert_equal([0, 1, 2], --3->range()) + END + CheckDefAndScriptSuccess(lines) + assert_equal('yes', 'yes' - ->s:Echo4Arg()) - assert_equal(true, !range(5)->empty()) - assert_equal([0, 1, 2], --3->range()) + ->s:Echo4Arg()) CheckDefFailure(["var x = 'yes'->Echo"], 'E107:', 1) CheckScriptFailure([