Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 22163:b6d36f0b4f03 v8.2.1631
patch 8.2.1631: test_fails() does not check the context of the line number
Commit: https://github.com/vim/vim/commit/9bd5d879c2ecfbdbb168b090e12f4b89724a302e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 6 21:47:48 2020 +0200
patch 8.2.1631: test_fails() does not check the context of the line number
Problem: test_fails() does not check the context of the line number.
Solution: Use another argument to specify the context of the line number.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Sep 2020 22:00:03 +0200 |
parents | 4b5f7869b8c0 |
children | c512e6f57ff2 |
comparison
equal
deleted
inserted
replaced
22162:b910fd9e1190 | 22163:b6d36f0b4f03 |
---|---|
28 enddef | 28 enddef |
29 | 29 |
30 def Test_return_something() | 30 def Test_return_something() |
31 assert_equal('string', ReturnString()) | 31 assert_equal('string', ReturnString()) |
32 assert_equal(123, ReturnNumber()) | 32 assert_equal(123, ReturnNumber()) |
33 assert_fails('ReturnGlobal()', 'E1029: Expected number but got string') | 33 assert_fails('ReturnGlobal()', 'E1029: Expected number but got string', '', 1, 'ReturnGlobal') |
34 enddef | 34 enddef |
35 | 35 |
36 def Test_missing_return() | 36 def Test_missing_return() |
37 CheckDefFailure(['def Missing(): number', | 37 CheckDefFailure(['def Missing(): number', |
38 ' if g:cond', | 38 ' if g:cond', |
110 enddef | 110 enddef |
111 | 111 |
112 def Test_call_default_args() | 112 def Test_call_default_args() |
113 assert_equal('string', MyDefaultArgs()) | 113 assert_equal('string', MyDefaultArgs()) |
114 assert_equal('one', MyDefaultArgs('one')) | 114 assert_equal('one', MyDefaultArgs('one')) |
115 assert_fails('MyDefaultArgs("one", "two")', 'E118:') | 115 assert_fails('MyDefaultArgs("one", "two")', 'E118:', '', 3, 'Test_call_default_args') |
116 | 116 |
117 assert_equal('test', MyDefaultSecond('test')) | 117 assert_equal('test', MyDefaultSecond('test')) |
118 assert_equal('test', MyDefaultSecond('test', true)) | 118 assert_equal('test', MyDefaultSecond('test', true)) |
119 assert_equal('none', MyDefaultSecond('test', false)) | 119 assert_equal('none', MyDefaultSecond('test', false)) |
120 | 120 |
137 enddef | 137 enddef |
138 | 138 |
139 func Test_call_default_args_from_func() | 139 func Test_call_default_args_from_func() |
140 call assert_equal('string', MyDefaultArgs()) | 140 call assert_equal('string', MyDefaultArgs()) |
141 call assert_equal('one', MyDefaultArgs('one')) | 141 call assert_equal('one', MyDefaultArgs('one')) |
142 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:') | 142 call assert_fails('call MyDefaultArgs("one", "two")', 'E118:', '', 3, 'Test_call_default_args_from_func') |
143 endfunc | 143 endfunc |
144 | 144 |
145 def Test_nested_global_function() | 145 def Test_nested_global_function() |
146 let lines =<< trim END | 146 let lines =<< trim END |
147 vim9script | 147 vim9script |
243 endfor | 243 endfor |
244 return res | 244 return res |
245 enddef | 245 enddef |
246 | 246 |
247 def Test_call_def_varargs() | 247 def Test_call_def_varargs() |
248 assert_fails('MyDefVarargs()', 'E119:') | 248 assert_fails('MyDefVarargs()', 'E119:', '', 1, 'Test_call_def_varargs') |
249 assert_equal('one,foo', MyDefVarargs('one')) | 249 assert_equal('one,foo', MyDefVarargs('one')) |
250 assert_equal('one,two', MyDefVarargs('one', 'two')) | 250 assert_equal('one,two', MyDefVarargs('one', 'two')) |
251 assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three')) | 251 assert_equal('one,two,three', MyDefVarargs('one', 'two', 'three')) |
252 CheckDefFailure(['MyDefVarargs("one", 22)'], | 252 CheckDefFailure(['MyDefVarargs("one", 22)'], |
253 'E1013: argument 2: type mismatch, expected string but got number') | 253 'E1013: argument 2: type mismatch, expected string but got number') |
360 CheckDefFailure(['MyVarargsOnly("one", 2)'], 'E1013: argument 2: type mismatch, expected string but got number') | 360 CheckDefFailure(['MyVarargsOnly("one", 2)'], 'E1013: argument 2: type mismatch, expected string but got number') |
361 enddef | 361 enddef |
362 | 362 |
363 def Test_using_var_as_arg() | 363 def Test_using_var_as_arg() |
364 writefile(['def Func(x: number)', 'let x = 234', 'enddef', 'defcompile'], 'Xdef') | 364 writefile(['def Func(x: number)', 'let x = 234', 'enddef', 'defcompile'], 'Xdef') |
365 assert_fails('so Xdef', 'E1006:') | 365 assert_fails('so Xdef', 'E1006:', '', 1, 'Func') |
366 delete('Xdef') | 366 delete('Xdef') |
367 enddef | 367 enddef |
368 | 368 |
369 def DictArg(arg: dict<string>) | 369 def DictArg(arg: dict<string>) |
370 arg['key'] = 'value' | 370 arg['key'] = 'value' |
386 CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:') | 386 CheckScriptFailure(['def Func(arg: number)', 'arg = 3', 'enddef', 'defcompile'], 'E1090:') |
387 enddef | 387 enddef |
388 | 388 |
389 def Test_call_func_defined_later() | 389 def Test_call_func_defined_later() |
390 assert_equal('one', g:DefinedLater('one')) | 390 assert_equal('one', g:DefinedLater('one')) |
391 assert_fails('NotDefined("one")', 'E117:') | 391 assert_fails('NotDefined("one")', 'E117:', '', 2, 'Test_call_func_defined_later') |
392 enddef | 392 enddef |
393 | 393 |
394 func DefinedLater(arg) | 394 func DefinedLater(arg) |
395 return a:arg | 395 return a:arg |
396 endfunc | 396 endfunc |
397 | 397 |
398 def Test_call_funcref() | 398 def Test_call_funcref() |
399 assert_equal(3, g:SomeFunc('abc')) | 399 assert_equal(3, g:SomeFunc('abc')) |
400 assert_fails('NotAFunc()', 'E117:') # comment after call | 400 assert_fails('NotAFunc()', 'E117:', '', 2, 'Test_call_funcref') # comment after call |
401 assert_fails('g:NotAFunc()', 'E117:') | 401 assert_fails('g:NotAFunc()', 'E117:', '', 3, 'Test_call_funcref') |
402 | 402 |
403 let lines =<< trim END | 403 let lines =<< trim END |
404 vim9script | 404 vim9script |
405 def RetNumber(): number | 405 def RetNumber(): number |
406 return 123 | 406 return 123 |
522 return arg | 522 return arg |
523 enddef | 523 enddef |
524 | 524 |
525 def Test_error_in_nested_function() | 525 def Test_error_in_nested_function() |
526 # Error in called function requires unwinding the call stack. | 526 # Error in called function requires unwinding the call stack. |
527 assert_fails('FuncWithForwardCall()', 'E1096:') | 527 assert_fails('FuncWithForwardCall()', 'E1096:', 1, 'FuncWithForwardCall') |
528 enddef | 528 enddef |
529 | 529 |
530 def Test_return_type_wrong() | 530 def Test_return_type_wrong() |
531 CheckScriptFailure([ | 531 CheckScriptFailure([ |
532 'def Func(): number', | 532 'def Func(): number', |
703 var = 'asdf' | 703 var = 'asdf' |
704 enddef | 704 enddef |
705 defcompile | 705 defcompile |
706 END | 706 END |
707 writefile(lines, 'Xcall_const.vim') | 707 writefile(lines, 'Xcall_const.vim') |
708 assert_fails('source Xcall_const.vim', 'E46:') | 708 assert_fails('source Xcall_const.vim', 'E46:', '', 1, 'MyFunc') |
709 delete('Xcall_const.vim') | 709 delete('Xcall_const.vim') |
710 enddef | 710 enddef |
711 | 711 |
712 " Test that inside :function a Python function can be defined, :def is not | 712 " Test that inside :function a Python function can be defined, :def is not |
713 " recognized. | 713 " recognized. |
734 | 734 |
735 delfunc g:GoneSoon | 735 delfunc g:GoneSoon |
736 CallGoneSoon() | 736 CallGoneSoon() |
737 END | 737 END |
738 writefile(lines, 'XToDelFunc') | 738 writefile(lines, 'XToDelFunc') |
739 assert_fails('so XToDelFunc', 'E933:') | 739 assert_fails('so XToDelFunc', 'E933:', '', 1, 'CallGoneSoon') |
740 assert_fails('so XToDelFunc', 'E933:') | 740 assert_fails('so XToDelFunc', 'E933:', '', 1, 'CallGoneSoon') |
741 | 741 |
742 delete('XToDelFunc') | 742 delete('XToDelFunc') |
743 enddef | 743 enddef |
744 | 744 |
745 def Test_redef_failure() | 745 def Test_redef_failure() |
746 writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef') | 746 writefile(['def Func0(): string', 'return "Func0"', 'enddef'], 'Xdef') |
747 so Xdef | 747 so Xdef |
748 writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef') | 748 writefile(['def Func1(): string', 'return "Func1"', 'enddef'], 'Xdef') |
749 so Xdef | 749 so Xdef |
750 writefile(['def! Func0(): string', 'enddef', 'defcompile'], 'Xdef') | 750 writefile(['def! Func0(): string', 'enddef', 'defcompile'], 'Xdef') |
751 assert_fails('so Xdef', 'E1027:') | 751 assert_fails('so Xdef', 'E1027:', '', 1, 'Func0') |
752 writefile(['def Func2(): string', 'return "Func2"', 'enddef'], 'Xdef') | 752 writefile(['def Func2(): string', 'return "Func2"', 'enddef'], 'Xdef') |
753 so Xdef | 753 so Xdef |
754 delete('Xdef') | 754 delete('Xdef') |
755 | 755 |
756 assert_equal(0, g:Func0()) | 756 assert_equal(0, g:Func0()) |
822 return ceil(1.1, 2) | 822 return ceil(1.1, 2) |
823 enddef | 823 enddef |
824 defcompile | 824 defcompile |
825 END | 825 END |
826 call writefile(l, 'Xinvalidarg') | 826 call writefile(l, 'Xinvalidarg') |
827 call assert_fails('so Xinvalidarg', 'E118:') | 827 call assert_fails('so Xinvalidarg', 'E118:', '', 1, 'FArgErr') |
828 let l =<< trim END | 828 let l =<< trim END |
829 def! FArgErr(): float | 829 def! FArgErr(): float |
830 return ceil() | 830 return ceil() |
831 enddef | 831 enddef |
832 defcompile | 832 defcompile |
833 END | 833 END |
834 call writefile(l, 'Xinvalidarg') | 834 call writefile(l, 'Xinvalidarg') |
835 call assert_fails('so Xinvalidarg', 'E119:') | 835 call assert_fails('so Xinvalidarg', 'E119:', '', 1, 'FArgErr') |
836 call delete('Xinvalidarg') | 836 call delete('Xinvalidarg') |
837 endfunc | 837 endfunc |
838 | 838 |
839 let s:funcResult = 0 | 839 let s:funcResult = 0 |
840 | 840 |