mirror of
https://github.com/vim/vim.git
synced 2025-10-04 05:25:06 -04:00
patch 9.0.1786: Vim9: need instanceof() function
Problem: Vim9: need instanceof() function Solution: Implement instanceof() builtin Implemented in the same form as Python's isinstance because it allows for checking multiple class types at the same time. closes: #12867 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: LemonBoy <thatlemon@gmail.com>
This commit is contained in:
committed by
Christian Brabandt
parent
1193951beb
commit
afe0466fb1
@@ -2367,6 +2367,39 @@ def Test_call_method_in_extended_class()
|
||||
v9.CheckScriptSuccess(lines)
|
||||
enddef
|
||||
|
||||
def Test_instanceof()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
|
||||
class Base1
|
||||
endclass
|
||||
|
||||
class Base2 extends Base1
|
||||
endclass
|
||||
|
||||
interface Intf1
|
||||
endinterface
|
||||
|
||||
class Mix1 implements Intf1
|
||||
endclass
|
||||
|
||||
class Base3 extends Mix1
|
||||
endclass
|
||||
|
||||
var b1 = Base1.new()
|
||||
var b2 = Base2.new()
|
||||
var b3 = Base3.new()
|
||||
|
||||
assert_true(instanceof(b1, Base1))
|
||||
assert_true(instanceof(b2, Base1))
|
||||
assert_false(instanceof(b1, Base2))
|
||||
assert_true(instanceof(b3, Mix1))
|
||||
assert_false(instanceof(b3, []))
|
||||
assert_true(instanceof(b3, [Base1, Base2, Intf1]))
|
||||
END
|
||||
v9.CheckScriptSuccess(lines)
|
||||
enddef
|
||||
|
||||
" Test for calling a method in the parent class that is extended partially.
|
||||
" This used to fail with the 'E118: Too many arguments for function: Text' error
|
||||
" message (Github issue #12524).
|
||||
|
Reference in New Issue
Block a user