changeset 20109:e82996ad131f v8.2.0610

patch 8.2.0610: some tests are still old style Commit: https://github.com/vim/vim/commit/08f4157c5cabc55bcb22f04dd7c717aba40caa34 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 20 16:50:00 2020 +0200 patch 8.2.0610: some tests are still old style Problem: Some tests are still old style. Solution: Convert to new style tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5957)
author Bram Moolenaar <Bram@vim.org>
date Mon, 20 Apr 2020 17:00:04 +0200
parents 8823765c60f2
children e24fd2902727
files src/testdir/test_blob.vim src/testdir/test_cursor_func.vim src/testdir/test_eval.in src/testdir/test_eval.ok src/testdir/test_eval_func.vim src/testdir/test_eval_stuff.vim src/testdir/test_expr.vim src/testdir/test_filter_map.vim src/testdir/test_functions.vim src/testdir/test_listdict.vim src/testdir/test_sort.vim src/testdir/test_syntax.vim src/testdir/test_utf8.vim src/testdir/test_vimscript.vim src/version.c
diffstat 15 files changed, 178 insertions(+), 106 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_blob.vim
+++ b/src/testdir/test_blob.vim
@@ -307,6 +307,9 @@ func Test_blob_insert()
   call assert_fails('call insert(b, -1)', 'E475:')
   call assert_fails('call insert(b, 257)', 'E475:')
   call assert_fails('call insert(b, 0, [9])', 'E745:')
+  call assert_fails('call insert(b, 0, -20)', 'E475:')
+  call assert_fails('call insert(b, 0, 20)', 'E475:')
+  call assert_fails('call insert(b, [])', 'E745:')
 endfunc
 
 func Test_blob_reverse()
--- a/src/testdir/test_cursor_func.vim
+++ b/src/testdir/test_cursor_func.vim
@@ -115,3 +115,5 @@ func Test_screenpos_number()
   close
   bwipe!
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_eval.in
+++ b/src/testdir/test_eval.in
@@ -27,14 +27,6 @@ endfun
         execute "silent normal! Go==\n==\e\"".a:1."P"
     endif
 endfun
-:fun ErrExe(str)
-    call append('$', 'Executing '.a:str)
-    try
-        execute a:str
-    catch
-        $put =v:exception
-    endtry
-endfun
 :fun Test()
 $put ='{{{1 Appending NL with setreg()'
 call setreg('a', 'abcA2', 'c')
@@ -109,103 +101,19 @@ else
   call AppendRegParts('*', 'V', "clipboard contents\n", "['clipboard contents']", "clipboard contents\n", "['clipboard contents']")
   call AppendRegParts('*', 'V', "something else\n", "['something else']", "something else\n", "['something else']")
 endif
-$put ='{{{1 Errors'
-call ErrExe('call setreg()')
-call ErrExe('call setreg(1)')
-call ErrExe('call setreg(1, 2, 3, 4)')
-call ErrExe('call setreg([], 2)')
-call ErrExe('call setreg(1, {})')
-call ErrExe('call setreg(1, 2, [])')
-call ErrExe('call setreg("/", ["1", "2"])')
-call ErrExe('call setreg("=", ["1", "2"])')
-call ErrExe('call setreg(1, ["", "", [], ""])')
 endfun
 :"
 :call Test()
 :"
 :delfunction SetReg
 :delfunction AppendRegContents
-:delfunction ErrExe
 :delfunction Test
 :delcommand AR
 :call garbagecollect(1)
 :"
-:" function name not starting with capital
-:try
-:func! g:test()
-:echo "test"
-:endfunc
-:catch
-:$put =v:exception
-:endtry
-:"
-:" function name includes a colon
-:try
-:func! b:test()
-:echo "test"
-:endfunc
-:catch
-:$put =v:exception
-:endtry
-:"
-:" function name folowed by #
-:try
-:func! test2() "#
-:echo "test2"
-:endfunc
-:catch
-:$put =v:exception
-:endtry
-:"
-:" function name starting with/without "g:", buffer-local funcref.
-:function! g:Foo(n)
-:  $put ='called Foo(' . a:n . ')'
-:endfunction
-:let b:my_func = function('Foo')
-:call b:my_func(1)
-:echo g:Foo(2)
-:echo Foo(3)
-:"
-:" script-local function used in Funcref must exist.
-:so test_eval_func.vim
-:"
-:" Using $ instead of '$' must give an error
-:try
-: call append($, 'foobar')
-:catch
-:$put =v:exception
-:endtry
-:"
-:$put ='{{{1 getcurpos/setpos'
-/^012345678
-6l:let sp = getcurpos()
-0:call setpos('.', sp)
-jyl:$put
-:"
-:" substring and variable name
-:let str = 'abcdef'
-:let n = 3
-:$put =str[n:]
-:$put =str[:n]
-:$put =str[n:n]
-:unlet n
-:let nn = 3
-:$put =str[nn:]
-:$put =str[:nn]
-:$put =str[nn:nn]
-:unlet nn
-:let b:nn = 4
-:$put =str[b:nn:]
-:$put =str[:b:nn]
-:$put =str[b:nn:b:nn]
-:unlet b:nn
-:"
 :/^start:/+1,$wq! test.out
 :" vim: et ts=4 isk-=\: fmr=???,???
 :call getchar()
 ENDTEST
 
-012345678
-012345678
-
 start:
index cb7c85e254424dccda4ff03df0a4d11b3655bbfa..3ae6f6c67184852ca66d7e73d7a9552d12de5bca
GIT binary patch
literal 6716
zc%02xOK;mo5Z?3t0G}7RC@vgGe7HqZ=pc#GDafTjFF_6@#l!*_SuokOf&P3sJ3IRz
zhqP=Lb$u|GJCAR6_nVm&&*yWbR;N>S+#il#)yEI&uS0vMnyP)MzP`Pd=kqzHx7liT
zqh?}uEm!YV`{PupKYml+^ZL)~y~>Mn6$|zD(@c+MpRaFJ_4nz4lgQ;#>M;xgfHeYi
z|H=+!ZBV}ZC~NC$9fM+s#7F^TsV8I)Z9~i1aLd`mf_!ZlBu;D=wu$9nWtm-B-2rAC
zVCFn#3?L^qfEfe0rNwPItgUmlWw1E0!P+udJG;1|1Kb(FtA&ravnR7-02wKr+b&*8
z1$dGAy=q%vX?<wgW{RkJ=L7kc%sv}7<s6$<2@x~tQ8o}zEUToq@`8ZY2n2^)a2vi(
zEHQgXJ&D=obu!rHlCU<21$$l6Uf%}PrQkO`tWZF!+VoeoC!|cP?OC?ku(KXWPeL3W
zE~o;S=tjleVmgiPE$P&&0a_$t(a8n+jesATBxp19;V)2yFd`X4OmZ007Z(!*^Mwtj
z@4X)ZCns2f^sDZpd|o*|mzK~gp3nl-9DQ;5+A?JLq^6_1#JO?i*GT<*g8QiF5gnnl
zZ7&%nRb6)A)ZqL!E=dXutMCf^)z4v?2vl@Qfmqr$%$rF~mq@CsRX9B?|0X4L2jm-o
zM(H%X{6QGB3Uh2y)g>KH4fe@nl-B1vI#C24u8aFrp;5o*Kh>6Q1;jUe@OK154VMf2
zRl$-8wK+=Bs2t<rWv2F$VTp;Nady_WU+}jNVjMnfJ_O98Q9Z)eOKs`il1Rf{l(3f=
z!?wb<pp4BeM^IGfXiB4EjN6x)(%xs3eZY5o788~B@vH79ywhkN*0DXW%Th%MWA_O0
z>E>inCX?v-UdPf)NTV~7Xu|P4ep<R=uwXZxJzlH`GL?wWcRH4$xC5ZXCaZ8c6I;&P
ze)7v?&I<D$PbZ)kE22y$^Ru0LUCL`y%H+BdG!=76FI>vqE^r^Zr<eV=i>dU-sI~EQ
zI(uOosHxKM61QI2c*@_f#F(Aaen)?&eEe|X50>=ZBFNtKU986fUlKQ;nyF3$mXot(
zsdHzF1~{ToA_gvOL3wTfe%bo(P^qkS_NJ79r6e;suo;v&cacrYFbJ4%QNUZ`Nm82B
zftbQru!RvEo5H1C+F>FXXH?i;5>8M;Ujg10Tkv8kthSfdSTdHQzj)I+3<f4#Fz}Xm
zl9VRtXln1La(K-G$EKuemv)#4#+kiIy(FHXy1xcKUH8BVo(-ByYbzPULE^Zt1ZfdQ
z0~0P9cuPD<N|SUt&{63d!&UTa&_}?vsq)&X9VUWtM@`@*0R{c$72s`O0xx0XF^xuh
z>)yzho%KC2pIQKLn-<X`j1H$<eE6OO($op;sYTHLD|>E1|2HtWUj*R2Bx1xheRceI
z!VJD?{!c=p^ELkLv63@9SmVl*gpTN<kw27oDnIV^I;*BR+#j3p=;w6wa{!-n4Qg(d
zI1hKspQfni%Q5d_+&z^ot>Xg(0t+E}7)y=u21IYP-lc0m6A(D#G0$ScH5<RNvfc%`
z?~dh1(^lV9SszZteg3eQKMi`1m8tUn*jC53(ICTV5Ai8B3}kcvt!nS!URu>nrA@;r
J59$(K`46Ck)a(EN
deleted file mode 100644
--- a/src/testdir/test_eval_func.vim
+++ /dev/null
@@ -1,10 +0,0 @@
-" Vim script used in test_eval.in.  Needed for script-local function.
-
-func s:Testje()
-  return "foo"
-endfunc
-let Bar = function('s:Testje')
-$put ='s:Testje exists: ' . exists('s:Testje')
-$put ='func s:Testje exists: ' . exists('*s:Testje')
-$put ='Bar exists: ' . exists('Bar')
-$put ='func Bar exists: ' . exists('*Bar')
--- a/src/testdir/test_eval_stuff.vim
+++ b/src/testdir/test_eval_stuff.vim
@@ -349,7 +349,17 @@ func Test_setreg_basic()
   call setreg('I', 'abcI')
   call Assert_reg('I', "v", "abcI", "['abcI']", "abcI", "['abcI']")
   call Assert_regput('I', ['==', '=abcI='])
+
+  " Error cases
+  call assert_fails('call setreg()', 'E119:')
+  call assert_fails('call setreg(1)', 'E119:')
+  call assert_fails('call setreg(1, 2, 3, 4)', 'E118:')
+  call assert_fails('call setreg([], 2)', 'E730:')
+  call assert_fails('call setreg(1, {})', 'E731:')
+  call assert_fails('call setreg(1, 2, [])', 'E730:')
+  call assert_fails('call setreg("/", ["1", "2"])', 'E883:')
+  call assert_fails('call setreg("=", ["1", "2"])', 'E883:')
+  call assert_fails('call setreg(1, ["", "", [], ""])', 'E730:')
 endfunc
 
-
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_expr.vim
+++ b/src/testdir/test_expr.vim
@@ -44,6 +44,7 @@ func Test_dict()
   call assert_equal('zero', d[0])
   call assert_true(has_key(d, ''))
   call assert_true(has_key(d, 'a'))
+  call assert_fails("let i = has_key([], 'a')", 'E715:')
 
   let d[''] = 'none'
   let d['a'] = 'aaa'
--- a/src/testdir/test_filter_map.vim
+++ b/src/testdir/test_filter_map.vim
@@ -89,9 +89,15 @@ func Test_filter_map_dict_expr_funcref()
   call assert_equal({"foo": "f", "bar": "b", "baz": "b"}, map(copy(dict), function('s:filter4')))
 endfunc
 
-func Test_map_fails()
+func Test_map_filter_fails()
   call assert_fails('call map([1], "42 +")', 'E15:')
   call assert_fails('call filter([1], "42 +")', 'E15:')
+  call assert_fails("let l = map('abc', '\"> \" . v:val')", 'E712:')
+  call assert_fails("let l = filter('abc', '\"> \" . v:val')", 'E712:')
+  call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:')
+  call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:')
+  call assert_equal(0, map(test_null_list(), '"> " .. v:val'))
+  call assert_equal(0, map(test_null_dict(), '"> " .. v:val'))
 endfunc
 
 func Test_map_and_modify()
@@ -103,3 +109,5 @@ func Test_map_and_modify()
   call assert_fails('call map(d, "remove(d, v:key)[0]")', 'E741:')
   call assert_fails('echo map(d, {k,v -> remove(d, k)})', 'E741:')
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -99,9 +99,11 @@ func Test_len()
   call assert_equal(2, len('ab'))
 
   call assert_equal(0, len([]))
+  call assert_equal(0, len(test_null_list()))
   call assert_equal(2, len([2, 1]))
 
   call assert_equal(0, len({}))
+  call assert_equal(0, len(test_null_dict()))
   call assert_equal(2, len({'a': 1, 'b': 2}))
 
   call assert_fails('call len(v:none)', 'E701:')
@@ -799,6 +801,9 @@ func Test_append()
   split
   only
   undo
+
+  " Using $ instead of '$' must give an error
+  call assert_fails("call append($, 'foobar')", 'E116:')
 endfunc
 
 func Test_getbufvar()
@@ -2043,6 +2048,7 @@ func Test_range()
 
   " list2str()
   call assert_equal('ABC', list2str(range(65, 67)))
+  call assert_fails('let s = list2str(5)', 'E474:')
 
   " lock()
   let thelist = range(5)
@@ -2216,4 +2222,17 @@ func Test_screen_functions()
   call assert_equal([], screenchars(-1, -1))
 endfunc
 
+" Test for getcurpos() and setpos()
+func Test_getcurpos_setpos()
+  new
+  call setline(1, ['012345678', '012345678'])
+  normal gg6l
+  let sp = getcurpos()
+  normal 0
+  call setpos('.', sp)
+  normal jyl
+  call assert_equal('6', @")
+  close!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -32,6 +32,7 @@ func Test_list_slice()
   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])
+  call assert_equal([], test_null_list()[:2])
 endfunc
 
 " List identity
@@ -168,6 +169,19 @@ func Test_dict()
   call assert_equal({'c': 'ccc', '1': 99, 'b': [1, 2, function('strlen')], '3': 33, '-1': {'a': 1}}, d)
   call filter(d, 'v:key =~ ''[ac391]''')
   call assert_equal({'c': 'ccc', '1': 99, '3': 33, '-1': {'a': 1}}, d)
+
+  " duplicate key
+  call assert_fails("let d = {'k' : 10, 'k' : 20}", 'E721:')
+  " missing comma
+  call assert_fails("let d = {'k' : 10 'k' : 20}", 'E722:')
+  " missing curly brace
+  call assert_fails("let d = {'k' : 10,", 'E723:')
+  " invalid key
+  call assert_fails('let d = #{++ : 10}', 'E15:')
+  " wrong type for key
+  call assert_fails('let d={[] : 10}', 'E730:')
+  " undefined variable as value
+  call assert_fails("let d={'k' : i}", 'E121:')
 endfunc
 
 " Dictionary identity
@@ -262,7 +276,7 @@ func Test_script_local_dict_func()
   unlet g:dict
 endfunc
 
-" Test removing items in la dictionary
+" Test removing items in a dictionary
 func Test_dict_func_remove()
   let d = {1:'a', 2:'b', 3:'c'}
   call assert_equal('b', remove(d, 2))
@@ -634,6 +648,11 @@ func Test_reverse_sort_uniq()
 
   call assert_fails('call reverse("")', 'E899:')
   call assert_fails('call uniq([1, 2], {x, y -> []})', 'E882:')
+  call assert_fails("call sort([1, 2], function('min'), 1)", "E715:")
+  call assert_fails("call sort([1, 2], function('invalid_func'))", "E700:")
+  call assert_fails("call sort([1, 2], function('min'))", "E702:")
+  call assert_equal(0, sort(test_null_list()))
+  call assert_equal(0, uniq(test_null_list()))
 endfunc
 
 " splitting a string to a List using split()
@@ -748,6 +767,9 @@ func Test_listdict_extend()
 
   call assert_fails("call extend([1, 2], 1)", 'E712:')
   call assert_fails("call extend([1, 2], {})", 'E712:')
+
+  " Extend g: dictionary with an invalid variable name
+  call assert_fails("call extend(g:, {'-!' : 10})", 'E461:')
 endfunc
 
 func s:check_scope_dict(x, fixed)
@@ -871,6 +893,26 @@ func Test_listdict_index()
   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:')
+  call assert_fails("let l = insert([1,2,3], 4, 10)", 'E684:')
+  call assert_fails("let l = insert([1,2,3], 4, -10)", 'E684:')
+  call assert_fails("let l = insert([1,2,3], 4, [])", 'E745:')
+endfunc
+
+" Test for a null list
+func Test_null_list()
+  call assert_equal(0, join(test_null_list()))
+  call assert_fails('let s = join([1, 2], [])', 'E730:')
+  call assert_equal([], split(test_null_string()))
+endfunc
+
+" Test for a null dict
+func Test_null_dict()
+  call assert_equal(0, items(test_null_dict()))
+  call assert_equal(0, keys(test_null_dict()))
+  call assert_equal(0, values(test_null_dict()))
+  call assert_false(has_key(test_null_dict(), 'k'))
+  call assert_fails("let l = [] + test_null_list()", 'E15:')
+  call assert_fails("let l = test_null_list() + []", 'E15:')
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/testdir/test_sort.vim
+++ b/src/testdir/test_sort.vim
@@ -47,7 +47,7 @@ func Test_sort_default()
   call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], ''))
   call assert_equal(['2', 'A', 'AA', 'a', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], 0))
   call assert_equal(['2', 'A', 'a', 'AA', 1, 3.3], sort([3.3, 1, "2", "A", "a", "AA"], 1))
-  call assert_fails('call sort([3.3, 1, "2"], 3)', "E474")
+  call assert_fails('call sort([3.3, 1, "2"], 3)', "E474:")
 endfunc
 
 " Tests for the ":sort" command.
--- a/src/testdir/test_syntax.vim
+++ b/src/testdir/test_syntax.vim
@@ -151,6 +151,10 @@ func Test_syntax_list()
   let a = execute('syntax list')
   call assert_equal("\nNo Syntax items defined for this buffer", a)
 
+  syntax keyword Type int containedin=g1 skipwhite skipempty skipnl nextgroup=Abc
+  let exp = "Type           xxx containedin=g1  nextgroup=Abc  skipnl skipwhite skipempty int"
+  call assert_equal(exp, split(execute("syntax list"), "\n")[1])
+
   bd
 endfunc
 
--- a/src/testdir/test_utf8.vim
+++ b/src/testdir/test_utf8.vim
@@ -103,6 +103,9 @@ func Test_list2str_str2list_latin1()
   let sres = list2str(l, 1)
   call assert_equal([65, 66, 67], str2list("ABC"))
 
+  " Try converting a list to a string in latin-1 encoding
+  call assert_equal([1, 2, 3], str2list(list2str([1, 2, 3])))
+
   let &encoding = save_encoding
   call assert_equal(l, lres)
   call assert_equal(s, sres)
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -1980,6 +1980,86 @@ func Test_float_conversion_errors()
   endif
 endfunc
 
+func Test_invalid_function_names()
+  " function name not starting with capital
+  let caught_e128 = 0
+  try
+    func! g:test()
+      echo "test"
+    endfunc
+  catch /E128:/
+    let caught_e128 = 1
+  endtry
+  call assert_equal(1, caught_e128)
+
+  " function name includes a colon
+  let caught_e884 = 0
+  try
+    func! b:test()
+      echo "test"
+    endfunc
+  catch /E884:/
+    let caught_e884 = 1
+  endtry
+  call assert_equal(1, caught_e884)
+
+  " function name folowed by #
+  let caught_e128 = 0
+  try
+    func! test2() "#
+      echo "test2"
+    endfunc
+  catch /E128:/
+    let caught_e128 = 1
+  endtry
+  call assert_equal(1, caught_e128)
+
+  " function name starting with/without "g:", buffer-local funcref.
+  function! g:Foo(n)
+    return 'called Foo(' . a:n . ')'
+  endfunction
+  let b:my_func = function('Foo')
+  call assert_equal('called Foo(1)', b:my_func(1))
+  call assert_equal('called Foo(2)', g:Foo(2))
+  call assert_equal('called Foo(3)', Foo(3))
+  delfunc g:Foo
+
+  " script-local function used in Funcref must exist.
+  let lines =<< trim END
+    func s:Testje()
+      return "foo"
+    endfunc
+    let Bar = function('s:Testje')
+    call assert_equal(0, exists('s:Testje'))
+    call assert_equal(1, exists('*s:Testje'))
+    call assert_equal(1, exists('Bar'))
+    call assert_equal(1, exists('*Bar'))
+  END
+  call writefile(lines, 'Xscript')
+  source Xscript
+  call delete('Xscript')
+endfunc
+
+" substring and variable name
+func Test_substring_var()
+  let str = 'abcdef'
+  let n = 3
+  call assert_equal('def', str[n:])
+  call assert_equal('abcd', str[:n])
+  call assert_equal('d', str[n:n])
+  unlet n
+  let nn = 3
+  call assert_equal('def', str[nn:])
+  call assert_equal('abcd', str[:nn])
+  call assert_equal('d', str[nn:nn])
+  unlet nn
+  let b:nn = 4
+  call assert_equal('ef', str[b:nn:])
+  call assert_equal('abcde', str[:b:nn])
+  call assert_equal('e', str[b:nn:b:nn])
+  unlet b:nn
+endfunc
+
 "-------------------------------------------------------------------------------
 " Modelines								    {{{1
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    610,
+/**/
     609,
 /**/
     608,