Skip to content

Commit

Permalink
patch 8.2.4809: various things no6 properly tested
Browse files Browse the repository at this point in the history
Problem:    Various things no6 properly tested.
Solution:   Add various test cases. (Yegappan Lakshmanan, closes #10259)
  • Loading branch information
yegappan authored and brammool committed Apr 23, 2022
1 parent 33d3ce6 commit 885de44
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 6 deletions.
25 changes: 24 additions & 1 deletion src/testdir/test_blob.vim
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func Test_blob_assign()
LET b[1 : 1] ..= 0z55
END
call v9.CheckLegacyAndVim9Failure(lines, ['E734:', 'E1183:', 'E734:'])

call assert_fails('let b = readblob("a1b2c3")', 'E484:')
endfunc

func Test_blob_get_range()
Expand Down Expand Up @@ -210,6 +212,8 @@ func Test_blob_compare()
call assert_true(b1 == b2)
call assert_false(b1 is b2)
call assert_true(b1 isnot b2)
call assert_true(0z != 0z10)
call assert_true(0z10 != 0z)
END
call v9.CheckLegacyAndVim9Success(lines)

Expand Down Expand Up @@ -266,7 +270,8 @@ func Test_blob_index_assign()
VAR b = 0z00
LET b[1] = 0x11
LET b[2] = 0x22
call assert_equal(0z001122, b)
LET b[0] = 0x33
call assert_equal(0z331122, b)
END
call v9.CheckLegacyAndVim9Success(lines)

Expand All @@ -281,6 +286,18 @@ func Test_blob_index_assign()
LET b[-2] = 0x33
END
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')

let lines =<< trim END
VAR b = 0z00010203
LET b[0 : -1] = 0z33
END
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')

let lines =<< trim END
VAR b = 0z00010203
LET b[3 : 4] = 0z3344
END
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')
endfunc

func Test_blob_for_loop()
Expand Down Expand Up @@ -426,6 +443,12 @@ func Test_blob_func_remove()
END
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')

let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(b, -10)
END
call v9.CheckLegacyAndVim9Failure(lines, 'E979:')

let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(b, 3, 2)
Expand Down
34 changes: 33 additions & 1 deletion src/testdir/test_debugger.vim
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,39 @@ func Test_Debugger_breakadd()
call assert_fails('breakadd file Xtest.vim /\)/', 'E55:')
endfunc

def Test_Debugger_breakadd_expr()
" Test for expression breakpoint set using ":breakadd expr <expr>"
func Test_Debugger_breakadd_expr()
let lines =<< trim END
let g:Xtest_var += 1
END
call writefile(lines, 'Xtest.vim')

" Start Vim in a terminal
let buf = RunVimInTerminal('Xtest.vim', {})
call RunDbgCmd(buf, ':let g:Xtest_var = 10')
call RunDbgCmd(buf, ':breakadd expr g:Xtest_var')
call RunDbgCmd(buf, ':source %')
let expected =<< eval trim END
Oldval = "10"
Newval = "11"
`=fnamemodify('Xtest.vim', ':p')`
line 1: let g:Xtest_var += 1
END
call RunDbgCmd(buf, ':source %', expected)
call RunDbgCmd(buf, 'cont')
let expected =<< eval trim END
Oldval = "11"
Newval = "12"
`=fnamemodify('Xtest.vim', ':p')`
line 1: let g:Xtest_var += 1
END
call RunDbgCmd(buf, ':source %', expected)

call StopVimInTerminal(buf)
call delete('Xtest.vim')
endfunc

def Test_Debugger_breakadd_vim9_expr()
var lines =<< trim END
vim9script
func g:EarlyFunc()
Expand Down
5 changes: 3 additions & 2 deletions src/testdir/test_listdict.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ func Test_reduce()

call assert_fails("call reduce([], { acc, val -> acc + val })", 'E998: Reduce of an empty List with no initial value')
call assert_fails("call reduce(0z, { acc, val -> acc + val })", 'E998: Reduce of an empty Blob with no initial value')
call assert_fails("call reduce(test_null_blob(), { acc, val -> acc + val })", 'E998: Reduce of an empty Blob with no initial value')
call assert_fails("call reduce('', { acc, val -> acc + val })", 'E998: Reduce of an empty String with no initial value')
call assert_fails("call reduce(test_null_string(), { acc, val -> acc + val })", 'E998: Reduce of an empty String with no initial value')

Expand All @@ -1034,8 +1035,8 @@ func Test_reduce()
call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1253:')
call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1253:')
call assert_fails("call reduce('abc', { a, v -> a10}, '')", 'E121:')
call assert_fails("call reduce(0z01, { a, v -> a10}, 1)", 'E121:')
call assert_fails("call reduce([1], { a, v -> a10}, '')", 'E121:')
call assert_fails("call reduce(0z0102, { a, v -> a10}, 1)", 'E121:')
call assert_fails("call reduce([1, 2], { a, v -> a10}, '')", 'E121:')

let g:lut = [1, 2, 3, 4]
func EvilRemove()
Expand Down
23 changes: 23 additions & 0 deletions src/testdir/test_vim9_builtin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1273,56 +1273,79 @@ def Test_float_funcs_args()

# acos()
v9.CheckDefAndScriptFailure(['acos("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('1.570796', string(acos(0.0)))
# asin()
v9.CheckDefAndScriptFailure(['asin("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(asin(0.0)))
# atan()
v9.CheckDefAndScriptFailure(['atan("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(atan(0.0)))
# atan2()
v9.CheckDefAndScriptFailure(['atan2("a", 1.1)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('-2.356194', string(atan2(-1, -1)))
v9.CheckDefAndScriptFailure(['atan2(1.2, "a")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 2'])
v9.CheckDefAndScriptFailure(['atan2(1.2)'], ['E119:', 'E119:'])
# ceil()
v9.CheckDefAndScriptFailure(['ceil("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('2.0', string(ceil(2.0)))
# cos()
v9.CheckDefAndScriptFailure(['cos("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('1.0', string(cos(0.0)))
# cosh()
v9.CheckDefAndScriptFailure(['cosh("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('1.0', string(cosh(0.0)))
# exp()
v9.CheckDefAndScriptFailure(['exp("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('1.0', string(exp(0.0)))
# float2nr()
v9.CheckDefAndScriptFailure(['float2nr("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal(1, float2nr(1.234))
# floor()
v9.CheckDefAndScriptFailure(['floor("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('2.0', string(floor(2.0)))
# fmod()
v9.CheckDefAndScriptFailure(['fmod(1.1, "a")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 2'])
v9.CheckDefAndScriptFailure(['fmod("a", 1.1)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
v9.CheckDefAndScriptFailure(['fmod(1.1)'], ['E119:', 'E119:'])
assert_equal('0.13', string(fmod(12.33, 1.22)))
# isinf()
v9.CheckDefAndScriptFailure(['isinf("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal(1, isinf(1.0 / 0.0))
# isnan()
v9.CheckDefAndScriptFailure(['isnan("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_true(isnan(0.0 / 0.0))
# log()
v9.CheckDefAndScriptFailure(['log("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(log(1.0)))
# log10()
v9.CheckDefAndScriptFailure(['log10("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(log10(1.0)))
# pow()
v9.CheckDefAndScriptFailure(['pow("a", 1.1)'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
v9.CheckDefAndScriptFailure(['pow(1.1, "a")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 2'])
v9.CheckDefAndScriptFailure(['pow(1.1)'], ['E119:', 'E119:'])
assert_equal('1.0', string(pow(0.0, 0.0)))
# round()
v9.CheckDefAndScriptFailure(['round("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('2.0', string(round(2.1)))
# sin()
v9.CheckDefAndScriptFailure(['sin("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(sin(0.0)))
# sinh()
v9.CheckDefAndScriptFailure(['sinh("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(sinh(0.0)))
# sqrt()
v9.CheckDefAndScriptFailure(['sqrt("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(sqrt(0.0)))
# tan()
v9.CheckDefAndScriptFailure(['tan("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(tan(0.0)))
# tanh()
v9.CheckDefAndScriptFailure(['tanh("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('0.0', string(tanh(0.0)))
# trunc()
v9.CheckDefAndScriptFailure(['trunc("a")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1219: Float or Number required for argument 1'])
assert_equal('2.0', string(trunc(2.1)))
enddef

def Test_fnameescape()
Expand Down
28 changes: 26 additions & 2 deletions src/testdir/test_vim9_import.vim
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,6 @@ def Test_import_fails()
END
v9.CheckScriptFailure(lines, 'E1047:')

delete('Xfoo.vim')

lines =<< trim END
vim9script
def TheFunc()
Expand Down Expand Up @@ -576,7 +574,26 @@ def Test_import_fails()
END
v9.CheckScriptSuccess(lines)

new
setline(1, ['vim9script', 'import "" as abc'])
assert_fails('source', 'E1071: Invalid string for :import: "" as abc')
setline(2, 'import [] as abc')
assert_fails('source', 'E1071: Invalid string for :import: [] as abc')
setline(2, 'import test_null_string() as abc')
assert_fails('source', 'E1071: Invalid string for :import: test_null_string() as abc')
bw!
call writefile(['vim9script', "import './Xfoo.vim' ask expo"], 'Xbar.vim')
assert_fails('source Xbar.vim', 'E488: Trailing characters: ask expo')
writefile([], 'Xtemp')
call writefile(['vim9script', "import './Xtemp'"], 'Xbar.vim')
assert_fails('source Xbar.vim', 'E1257: Imported script must use "as" or end in .vim: Xtemp')
delete('Xtemp')
call writefile(['vim9script', "import './Xfoo.vim' as abc | foobar"], 'Xbar.vim')
assert_fails('source Xbar.vim', 'E492: Not an editor command: foobar')
call delete('Xbar.vim')

delete('Ximport', 'rf')
delete('Xfoo.vim')
enddef

func g:Trigger()
Expand Down Expand Up @@ -1404,6 +1421,7 @@ def Test_export_fails()
v9.CheckScriptFailure(['export var some = 123'], 'E1042:')
v9.CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
v9.CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')
v9.CheckScriptFailure(['vim9script', 'export function /a1b2c3'], 'E1044:')

assert_fails('export something', 'E1043:')
enddef
Expand Down Expand Up @@ -2646,6 +2664,12 @@ def Test_vim9script_autoload_fails()
var n = 0
END
v9.CheckScriptFailure(lines, 'E983: Duplicate argument: noclear')

lines =<< trim END
vim9script noclears
var n = 0
END
v9.CheckScriptFailure(lines, 'E475: Invalid argument: noclears')
enddef

def Test_import_autoload_fails()
Expand Down
10 changes: 10 additions & 0 deletions src/testdir/test_vim9_script.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3779,6 +3779,16 @@ def Test_unsupported_commands()
END
v9.CheckDefAndScriptFailure(lines, ['E476:', 'E492:'])

lines =<< trim END
:k a
END
v9.CheckDefAndScriptFailure(lines, 'E1100:')

lines =<< trim END
:1k a
END
v9.CheckDefAndScriptFailure(lines, 'E481:')

lines =<< trim END
t
END
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4809,
/**/
4808,
/**/
Expand Down

0 comments on commit 885de44

Please sign in to comment.