To: vim_dev@googlegroups.com Subject: Patch 8.2.1980 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1980 Problem: Vim9: some tests are not done at the script level. Solution: Use CheckDefAndScriptSuccess() in more places. Fix uncovered problems. Files: src/eval.c, src/list.c, src/scriptfile.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.1979/src/eval.c 2020-11-05 18:45:42.970909982 +0100 --- src/eval.c 2020-11-12 15:54:19.964860659 +0100 *************** *** 3438,3444 **** } #ifdef FEAT_FLOAT if (rettv->v_type == VAR_FLOAT) ! f = !f; else #endif { --- 3438,3452 ---- } #ifdef FEAT_FLOAT if (rettv->v_type == VAR_FLOAT) ! { ! if (in_vim9script()) ! { ! rettv->v_type = VAR_BOOL; ! val = f == 0.0 ? VVAL_TRUE : VVAL_FALSE; ! } ! else ! f = !f; ! } else #endif { *** ../vim-8.2.1979/src/list.c 2020-11-10 11:43:52.849854205 +0100 --- src/list.c 2020-11-12 19:26:46.341834815 +0100 *************** *** 1264,1270 **** had_comma = **arg == ','; if (had_comma) { ! if (vim9script && !IS_WHITE_OR_NUL((*arg)[1])) { semsg(_(e_white_space_required_after_str), ","); goto failret; --- 1264,1270 ---- had_comma = **arg == ','; if (had_comma) { ! if (vim9script && !IS_WHITE_OR_NUL((*arg)[1]) && (*arg)[1] != ']') { semsg(_(e_white_space_required_after_str), ","); goto failret; *** ../vim-8.2.1979/src/scriptfile.c 2020-10-24 23:08:34.711491620 +0200 --- src/scriptfile.c 2020-11-12 20:12:55.351789850 +0100 *************** *** 1332,1338 **** --- 1332,1341 ---- // set again. ht = &SCRIPT_VARS(sid); if (is_vim9) + { hashtab_free_contents(ht); + hash_init(ht); + } else { int todo = (int)ht->ht_used; *** ../vim-8.2.1979/src/testdir/test_vim9_expr.vim 2020-11-12 12:08:47.986254110 +0100 --- src/testdir/test_vim9_expr.vim 2020-11-12 20:15:06.383500296 +0100 *************** *** 13,64 **** " 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') ! 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) ! ! 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 X = FuncOne ! var Y = FuncTwo ! var Z = g:cond ? FuncOne : FuncTwo ! assert_equal(123, Z(3)) enddef def Test_expr1_trinary_vimscript() --- 13,67 ---- " test cond ? expr : expr def Test_expr1_trinary() ! 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') ! ! # 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 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)) ! END ! CheckDefAndScriptSuccess(lines) enddef def Test_expr1_trinary_vimscript() *************** *** 225,231 **** 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 --- 228,233 ---- *************** *** 233,264 **** " 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) ! ! 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) ! || Record(0)) ! assert_equal([0, 1], g:vals) ! ! g:vals = [] ! assert_equal(false, Record(0) || Record(false) || Record(0)) ! assert_equal([0, false, 0], g:vals) enddef def Test_expr2_vimscript() --- 235,286 ---- " test || def Test_expr2() ! 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(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(true) ! || Record(0)) ! assert_equal([0, true], 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,352 **** 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() --- 338,343 ---- *************** *** 367,402 **** " 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) ! ! 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(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) ! ! g:vals = [] ! assert_equal(false, Record(1) && Record(true) && Record(0)) ! assert_equal([1, true, 0], g:vals) enddef def Test_expr3_vimscript() --- 358,400 ---- " test && def Test_expr3() ! 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(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(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,491 **** 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() --- 452,457 ---- *************** *** 495,500 **** --- 461,468 ---- 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,821 **** " 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) ! ! 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) ! 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) ! ! assert_equal(false, 'abc' == 'aBc') ! assert_equal(false, 'abc' ==# 'aBc') ! assert_equal(true, 'abc' ==? 'aBc') ! ! assert_equal(false, 'abc' == 'ABC') ! set ignorecase ! assert_equal(false, 'abc' == 'ABC') ! assert_equal(false, 'abc' ==# 'ABC') ! set noignorecase 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) ! ! 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) ! 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 ! 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') ! 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) ! ! 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, 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])) 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 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 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 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 enddef " test =~ comperator def Test_expr4_match() ! assert_equal(false, '2' =~ '0') ! assert_equal(false, '' ! =~ '0') ! assert_equal(true, '2' =~ ! '[0-9]') enddef " test !~ comperator def Test_expr4_nomatch() ! assert_equal(true, '2' !~ '0') ! assert_equal(true, '' ! !~ '0') ! assert_equal(false, '2' !~ ! '[0-9]') 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 myblob = 0z1234 ! assert_false(myblob ! is 0z1234) ! var otherblob = myblob ! assert_true(myblob is otherblob) 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 myblob = 0z1234 ! assert_true(myblob ! isnot 0z1234) ! var otherblob = myblob ! assert_false(myblob isnot otherblob) enddef def RetVoid() --- 483,827 ---- " test == comperator def Test_expr4_equal() ! 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) ! ! 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) ! ! assert_equal(false, 'abc' == 'aBc') ! assert_equal(false, 'abc' ==# 'aBc') ! assert_equal(true, 'abc' ==? 'aBc') ! ! 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, [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')) ! END ! CheckDefAndScriptSuccess(lines) CheckDefFailure(["var x = 'a' == xxx"], 'E1001:', 1) CheckDefExecFailure(['var items: any', 'eval 1', 'eval 2', 'if items == []', 'endif'], 'E691:', 4) enddef " test != comperator def Test_expr4_notequal() ! 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) ! ! 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) ! ! 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(true, 'abc' != 'ABC') ! set ignorecase ! assert_equal(true, 'abc' != 'ABC') ! assert_equal(true, 'abc' !=# 'ABC') ! assert_equal(false, '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) ! ! 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, 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])) ! END ! CheckDefAndScriptSuccess(lines) enddef " test > comperator def Test_expr4_greater() ! 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() ! 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() ! 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() ! 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() ! 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() ! 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 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) ! END ! CheckDefAndScriptSuccess(lines) enddef " test isnot comperator def Test_expr4_isnot() ! 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) ! END ! CheckDefAndScriptSuccess(lines) enddef def RetVoid() *************** *** 896,920 **** 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 --- 902,907 ---- *************** *** 1032,1086 **** " 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) ! ! 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('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) ! ! # 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) ! $ENVVAR = 'env' ! assert_equal('aenv', 'a' .. $ENVVAR) enddef def Test_expr5_vim9script() --- 1019,1076 ---- " test addition, subtraction, concatenation def Test_expr5() ! 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('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([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 ! @b = 'b' ! assert_equal('ab', 'a' .. @b) ! $ENVVAR = 'env' ! assert_equal('aenv', 'a' .. $ENVVAR) ! END ! CheckDefAndScriptSuccess(lines) enddef def Test_expr5_vim9script() *************** *** 1196,1214 **** 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 --- 1186,1191 ---- *************** *** 1258,1281 **** 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) ! ! 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) endif enddef --- 1235,1261 ---- if !has('float') MissingFeature 'float' else ! 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) ! END ! CheckDefAndScriptSuccess(lines) endif enddef *************** *** 1319,1359 **** " 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) ! ! 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(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 CheckDefFailure(["var x = 6 * xxx"], 'E1001:', 1) enddef --- 1299,1342 ---- " test multiply, divide, modulo def Test_expr6() ! 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(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) ! ! 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,1447 **** 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) ! ! 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.0 / 6.0) endif enddef --- 1402,1433 ---- if !has('float') MissingFeature 'float' else ! 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(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) ! END ! CheckDefAndScriptSuccess(lines) endif enddef *************** *** 1531,1542 **** " test low level expression def Test_expr7_number() # number constant ! assert_equal(0, 0) ! assert_equal(654, 0654) ! assert_equal(6, 0x6) ! assert_equal(15, 0xf) ! assert_equal(255, 0xff) enddef def Test_expr7_float() --- 1517,1531 ---- " test low level expression def Test_expr7_number() # number constant ! var lines =<< trim END ! assert_equal(0, 0) ! assert_equal(654, 0654) ! assert_equal(6, 0x6) ! assert_equal(15, 0xf) ! assert_equal(255, 0xff) ! END ! CheckDefAndScriptSuccess(lines) enddef def Test_expr7_float() *************** *** 1544,1574 **** 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) 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) 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") CheckDefFailure(['var x = "abc'], 'E114:', 1) CheckDefFailure(["var x = 'abc"], 'E115:', 1) --- 1533,1572 ---- if !has('float') MissingFeature 'float' else ! 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 ! 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 ! 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,1625 **** 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) - - 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) - - CheckDefFailure(['v:true = true'], 'E46:', 1) - CheckDefFailure(['v:true = false'], 'E46:', 1) - CheckDefFailure(['v:false = true'], 'E46:', 1) - CheckDefFailure(['v:null = 11'], 'E46:', 1) - 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) --- 1585,1598 ---- def Test_expr7_special() # special constant 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) *************** *** 1628,1661 **** 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 numbers: list = [1, 2, 3] ! numbers = [1] ! numbers = [] ! ! var strings: list = ['a', 'b', 'c'] ! strings = ['x'] ! strings = [] ! ! var mixed: list = [1, 'b', false,] ! assert_equal(g:list_mixed, mixed) ! assert_equal('b', mixed[1]) ! ! echo [1, ! 2] [3, ! 4] ! ! var llstring: list> = [['text'], []] ! llstring = [[], ['text']] ! llstring = [[], []] var rangelist: list = range(3) g:rangelist = range(3) --- 1601,1651 ---- assert_equal(true, !!true) assert_equal(false, !!0) assert_equal(true, !!1) + + 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) ! CheckDefFailure(['v:false = true'], 'E46:', 1) ! CheckDefFailure(['v:null = 11'], 'E46:', 1) ! CheckDefFailure(['v:none = 22'], 'E46:', 1) enddef def Test_expr7_list() # list ! var lines =<< trim END ! assert_equal(g:list_empty, []) ! assert_equal(g:list_empty, [ ]) ! var numbers: list = [1, 2, 3] ! numbers = [1] ! numbers = [] ! ! var strings: list = ['a', 'b', 'c'] ! strings = ['x'] ! strings = [] ! ! var mixed: list = [1, 'b', false,] ! assert_equal(g:list_mixed, mixed) ! assert_equal('b', mixed[1]) ! ! echo [1, ! 2] [3, ! 4] ! ! var llstring: list> = [['text'], []] ! llstring = [[], ['text']] ! llstring = [[], []] ! END ! CheckDefAndScriptSuccess(lines) var rangelist: list = range(3) g:rangelist = range(3) *************** *** 1680,1686 **** CheckDefExecFailure(["var l: list = [234, 'x']"], 'E1012:', 1) CheckDefExecFailure(["var l: list = ['x', 123]"], 'E1012:', 1) ! var lines =<< trim END vim9script var datalist: list def Main() --- 1670,1676 ---- CheckDefExecFailure(["var l: list = [234, 'x']"], 'E1012:', 1) CheckDefExecFailure(["var l: list = ['x', 123]"], 'E1012:', 1) ! lines =<< trim END vim9script var datalist: list def Main() *************** *** 1788,1832 **** 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})) ! ! # 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 == 0 ? 111 : 222 ! }) ! assert_equal([111, 222, 111], ll) ! ! 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})) ! ! 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)()) CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:', 1) # error is in first line of the lambda --- 1778,1825 ---- enddef def Test_expr7_lambda() ! 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) ! ! 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) ! ! 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})) ! ! 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)()) ! END ! CheckDefAndScriptSuccess(lines) CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:', 1) # error is in first line of the lambda *************** *** 1871,1916 **** def Test_epxr7_funcref() var lines =<< trim END ! 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 numbers: dict = #{a: 1, b: 2, c: 3} ! numbers = #{a: 1} ! numbers = #{} ! ! var strings: dict = #{a: 'a', b: 'b', c: 'c'} ! strings = #{a: 'x'} ! strings = #{} ! ! var mixed: dict = #{a: 'a', b: 42} ! mixed = #{a: 'x'} ! mixed = #{a: 234} ! mixed = #{} ! ! var dictlist: dict> = #{absent: [], present: ['hi']} ! dictlist = #{absent: ['hi'], present: []} ! dictlist = #{absent: [], present: []} ! ! var dictdict: dict> = #{one: #{a: 'text'}, two: #{}} ! dictdict = #{one: #{}, two: #{a: 'text'}} ! dictdict = #{one: #{}, two: #{}} ! assert_equal({'': 0}, {matchstr('string', 'wont match'): 0}) CheckDefFailure(["var x = #{a:8}"], 'E1069:', 1) CheckDefFailure(["var x = #{a : 8}"], 'E1068:', 1) --- 1864,1912 ---- def Test_epxr7_funcref() var lines =<< trim END ! def RetNumber(): number ! return 123 ! enddef ! var FuncRef = RetNumber ! assert_equal(123, FuncRef()) END CheckDefAndScriptSuccess(lines) enddef def Test_expr7_dict() # dictionary ! 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 = #{a: 1, b: 2, c: 3} ! numbers = #{a: 1} ! numbers = #{} ! ! var strings: dict = #{a: 'a', b: 'b', c: 'c'} ! strings = #{a: 'x'} ! strings = #{} ! ! var mixed: dict = #{a: 'a', b: 42} ! mixed = #{a: 'x'} ! mixed = #{a: 234} ! mixed = #{} ! ! var dictlist: dict> = #{absent: [], present: ['hi']} ! dictlist = #{absent: ['hi'], present: []} ! dictlist = #{absent: [], present: []} ! ! var dictdict: dict> = #{one: #{a: 'text'}, two: #{}} ! dictdict = #{one: #{}, two: #{a: 'text'}} ! dictdict = #{one: #{}, two: #{}} ! 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,2321 **** enddef def Test_expr7_call() ! assert_equal('yes', 'yes'->Echo()) assert_equal('yes', 'yes' ! ->s:Echo4Arg()) ! assert_equal(true, !range(5)->empty()) ! assert_equal([0, 1, 2], --3->range()) CheckDefFailure(["var x = 'yes'->Echo"], 'E107:', 1) CheckScriptFailure([ --- 2307,2321 ---- enddef def Test_expr7_call() ! 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()) CheckDefFailure(["var x = 'yes'->Echo"], 'E107:', 1) CheckScriptFailure([ *** ../vim-8.2.1979/src/version.c 2020-11-12 15:12:12.034017200 +0100 --- src/version.c 2020-11-12 15:46:28.450342120 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1980, /**/ -- hundred-and-one symptoms of being an internet addict: 241. You try to look for Net Search even when you're in File Manager. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///