Mercurial > vim
diff src/testdir/test_vim9_class.vim @ 34112:0f2632b04cde v9.1.0020
patch 9.1.0020: Vim9: cannot compile all methods in a class
Commit: https://github.com/vim/vim/commit/4f32c83a775a195ae7e1545b2840fb773f93414f
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Jan 12 17:36:40 2024 +0100
patch 9.1.0020: Vim9: cannot compile all methods in a class
Problem: Vim9: cannot compile all methods in a class
Solution: Support compiling all the methods in a class using :defcompile
(Yegappan Lakshmanan)
closes: #13844
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 12 Jan 2024 17:45:08 +0100 |
parents | ab6a70fad5b5 |
children | be4389b04043 |
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -9686,4 +9686,87 @@ def Test_method_double_underscore_prefix v9.CheckSourceFailure(lines, 'E1034: Cannot use reserved name __foo()', 3) enddef +" Test for compiling class/object methods using :defcompile +def Test_defcompile_class() + # defcompile all the classes in the current script + var lines =<< trim END + vim9script + class A + def Foo() + var i = 10 + enddef + endclass + class B + def Bar() + var i = 20 + xxx + enddef + endclass + defcompile + END + v9.CheckSourceFailure(lines, 'E476: Invalid command: xxx', 2) + + # defcompile a specific class + lines =<< trim END + vim9script + class A + def Foo() + xxx + enddef + endclass + class B + def Bar() + yyy + enddef + endclass + defcompile B + END + v9.CheckSourceFailure(lines, 'E476: Invalid command: yyy', 1) + + # defcompile a non-class + lines =<< trim END + vim9script + class A + def Foo() + enddef + endclass + var X: list<number> = [] + defcompile X + END + v9.CheckSourceFailure(lines, 'E1061: Cannot find function X', 7) + + # defcompile a class twice + lines =<< trim END + vim9script + class A + def new() + enddef + endclass + defcompile A + defcompile A + assert_equal('Function A.new does not need compiling', v:statusmsg) + END + v9.CheckSourceSuccess(lines) + + # defcompile should not compile an imported class + lines =<< trim END + vim9script + export class A + def Foo() + xxx + enddef + endclass + END + writefile(lines, 'Xdefcompileimport.vim', 'D') + lines =<< trim END + vim9script + + import './Xdefcompileimport.vim' + class B + endclass + defcompile + END + v9.CheckScriptSuccess(lines) +enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker