To: vim_dev@googlegroups.com Subject: Patch 8.2.0418 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0418 Problem: Code in eval.c not sufficiently covered by tests. Solution: Add more tests. (Yegappan Lakshmanan, closes #5815) Files: src/testdir/test_blob.vim, src/testdir/test_channel.vim, src/testdir/test_cmdline.vim, src/testdir/test_eval_stuff.vim, src/testdir/test_expr.vim, src/testdir/test_functions.vim, src/testdir/test_job_fails.vim, src/testdir/test_lambda.vim, src/testdir/test_let.vim, src/testdir/test_listdict.vim, src/testdir/test_marks.vim, src/testdir/test_method.vim, src/testdir/test_normal.vim, src/testdir/test_unlet.vim, src/testdir/test_usercommands.vim, src/testdir/test_vimscript.vim, src/testdir/test_window_cmd.vim *** ../vim-8.2.0417/src/testdir/test_blob.vim 2020-01-30 19:39:00.527127306 +0100 --- src/testdir/test_blob.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 87,92 **** --- 87,93 ---- call assert_equal(0z0011223344, b[:]) call assert_equal(0z0011223344, b[:-1]) call assert_equal(0z, b[5:6]) + call assert_equal(0z0011, b[-10:1]) endfunc func Test_blob_get() *** ../vim-8.2.0417/src/testdir/test_channel.vim 2020-03-19 19:44:29.155344080 +0100 --- src/testdir/test_channel.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 518,523 **** --- 518,532 ---- endif endfor call assert_equal(1, found) + + " Try to use the job and channel where a number is expected. This is not + " related to testing the raw pipe. This test is here just to reuse the + " already created job/channel. + let ch = job_getchannel(job) + call assert_fails('let i = job + 1', 'E910:') + call assert_fails('let j = ch + 1', 'E913:') + call assert_fails('echo 2.0 == job', 'E911:') + call assert_fails('echo 2.0 == ch', 'E914:') endfunc func Test_raw_pipe_blob() *************** *** 2025,2027 **** --- 2034,2038 ---- call WaitForAssert({-> assert_equal("local local", trim(g:Ch_reply))}) unlet $VAR1 endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0417/src/testdir/test_cmdline.vim 2020-03-18 19:32:22.510363327 +0100 --- src/testdir/test_cmdline.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 195,229 **** call assert_equal([], getcompletion('A', 'highlight')) endfunc - func Test_expr_completion() - if !has('cmdline_compl') - return - endif - for cmd in [ - \ 'let a = ', - \ 'const a = ', - \ 'if', - \ 'elseif', - \ 'while', - \ 'for', - \ 'echo', - \ 'echon', - \ 'execute', - \ 'echomsg', - \ 'echoerr', - \ 'call', - \ 'return', - \ 'cexpr', - \ 'caddexpr', - \ 'cgetexpr', - \ 'lexpr', - \ 'laddexpr', - \ 'lgetexpr'] - call feedkeys(":" . cmd . " getl\\\"\", 'xt') - call assert_equal('"' . cmd . ' getline(', getreg(':')) - endfor - endfunc - func Test_getcompletion() if !has('cmdline_compl') return --- 195,200 ---- *************** *** 612,618 **** endif endfunc ! funct Test_cmdline_complete_languages() let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') call feedkeys(":language \\\"\", 'tx') --- 583,589 ---- endif endfunc ! func Test_cmdline_complete_languages() let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '') call feedkeys(":language \\\"\", 'tx') *************** *** 636,645 **** func Test_cmdline_complete_env_variable() let $X_VIM_TEST_COMPLETE_ENV = 'foo' - call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\\\"\", 'tx') call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:) - unlet $X_VIM_TEST_COMPLETE_ENV endfunc --- 607,614 ---- *************** *** 781,797 **** call feedkeys(":e `a1b2c\t\\"\", 'xt') call assert_equal('"e `a1b2c', @:) - " completion for the expression register - call feedkeys(":\"\=float2\t\"\\"\", 'xt') - call assert_equal('"float2nr("', @=) - " completion for :language command with an invalid argument call feedkeys(":language dummy \t\\"\", 'xt') call assert_equal("\"language dummy \t", @:) " completion for commands after a :global command ! call feedkeys(":g/a\\xb/call float2\t\\"\", 'xt') ! call assert_equal('"g/a\xb/call float2nr(', @:) " completion with ambiguous user defined commands com TCmd1 echo 'TCmd1' --- 750,762 ---- call feedkeys(":e `a1b2c\t\\"\", 'xt') call assert_equal('"e `a1b2c', @:) " completion for :language command with an invalid argument call feedkeys(":language dummy \t\\"\", 'xt') call assert_equal("\"language dummy \t", @:) " completion for commands after a :global command ! call feedkeys(":g/a\\xb/clearj\t\\"\", 'xt') ! call assert_equal('"g/a\xb/clearjumps', @:) " completion with ambiguous user defined commands com TCmd1 echo 'TCmd1' *************** *** 804,823 **** " completion after a range followed by a pipe (|) character call feedkeys(":1,10 | chist\t\\"\", 'xt') call assert_equal('"1,10 | chistory', @:) - - " completion for window local variables - let w:wvar1 = 10 - let w:wvar2 = 10 - call feedkeys(":echo w:wvar\\\"\", 'xt') - call assert_equal('"echo w:wvar1 w:wvar2', @:) - unlet w:wvar1 w:wvar2 - - " completion for tab local variables - let t:tvar1 = 10 - let t:tvar2 = 10 - call feedkeys(":echo t:tvar\\\"\", 'xt') - call assert_equal('"echo t:tvar1 t:tvar2', @:) - unlet t:tvar1 t:tvar2 endfunc func Test_cmdline_write_alternatefile() --- 769,774 ---- *** ../vim-8.2.0417/src/testdir/test_eval_stuff.vim 2020-02-22 14:26:39.248757828 +0100 --- src/testdir/test_eval_stuff.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 234,236 **** --- 234,238 ---- " correctly. call assert_equal(64, v:numbersize) endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0417/src/testdir/test_expr.vim 2020-02-17 22:11:39.666644199 +0100 --- src/testdir/test_expr.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 73,78 **** --- 73,80 ---- call assert_equal('', strcharpart('axb', -2, 2)) call assert_equal('a', strcharpart('axb', -1, 2)) + + call assert_equal('edit', "editor"[-10:3]) endfunc func Test_getreg_empty_list() *************** *** 476,481 **** --- 478,484 ---- call assert_fails("call function('foo()')", 'E475:') call assert_fails("call function('foo()')", 'foo()') + call assert_fails("function('')", 'E129:') endfunc func Test_funcref() *************** *** 533,535 **** --- 536,630 ---- if 0 | eval SetVal('a') | endif | call SetVal('b') call assert_equal('b', s:val) endfunc + + " Test for command-line completion of expressions + func Test_expr_completion() + if !has('cmdline_compl') + return + endif + for cmd in [ + \ 'let a = ', + \ 'const a = ', + \ 'if', + \ 'elseif', + \ 'while', + \ 'for', + \ 'echo', + \ 'echon', + \ 'execute', + \ 'echomsg', + \ 'echoerr', + \ 'call', + \ 'return', + \ 'cexpr', + \ 'caddexpr', + \ 'cgetexpr', + \ 'lexpr', + \ 'laddexpr', + \ 'lgetexpr'] + call feedkeys(":" . cmd . " getl\\\"\", 'xt') + call assert_equal('"' . cmd . ' getline(', getreg(':')) + endfor + + " completion for the expression register + call feedkeys(":\"\=float2\t\"\\"\", 'xt') + call assert_equal('"float2nr("', @=) + + " completion for window local variables + let w:wvar1 = 10 + let w:wvar2 = 10 + call feedkeys(":echo w:wvar\\\"\", 'xt') + call assert_equal('"echo w:wvar1 w:wvar2', @:) + unlet w:wvar1 w:wvar2 + + " completion for tab local variables + let t:tvar1 = 10 + let t:tvar2 = 10 + call feedkeys(":echo t:tvar\\\"\", 'xt') + call assert_equal('"echo t:tvar1 t:tvar2', @:) + unlet t:tvar1 t:tvar2 + + " completion for variables + let g:tvar1 = 1 + let g:tvar2 = 2 + call feedkeys(":let g:tv\\\"\", 'xt') + call assert_equal('"let g:tvar1 g:tvar2', @:) + " completion for variables after a || + call feedkeys(":echo 1 || g:tv\\\"\", 'xt') + call assert_equal('"echo 1 || g:tvar1 g:tvar2', @:) + + " completion for options + call feedkeys(":echo &compat\\\"\", 'xt') + call assert_equal('"echo &compatible', @:) + call feedkeys(":echo 1 && &compat\\\"\", 'xt') + call assert_equal('"echo 1 && &compatible', @:) + call feedkeys(":echo &g:equala\\\"\", 'xt') + call assert_equal('"echo &g:equalalways', @:) + + " completion for string + call feedkeys(":echo \"Hello\\ World\"\\\"\", 'xt') + call assert_equal("\"echo \"Hello\\ World\"\", @:) + call feedkeys(":echo 'Hello World'\\\"\", 'xt') + call assert_equal("\"echo 'Hello World'\", @:) + + " completion for command after a | + call feedkeys(":echo 'Hello' | cwin\\\"\", 'xt') + call assert_equal("\"echo 'Hello' | cwindow", @:) + + " completion for environment variable + let $X_VIM_TEST_COMPLETE_ENV = 'foo' + call feedkeys(":let $X_VIM_TEST_COMPLETE_E\\\"\", 'tx') + call assert_match('"let $X_VIM_TEST_COMPLETE_ENV', @:) + unlet $X_VIM_TEST_COMPLETE_ENV + endfunc + + " Test for errors in expression evaluation + func Test_expr_eval_error() + call assert_fails("let i = 'abc' . []", 'E730:') + call assert_fails("let l = [] + 10", 'E745:') + call assert_fails("let v = 10 + []", 'E745:') + call assert_fails("let v = 10 / []", 'E745:') + call assert_fails("let v = -{}", 'E728:') + endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0417/src/testdir/test_functions.vim 2020-03-18 19:32:22.510363327 +0100 --- src/testdir/test_functions.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 1145,1150 **** --- 1145,1151 ---- norm gg4|mx6|mY2| call assert_equal(2, col('.')) call assert_equal(7, col('$')) + call assert_equal(2, col('v')) call assert_equal(4, col("'x")) call assert_equal(6, col("'Y")) call assert_equal(2, [1, 2]->col()) *************** *** 1155,1160 **** --- 1156,1174 ---- call assert_equal(0, col([2, '$'])) call assert_equal(0, col([1, 100])) call assert_equal(0, col([1])) + + " test for getting the visual start column + func T() + let g:Vcol = col('v') + return '' + endfunc + let g:Vcol = 0 + xmap T() + exe "normal gg3|ve\" + call assert_equal(3, g:Vcol) + xunmap + delfunc T + bw! endfunc *** ../vim-8.2.0417/src/testdir/test_job_fails.vim 2018-04-28 21:13:12.000000000 +0200 --- src/testdir/test_job_fails.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 1,6 **** " This test is in a separate file, because it usually causes reports for memory " leaks under valgrind. That is because when fork/exec fails memory is not ! " freed. Since the process exists right away it's not a real leak. source shared.vim --- 1,6 ---- " This test is in a separate file, because it usually causes reports for memory " leaks under valgrind. That is because when fork/exec fails memory is not ! " freed. Since the process exits right away it's not a real leak. source shared.vim *************** *** 14,16 **** --- 14,18 ---- endif endif endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0417/src/testdir/test_lambda.vim 2020-01-30 18:24:47.001204003 +0100 --- src/testdir/test_lambda.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 63,68 **** --- 63,69 ---- call assert_equal(3, {a, b -> a + b}(1, 2)) call assert_fails('echo {a, a -> a + a}(1, 2)', 'E853:') call assert_fails('echo {a, b -> a + b)}(1, 2)', 'E15:') + echo assert_fails('echo 10->{a -> a + 2}', 'E107:') endfunc func Test_not_lamda() *************** *** 309,311 **** --- 310,314 ---- " This was causing a crash call assert_fails('ec{@{->{d->()()', 'E15') endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0417/src/testdir/test_let.vim 2020-03-18 19:32:22.510363327 +0100 --- src/testdir/test_let.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 275,280 **** --- 275,291 ---- let s = "var" let var = 1 call assert_fails('let {s}.1 = 2', 'E18:') + call assert_fails('let a[1] = 5', 'E121:') + let l = [[1,2]] + call assert_fails('let l[:][0] = [5]', 'E708:') + let d = {'k' : 4} + call assert_fails('let d.# = 5', 'E713:') + call assert_fails('let d.m += 5', 'E734:') + let l = [1, 2] + call assert_fails('let l[2] = 0', 'E684:') + call assert_fails('let l[0:1] = [1, 2, 3]', 'E710:') + call assert_fails('let l[-2:-3] = [3, 4]', 'E684:') + call assert_fails('let l[0:4] = [5, 6]', 'E711:') " This test works only when the language is English if v:lang == "C" || v:lang =~ '^[Ee]n' *** ../vim-8.2.0417/src/testdir/test_listdict.vim 2020-03-18 19:32:22.510363327 +0100 --- src/testdir/test_listdict.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 31,36 **** --- 31,37 ---- call assert_equal([1, 'as''d', [1, 2, function('strlen')]], l[:-2]) call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8]) call assert_equal([], l[8:-1]) + call assert_equal([], l[0:-10]) endfunc " List identity *************** *** 104,109 **** --- 105,112 ---- let l = [0] let l[:] = [1, 2] call assert_equal([1, 2], l) + let l[-4:-1] = [5, 6] + call assert_equal([5, 6], l) endfunc " Test removing items in list *************** *** 648,653 **** --- 651,662 ---- call assert_true(d == d) call assert_false(l != deepcopy(l)) call assert_false(d != deepcopy(d)) + + " comparison errors + call assert_fails('echo [1, 2] =~ {}', 'E691:') + call assert_fails('echo [1, 2] =~ [1, 2]', 'E692:') + call assert_fails('echo {} =~ 5', 'E735:') + call assert_fails('echo {} =~ {}', 'E736:') endfunc " compare complex recursively linked list and dict *************** *** 842,845 **** --- 851,867 ---- unlet deep_dict endfunc + " List and dict indexing tests + func Test_listdict_index() + call assert_fails('echo function("min")[0]', 'E695:') + call assert_fails('echo v:true[0]', 'E909:') + let d = {'k' : 10} + call assert_fails('echo d.', 'E15:') + call assert_fails('echo d[1:2]', 'E719:') + call assert_fails("let v = [4, 6][{-> 1}]", 'E729:') + call assert_fails("let v = range(5)[2:[]]", 'E730:') + call assert_fails("let v = range(5)[2:{-> 2}(]", 'E116:') + call assert_fails("let v = range(5)[2:3", 'E111:') + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0417/src/testdir/test_marks.vim 2020-03-10 07:48:06.571619551 +0100 --- src/testdir/test_marks.vim 2020-03-20 18:15:38.686063304 +0100 *************** *** 81,86 **** --- 81,95 ---- call assert_equal([0, 1, 21341234, 0], getpos("'a")) call assert_equal(4, virtcol("'a")) + " Test with invalid buffer number, line number and column number + call cursor(2, 2) + call setpos('.', [-1, 1, 1, 0]) + call assert_equal([2, 2], [line('.'), col('.')]) + call setpos('.', [0, -1, 1, 0]) + call assert_equal([2, 2], [line('.'), col('.')]) + call setpos('.', [0, 1, -1, 0]) + call assert_equal([2, 2], [line('.'), col('.')]) + bwipe! call win_gotoid(twowin) bwipe! *** ../vim-8.2.0417/src/testdir/test_method.vim 2020-01-26 21:42:00.089532706 +0100 --- src/testdir/test_method.vim 2020-03-20 18:15:38.690063290 +0100 *************** *** 35,40 **** --- 35,41 ---- call assert_equal(v:t_list, l->type()) call assert_equal([1, 2, 3], [1, 1, 2, 3, 3]->uniq()) call assert_fails('eval l->values()', 'E715:') + call assert_fails('echo []->len', 'E107:') endfunc func Test_dict_method() *************** *** 152,154 **** --- 153,157 ---- func Test_method_not_supported() call assert_fails('eval 123->changenr()', 'E276:') endfunc + + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0417/src/testdir/test_normal.vim 2020-03-10 07:48:06.571619551 +0100 --- src/testdir/test_normal.vim 2020-03-20 18:15:38.690063290 +0100 *************** *** 420,425 **** --- 420,426 ---- " Test expand(`=...`) i.e. backticks expression expansion call assert_equal('5', expand('`=2+3`')) + call assert_equal('3.14', expand('`=3.14`')) " clean up bw! *** ../vim-8.2.0417/src/testdir/test_unlet.vim 2020-03-18 19:32:22.514363313 +0100 --- src/testdir/test_unlet.vim 2020-03-20 18:15:38.690063290 +0100 *************** *** 21,26 **** --- 21,32 ---- func Test_unlet_fails() call assert_fails('unlet v:["count"]', 'E46:') call assert_fails('unlet $', 'E475:') + let v = {} + call assert_fails('unlet v[:]', 'E719:') + let l = [] + call assert_fails("unlet l['k'", 'E111:') + let d = {'k' : 1} + call assert_fails("unlet d.k2", 'E716:') endfunc func Test_unlet_env() *** ../vim-8.2.0417/src/testdir/test_usercommands.vim 2020-03-16 21:25:16.998615353 +0100 --- src/testdir/test_usercommands.vim 2020-03-20 18:15:38.690063290 +0100 *************** *** 549,552 **** --- 549,573 ---- call assert_equal("\nNo user-defined commands found", execute('command')) endfunc + " Test for a custom user completion returning the wrong value type + func Test_usercmd_custom() + func T1(a, c, p) + return "a\nb\n" + endfunc + command -nargs=* -complete=customlist,T1 TCmd1 + call feedkeys(":T1 \\\"\", 'xt') + call assert_equal('"T1 ', @:) + delcommand TCmd1 + delfunc T1 + + func T2(a, c, p) + return ['a', 'b', 'c'] + endfunc + command -nargs=* -complete=customlist,T2 TCmd2 + call feedkeys(":T2 \\\"\", 'xt') + call assert_equal('"T2 ', @:) + delcommand TCmd2 + delfunc T2 + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.0417/src/testdir/test_vimscript.vim 2020-03-18 19:32:22.514363313 +0100 --- src/testdir/test_vimscript.vim 2020-03-20 18:15:38.690063290 +0100 *************** *** 1737,1742 **** --- 1737,1744 ---- call assert_equal(4.2, x) call assert_fails('let x %= 0.5', 'E734') call assert_fails('let x .= "f"', 'E734') + let x = !3.14 + call assert_equal(0.0, x) endif " Test for environment variable *************** *** 2083,2088 **** --- 2085,2104 ---- delfunc Xfunc endfunc + " Test for errors in converting to float from various types {{{1 + func Test_float_conversion_errors() + if has('float') + call assert_fails('let x = 4.0 % 2.0', 'E804') + call assert_fails('echo 1.1[0]', 'E806') + call assert_fails('echo sort([function("min"), 1], "f")', 'E891:') + call assert_fails('echo 3.2 == "vim"', 'E892:') + call assert_fails('echo sort([[], 1], "f")', 'E893:') + call assert_fails('echo sort([{}, 1], "f")', 'E894:') + call assert_fails('echo 3.2 == v:true', 'E362:') + call assert_fails('echo 3.2 == v:none', 'E907:') + endif + endfunc + "------------------------------------------------------------------------------- " Modelines {{{1 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker *** ../vim-8.2.0417/src/testdir/test_window_cmd.vim 2020-02-18 21:54:36.982093690 +0100 --- src/testdir/test_window_cmd.vim 2020-03-20 18:15:38.690063290 +0100 *************** *** 546,551 **** --- 546,556 ---- call assert_equal(59, line("w0")) call assert_equal('59 ', s3) + %d + call setline(1, ['one', 'two', 'three']) + call assert_equal(1, line('w0')) + call assert_equal(3, line('w$')) + bwipeout! call test_garbagecollect_now() endfunc *** ../vim-8.2.0417/src/version.c 2020-03-20 18:11:15.778980169 +0100 --- src/version.c 2020-03-20 18:15:18.686133458 +0100 *************** *** 740,741 **** --- 740,743 ---- { /* Add new patch number below this line */ + /**/ + 418, /**/ -- You had connectors? Eeee, when I were a lad we 'ad to carry the bits between the computer and the terminal with a spoon... /// 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 ///