Skip to content

Commit 611728f

Browse files
yegappanbrammool
authored andcommitted
patch 8.2.2881: 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 #8245)
1 parent ad5c178 commit 611728f

8 files changed

Lines changed: 49 additions & 2 deletions

File tree

src/testdir/test_const.vim

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,28 @@ func Test_lockvar()
223223
call add(val, 4)
224224
call assert_equal([9, 2, 3, 4], val)
225225
call assert_fails('let val = [4, 5, 6]', 'E1122:')
226-
endfunc
227226

227+
let l =<< trim END
228+
let d = {}
229+
lockvar d
230+
func d.fn()
231+
return 1
232+
endfunc
233+
END
234+
let @a = l->join("\n")
235+
call assert_fails('exe @a', 'E741:')
236+
237+
let l =<< trim END
238+
let d = {}
239+
let d.fn = function("min")
240+
lockvar d.fn
241+
func! d.fn()
242+
return 1
243+
endfunc
244+
END
245+
let @a = l->join("\n")
246+
call assert_fails('exe @a', 'E741:')
247+
endfunc
228248

229249
func Test_const_with_index_access()
230250
let l = [1, 2, 3]

src/testdir/test_functions.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,10 @@ func Test_func_exists_on_reload()
18431843
call writefile(['func ExistingFunction()', 'echo "yes"', 'endfunc'], 'Xfuncexists2')
18441844
call assert_fails('source Xfuncexists2', 'E122:')
18451845

1846+
" Defining a new function from the cmdline should fail if the function is
1847+
" already defined
1848+
call assert_fails('call feedkeys(":func ExistingFunction()\<CR>", "xt")', 'E122:')
1849+
18461850
delfunc ExistingFunction
18471851
call assert_equal(0, exists('*ExistingFunction'))
18481852
call writefile([

src/testdir/test_python2.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ func Test_python_window()
314314
10new
315315
py vim.current.window.height = 5
316316
call assert_equal(5, winheight(0))
317+
py vim.current.window.height = 3.2
318+
call assert_equal(3, winheight(0))
317319

318320
" Test for setting the window width
319321
10vnew

src/testdir/test_python3.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ func Test_python3_window()
511511
10new
512512
py3 vim.current.window.height = 5
513513
call assert_equal(5, winheight(0))
514+
py3 vim.current.window.height = 3.2
515+
call assert_equal(3, winheight(0))
514516

515517
" Test for setting the window width
516518
10vnew

src/testdir/test_user_func.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ func Test_func_def_error()
405405
let l = join(lines, "\n") . "\n"
406406
exe l
407407
call assert_fails('exe l', 'E717:')
408+
call assert_fails('call feedkeys(":func d.F1()\<CR>", "xt")', 'E717:')
408409

409410
" Define an autoload function with an incorrect file name
410411
call writefile(['func foo#Bar()', 'return 1', 'endfunc'], 'Xscript')
@@ -420,6 +421,11 @@ func Test_del_func()
420421
call assert_fails('delfunction Xabc', 'E130:')
421422
let d = {'a' : 10}
422423
call assert_fails('delfunc d.a', 'E718:')
424+
func d.fn()
425+
return 1
426+
endfunc
427+
delfunc d.fn
428+
call assert_equal({'a' : 10}, d)
423429
endfunc
424430

425431
" Test for calling return outside of a function
@@ -451,11 +457,12 @@ func Test_func_dict()
451457
return len(self)
452458
endfunc
453459

454-
call assert_equal("{'a': 'b', 'somefunc': function('2')}", string(mydict))
460+
call assert_equal("{'a': 'b', 'somefunc': function('3')}", string(mydict))
455461
call assert_equal(2, mydict.somefunc())
456462
call assert_match("^\n function \\d\\\+() dict"
457463
\ .. "\n1 return len(self)"
458464
\ .. "\n endfunction$", execute('func mydict.somefunc'))
465+
call assert_fails('call mydict.nonexist()', 'E716:')
459466
endfunc
460467

461468
func Test_func_range()

src/testdir/test_vim9_expr.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,9 @@ def Test_expr7_lambda()
19411941
CheckDefAndScriptFailure(["var Ref = (a)=>a + 1"], 'E1004:')
19421942
CheckDefAndScriptFailure(["var Ref = (a)=> a + 1"], 'E1004: White space required before and after ''=>'' at "=> a + 1"')
19431943
CheckDefAndScriptFailure(["var Ref = (a) =>a + 1"], 'E1004:')
1944+
CheckDefAndScriptFailure2(["var Ref = (a) =< a + 1"], 'E1001:', 'E121:')
1945+
CheckDefAndScriptFailure(["var Ref = (a: int) => a + 1"], 'E1010:')
1946+
CheckDefAndScriptFailure(["var Ref = (a): int => a + 1"], 'E1010:')
19441947

19451948
CheckDefAndScriptFailure(["filter([1, 2], (k,v) => 1)"], 'E1069:', 1)
19461949
# error is in first line of the lambda

src/testdir/test_vim9_func.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,12 @@ def Test_lambda_return_type()
887887
END
888888
CheckDefAndScriptFailure(lines, 'E1157:', 1)
889889

890+
# no space before the return type
891+
lines =<< trim END
892+
var Ref = (x):number => x + 1
893+
END
894+
CheckDefAndScriptFailure(lines, 'E1069:', 1)
895+
890896
# this works
891897
for x in ['foo', 'boo']
892898
echo FilterWithCond(x, (v) => v =~ '^b')
@@ -1318,6 +1324,7 @@ def Test_white_space_before_comma()
13181324
enddef
13191325
END
13201326
CheckScriptFailure(lines, 'E1068:')
1327+
call assert_fails('vim9cmd echo stridx("a" .. "b" , "a")', 'E1068:')
13211328
enddef
13221329

13231330
def Test_white_space_after_comma()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2881,
753755
/**/
754756
2880,
755757
/**/

0 commit comments

Comments
 (0)