mirror of
https://github.com/vim/vim.git
synced 2025-10-03 05:14:07 -04:00
patch 9.0.1181: class inheritance and typing insufficiently tested
Problem: Class inheritance and typing insufficiently tested. Solution: Add more tests. Implement missing behavior.
This commit is contained in:
@@ -419,6 +419,44 @@ def Test_class_object_compare()
|
||||
endfor
|
||||
enddef
|
||||
|
||||
def Test_object_type()
|
||||
var lines =<< trim END
|
||||
vim9script
|
||||
|
||||
class One
|
||||
this.one = 1
|
||||
endclass
|
||||
class Two
|
||||
this.two = 2
|
||||
endclass
|
||||
class TwoMore extends Two
|
||||
this.more = 9
|
||||
endclass
|
||||
|
||||
var o: One = One.new()
|
||||
var t: Two = Two.new()
|
||||
var m: TwoMore = TwoMore.new()
|
||||
var tm: Two = TwoMore.new()
|
||||
|
||||
t = m
|
||||
END
|
||||
v9.CheckScriptSuccess(lines)
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
|
||||
class One
|
||||
this.one = 1
|
||||
endclass
|
||||
class Two
|
||||
this.two = 2
|
||||
endclass
|
||||
|
||||
var o: One = Two.new()
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object<One> but got object<Two>')
|
||||
enddef
|
||||
|
||||
def Test_class_member()
|
||||
# check access rules
|
||||
var lines =<< trim END
|
||||
@@ -750,7 +788,7 @@ def Test_class_used_as_type()
|
||||
var p: Point
|
||||
p = 'text'
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object but got string')
|
||||
v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object<Point> but got string')
|
||||
enddef
|
||||
|
||||
def Test_class_extends()
|
||||
@@ -895,6 +933,27 @@ def Test_class_extends()
|
||||
echo o.ToString()
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1358:')
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
class Base
|
||||
this.name: string
|
||||
static def ToString(): string
|
||||
return 'Base class'
|
||||
enddef
|
||||
endclass
|
||||
|
||||
class Child extends Base
|
||||
this.age: number
|
||||
def ToString(): string
|
||||
return Base.ToString() .. ': ' .. this.age
|
||||
enddef
|
||||
endclass
|
||||
|
||||
var o = Child.new('John', 42)
|
||||
assert_equal('Base class: 42', o.ToString())
|
||||
END
|
||||
v9.CheckScriptSuccess(lines)
|
||||
enddef
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user