add more super class specs

This commit is contained in:
leaf corcoran 2015-12-06 11:31:40 -08:00
parent 7aa63b2b61
commit 92932584b4
4 changed files with 173 additions and 119 deletions

View File

@ -121,11 +121,11 @@ do
end,
render = function(self, ...)
self:lint_check_unused()
return _class_0.__parent.render(self, ...)
return _class_0.__parent.__base.render(self, ...)
end,
block = function(self, ...)
do
local _with_0 = _class_0.__parent.block(self, ...)
local _with_0 = _class_0.__parent.__base.block(self, ...)
_with_0.block = self.block
_with_0.render = self.render
_with_0.get_root_block = self.get_root_block

View File

@ -40,61 +40,6 @@ describe "class", ->
instance = Thing "color"
assert.same instance\get_property!, "green"
it "should call super constructor", ->
class Base
new: (@property) =>
class Thing extends Base
new: (@name) =>
super "name"
instance = Thing "the_thing"
assert.same instance.property, "name"
assert.same instance.name, "the_thing"
it "should call super method", ->
class Base
_count: 111
counter: => @_count
class Thing extends Base
counter: => "%08d"\format super!
instance = Thing!
assert.same instance\counter!, "00000111"
it "should call other method from super", ->
class Base
_count: 111
counter: =>
@_count
class Thing extends Base
other_method: => super\counter!
instance = Thing!
assert.same instance\other_method!, 111
it "should get super class", ->
class Base
class Thing extends Base
get_super: => super
instance = Thing!
assert.is_true instance\get_super! == Base
it "should get a bound method from super", ->
class Base
count: 1
get_count: => @count
class Thing extends Base
get_count: => "this is wrong"
get_method: => super\get_count
instance = Thing!
assert.same instance\get_method!!, 1
it "should have class properties", ->
class Base
@ -151,6 +96,63 @@ describe "class", ->
assert.same "hello", Thing.prop
describe "super", ->
it "should call super constructor", ->
class Base
new: (@property) =>
class Thing extends Base
new: (@name) =>
super "name"
instance = Thing "the_thing"
assert.same instance.property, "name"
assert.same instance.name, "the_thing"
it "should call super method", ->
class Base
_count: 111
counter: => @_count
class Thing extends Base
counter: => "%08d"\format super!
instance = Thing!
assert.same instance\counter!, "00000111"
it "should call other method from super", ->
class Base
_count: 111
counter: =>
@_count
class Thing extends Base
other_method: => super\counter!
instance = Thing!
assert.same instance\other_method!, 111
it "should get super class", ->
class Base
class Thing extends Base
get_super: => super
instance = Thing!
assert.is_true instance\get_super! == Base
it "should get a bound method from super", ->
class Base
count: 1
get_count: => @count
class Thing extends Base
get_count: => "this is wrong"
get_method: => super\get_count
instance = Thing!
assert.same instance\get_method!!, 1
it "class properties take precedence in super class over base", ->
class Thing
@prop: "hello"
@ -234,3 +236,55 @@ describe "class", ->
i = Four!
assert.same 8, i\a!
it "should call correct class/instance super methods", ->
class Base
doit: =>
"instance"
@doit: =>
"class"
class One extends Base
doit: => super!
@doit: => super!
assert.same "instance", One!\doit!
assert.same "class", One\doit!
it "should resolve many levels of super on class methods", ->
class One
@a: =>
1
class Two extends One
class Three extends Two
@a: =>
super! + 3
class Four extends Three
@a: =>
super! + 4
assert.same 8, Four\a!
it "super should still work when method wrapped", ->
add_some = (opts) ->
=> opts.amount + opts[1] @
class Base
value: => 1
class Sub extends Base
value: add_some {
amount: 12
=>
super! + 100
}
assert.same 1 + 100 + 12, Sub!\value!

View File

@ -202,7 +202,7 @@ class Wowha extends Thing
super\hello
@butt: cool {
@zone: cool {
->
super!
super.hello

View File

@ -893,9 +893,9 @@ do
return _fn_0(self, ...)
end
end
self.butt = cool({
self.zone = cool({
function()
_class_0.__parent.butt(self)
_class_0.__parent.zone(self)
_ = _class_0.__parent.hello
_class_0.__parent.hello(self)
local _base_1 = _class_0.__parent