MyDefaultSecond('test', false)->assert_equal('none')
CheckScriptFailure(['def Func(arg: number = asdf)', 'enddef', 'defcompile'], 'E1001:')
+ delfunc g:Func
CheckScriptFailure(['def Func(arg: number = "text")', 'enddef', 'defcompile'], 'E1013: Argument 1: type mismatch, expected number but got string')
+ delfunc g:Func
enddef
def Test_nested_function()
enddef
g:Func()->assert_equal('global')
Func()->assert_equal('local')
+ delfunc g:Func
END
CheckScriptSuccess(lines)
l[0]->assert_equal('value')
CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:')
+ delfunc! g:Func
enddef
" These argument names are reserved in legacy functions.
'return "a"',
'enddef',
'defcompile'], 'expected number but got string')
+ delfunc! g:Func
CheckScriptFailure([
'def Func(): string',
'return 1',
'enddef',
'defcompile'], 'expected string but got number')
+ delfunc! g:Func
CheckScriptFailure([
'def Func(): void',
'return "a"',
'enddef',
'defcompile'],
'E1096: Returning a value in a function without a return type')
+ delfunc! g:Func
CheckScriptFailure([
'def Func()',
'return "a"',
'enddef',
'defcompile'],
'E1096: Returning a value in a function without a return type')
+ delfunc! g:Func
CheckScriptFailure([
'def Func(): number',
'return',
'enddef',
'defcompile'], 'E1003:')
+ delfunc! g:Func
CheckScriptFailure(['def Func(): list', 'return []', 'enddef'], 'E1008:')
+ delfunc! g:Func
CheckScriptFailure(['def Func(): dict', 'return {}', 'enddef'], 'E1008:')
+ delfunc! g:Func
CheckScriptFailure(['def Func()', 'return 1'], 'E1057:')
+ delfunc! g:Func
CheckScriptFailure([
'vim9script',
v:exception->assert_match('Invalid command: invalid')
v:throwpoint->assert_match(', line 3$')
endtry
+ delfunc! g:Func
# comment lines after the start of the function
lines =<< trim END
v:exception->assert_match('Invalid command: invalid')
v:throwpoint->assert_match(', line 4$')
endtry
+ delfunc! g:Func
lines =<< trim END
vim9script
catch /E716:/
v:throwpoint->assert_match('_Func, line 3$')
endtry
+ delfunc! g:Func
delete('Xdef')
enddef
Func()
END
CheckScriptFailure(lines, 'E492:', 8)
+ delfunc! g:Func
enddef
def Test_abort_even_with_silent()
CheckDefFailure(['for i In range(5)'], 'E690:')
CheckDefFailure(['var x = 5', 'for x in range(5)'], 'E1017:')
CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef', 'defcompile'], 'E1006:')
+ delfunc! g:Func
CheckDefFailure(['for i in "text"'], 'E1012:')
CheckDefFailure(['for i in xxx'], 'E1001:')
CheckDefFailure(['endfor'], 'E588:')
'vim9script',
'command Echo echo # comment',
'command Echo # comment',
+ 'delcommand Echo',
])
CheckScriptFailure([
'vim9script',
'command Echo echo# comment',
'Echo',
], 'E121:')
+ delcommand Echo
CheckScriptFailure([
'vim9script',
'command Echo# comment',
'command Echo echo',
'command Echo# comment',
], 'E182:')
+ delcommand Echo
CheckScriptSuccess([
'vim9script',
CheckScriptSuccess([
'func Test() " comment',
'endfunc',
+ 'delfunc Test',
])
CheckScriptSuccess([
'vim9script',
" Utility functions for testing vim9 script
-" Check that "lines" inside ":def" has no error.
+" Use a different file name for each run.
+let s:sequence = 1
+
+" Check that "lines" inside a ":def" function has no error.
func CheckDefSuccess(lines)
- call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], 'Xdef')
- so Xdef
+ let fname = 'Xdef' .. s:sequence
+ let s:sequence += 1
+ call writefile(['def Func()'] + a:lines + ['enddef', 'defcompile'], fname)
+ exe 'so ' .. fname
call Func()
- call delete('Xdef')
+ delfunc! Func
+ call delete(fname)
endfunc
" Check that "lines" inside ":def" results in an "error" message.
" Add a line before and after to make it less likely that the line number is
" accidentally correct.
func CheckDefFailure(lines, error, lnum = -3)
- call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], 'Xdef')
- call assert_fails('so Xdef', a:error, a:lines, a:lnum + 1)
- call delete('Xdef')
+ let fname = 'Xdef' .. s:sequence
+ call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef', 'defcompile'], fname)
+ call assert_fails('so ' .. fname, a:error, a:lines, a:lnum + 1)
+ delfunc! Func
+ call delete(fname)
+ let s:sequence += 1
endfunc
" Check that "lines" inside ":def" results in an "error" message when executed.
" Add a line before and after to make it less likely that the line number is
" accidentally correct.
func CheckDefExecFailure(lines, error, lnum = -3)
- call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], 'Xdef')
- so Xdef
+ let fname = 'Xdef' .. s:sequence
+ let s:sequence += 1
+ call writefile(['def Func()', '# comment'] + a:lines + ['#comment', 'enddef'], fname)
+ exe 'so ' .. fname
call assert_fails('call Func()', a:error, a:lines, a:lnum + 1)
- call delete('Xdef')
+ delfunc! Func
+ call delete(fname)
endfunc
def CheckScriptFailure(lines: list<string>, error: string, lnum = -3)
- writefile(lines, 'Xdef')
- assert_fails('so Xdef', error, lines, lnum)
- delete('Xdef')
+ var fname = 'Xdef' .. s:sequence
+ s:sequence += 1
+ writefile(lines, fname)
+ assert_fails('so ' .. fname, error, lines, lnum)
+ delete(fname)
enddef
def CheckScriptSuccess(lines: list<string>)
- writefile(lines, 'Xdef')
- so Xdef
- delete('Xdef')
+ var fname = 'Xdef' .. s:sequence
+ s:sequence += 1
+ writefile(lines, fname)
+ exe 'so ' .. fname
+ delete(fname)
enddef
def CheckDefAndScriptSuccess(lines: list<string>)
CheckScriptSuccess(['vim9script'] + lines)
enddef
-" Check that a command fails both when used in a :def function and when used
-" in Vim9 script.
+" Check that a command fails with the same error when used in a :def function
+" and when used in Vim9 script.
def CheckDefAndScriptFailure(lines: list<string>, error: string, lnum = -3)
CheckDefFailure(lines, error, lnum)
CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)
enddef
-" Check that a command fails both when executed in a :def function and when
-" used in Vim9 script.
+" Check that a command fails with the same error when executed in a :def
+" function and when used in Vim9 script.
def CheckDefExecAndScriptFailure(lines: list<string>, error: string, lnum = -3)
CheckDefExecFailure(lines, error, lnum)
CheckScriptFailure(['vim9script'] + lines, error, lnum + 1)