changeset 24695:13efbfc53054 v8.2.2886

patch 8.2.2886: various pieces of code not covered by tests Commit: https://github.com/vim/vim/commit/34fcb697240c1bc9e69417ed75db3b1a83479724 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Tue May 25 20:14:00 2021 +0200 patch 8.2.2886: various pieces of code not covered by tests Problem: Various pieces of code not covered by tests. Solution: Add a few more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/8255)
author Bram Moolenaar <Bram@vim.org>
date Tue, 25 May 2021 20:15:03 +0200
parents 44426ac4b715
children dc0703c51aef
files src/testdir/test_expr.vim src/testdir/test_functions.vim src/testdir/test_listdict.vim src/testdir/test_registers.vim src/testdir/test_user_func.vim src/testdir/test_vim9_builtin.vim src/testdir/test_vim9_expr.vim src/testdir/test_vim9_func.vim src/version.c
diffstat 9 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_expr.vim
+++ b/src/testdir/test_expr.vim
@@ -127,6 +127,7 @@ func Test_getreg_empty_list()
   let y = x
   call add(x, 'foo')
   call assert_equal(['foo'], y)
+  call assert_fails('call getreg([])', 'E730:')
 endfunc
 
 func Test_loop_over_null_list()
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -141,6 +141,7 @@ func Test_min()
 
   call assert_fails('call min(1)', 'E712:')
   call assert_fails('call min(v:none)', 'E712:')
+  call assert_fails('call min([1, {}])', 'E728:')
 
   " check we only get one error
   call assert_fails('call min([[1], #{}])', ['E745:', 'E745:'])
@@ -715,6 +716,7 @@ func Test_tr()
   call assert_fails("let s=tr('abcd', 'abcd', 'def')", 'E475:')
   call assert_equal('hEllO', tr('hello', 'eo', 'EO'))
   call assert_equal('hello', tr('hello', 'xy', 'ab'))
+  call assert_fails('call tr("abc", "123", "₁₂")', 'E475:')
   set encoding=utf8
 endfunc
 
@@ -2674,4 +2676,9 @@ func Test_default_arg_value()
   call assert_equal('msg', HasDefault())
 endfunc
 
+" Test for gettext()
+func Test_gettext()
+  call assert_fails('call gettext(1)', 'E475:')
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -513,6 +513,11 @@ func Test_list_locked_var_unlet()
       call assert_equal(expected[depth][u][1], ps)
     endfor
   endfor
+  " Deleting a list range should fail if the range is locked
+  let l = [1, 2, 3, 4]
+  lockvar l[1:2]
+  call assert_fails('unlet l[1:2]', 'E741:')
+  unlet l
 endfunc
 
 " Locked variables and :unlet or list / dict functions
--- a/src/testdir/test_registers.vim
+++ b/src/testdir/test_registers.vim
@@ -281,6 +281,7 @@ endfunc
 
 func Test_set_register()
   call assert_fails("call setreg('#', 200)", 'E86:')
+  call assert_fails("call setreg('a', test_unknown())", 'E908:')
 
   edit Xfile_alt_1
   let b1 = bufnr('')
@@ -470,6 +471,14 @@ func Test_get_reginfo()
   let info = getreginfo('"')
   call assert_equal('z', info.points_to)
 
+  let @a="a1b2"
+  nnoremap <F2> <Cmd>let g:RegInfo = getreginfo()<CR>
+  exe "normal \"a\<F2>"
+  call assert_equal({'regcontents': ['a1b2'], 'isunnamed': v:false,
+        \ 'regtype': 'v'}, g:RegInfo)
+  nunmap <F2>
+  unlet g:RegInfo
+
   bwipe!
 endfunc
 
--- a/src/testdir/test_user_func.vim
+++ b/src/testdir/test_user_func.vim
@@ -160,6 +160,16 @@ func Test_default_arg()
 	\ .. "1    return deepcopy(a:)\n"
 	\ .. "   endfunction",
 	\ execute('func Args2'))
+
+  " Error in default argument expression
+  let l =<< trim END
+    func F1(x = y)
+      return a:x * 2
+    endfunc
+    echo F1()
+  END
+  let @a = l->join("\n")
+  call assert_fails("exe @a", 'E121:')
 endfunc
 
 func s:addFoo(lead)
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -363,6 +363,7 @@ def Test_extend_arg_types()
   END
   CheckDefAndScriptSuccess(lines)
 
+  CheckDefFailure(['extend("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string')
   CheckDefFailure(['extend([1, 2], 3)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number')
   CheckDefFailure(['extend([1, 2], ["x"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
   CheckDefFailure(['extend([1, 2], [3], "x")'], 'E1013: Argument 3: type mismatch, expected number but got string')
@@ -726,6 +727,12 @@ def Test_insert()
   endfor
   res->assert_equal(6)
 
+  var m: any = []
+  insert(m, 4)
+  call assert_equal([4], m)
+  extend(m, [6], 0)
+  call assert_equal([6, 4], m)
+
   var lines =<< trim END
       insert(test_null_list(), 123)
   END
@@ -743,6 +750,7 @@ def Test_insert()
   assert_equal(['a', 'b', 'c'], insert(['b', 'c'], 'a'))
   assert_equal(0z1234, insert(0z34, 0x12))
 
+  CheckDefFailure(['insert("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 1)
   CheckDefFailure(['insert([2, 3], "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 1)
   CheckDefFailure(['insert([2, 3], 1, "x")'], 'E1013: Argument 3: type mismatch, expected number but got string', 1)
 enddef
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -1580,6 +1580,8 @@ def Test_expr7t()
       var ln: list<number> = [<number>g:anint, <number>g:thefour]
       var nr = <number>234
       assert_equal(234, nr)
+      var b: bool = <bool>1
+      assert_equal(true, b)
       var text =
             <string>
               'text'
@@ -1591,6 +1593,7 @@ def Test_expr7t()
 
   CheckDefAndScriptFailure(["var x = <nr>123"], 'E1010:', 1)
   CheckDefFailure(["var x = <number>"], 'E1097:', 3)
+  CheckDefFailure(["var x = <number>string(1)"], 'E1012:', 1)
   CheckScriptFailure(['vim9script', "var x = <number>"], 'E15:', 2)
   CheckDefAndScriptFailure(["var x = <number >123"], 'E1068:', 1)
   CheckDefAndScriptFailure(["var x = <number 123"], 'E1104:', 1)
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -397,6 +397,7 @@ def Test_call_default_args()
   delfunc g:Func
   CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string')
   delfunc g:Func
+  CheckDefFailure(['def Func(x: number = )', 'enddef'], 'E15:')
 
   lines =<< trim END
       vim9script
@@ -1315,6 +1316,8 @@ def Test_arg_type_wrong()
   CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...')
   CheckScriptFailure(['def Func5(items:string)', 'echo "a"'], 'E1069:')
   CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:')
+  CheckScriptFailure(['def Func6(...x:list<number>)', 'echo "a"', 'enddef'], 'E1069:')
+  CheckScriptFailure(['def Func7(...x: int)', 'echo "a"', 'enddef'], 'E1010:')
 enddef
 
 def Test_white_space_before_comma()
@@ -2717,6 +2720,11 @@ def Test_ignored_argument()
       var _ = 1
   END
   CheckDefAndScriptFailure(lines, 'E1181:', 1)
+
+  lines =<< trim END
+      var x = _
+  END
+  CheckDefAndScriptFailure(lines, 'E1181:', 1)
 enddef
 
 def Test_too_many_arguments()
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2886,
+/**/
     2885,
 /**/
     2884,