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,86 +96,195 @@ describe "class", ->
assert.same "hello", Thing.prop
it "class properties take precedence in super class over base", ->
class Thing
@prop: "hello"
prop: "world"
describe "super", ->
it "should call super constructor", ->
class Base
new: (@property) =>
class OtherThing extends Thing
class Thing extends Base
new: (@name) =>
super "name"
assert.same "hello", OtherThing.prop
instance = Thing "the_thing"
it "gets value from base in super class", ->
class Thing
prop: "world"
assert.same instance.property, "name"
assert.same instance.name, "the_thing"
class OtherThing extends Thing
assert.same "world", OtherThing.prop
it "should call super method", ->
class Base
_count: 111
counter: => @_count
it "should let parent be replaced on class", ->
class A
@prop: "yeah"
cool: => 1234
plain: => "a"
class Thing extends Base
counter: => "%08d"\format super!
class B
@prop: "okay"
cool: => 9999
plain: => "b"
instance = Thing!
assert.same instance\counter!, "00000111"
class Thing extends A
cool: =>
super! + 1
it "should call other method from super", ->
class Base
_count: 111
counter: =>
@_count
get_super: =>
super
class Thing extends Base
other_method: => super\counter!
instance = Thing!
instance = Thing!
assert.same instance\other_method!, 111
assert.same "a", instance\plain!
assert.same 1235, instance\cool!
assert A == instance\get_super!, "expected super to be B"
it "should get super class", ->
class Base
class Thing extends Base
get_super: => super
Thing.__parent = B
setmetatable Thing.__base, B.__base
instance = Thing!
assert.is_true instance\get_super! == Base
assert.same "b", instance\plain!
assert.same 10000, instance\cool!
assert B == instance\get_super!, "expected super to be B"
it "should get a bound method from super", ->
class Base
count: 1
get_count: => @count
it "should resolve many levels of super", ->
class One
a: =>
1
class Thing extends Base
get_count: => "this is wrong"
get_method: => super\get_count
class Two extends One
a: =>
super! + 2
instance = Thing!
assert.same instance\get_method!!, 1
class Three extends Two
a: =>
super! + 3
it "class properties take precedence in super class over base", ->
class Thing
@prop: "hello"
prop: "world"
i = Three!
class OtherThing extends Thing
assert.same 6, i\a!
assert.same "hello", OtherThing.prop
it "gets value from base in super class", ->
class Thing
prop: "world"
class OtherThing extends Thing
assert.same "world", OtherThing.prop
it "should let parent be replaced on class", ->
class A
@prop: "yeah"
cool: => 1234
plain: => "a"
class B
@prop: "okay"
cool: => 9999
plain: => "b"
class Thing extends A
cool: =>
super! + 1
get_super: =>
super
instance = Thing!
assert.same "a", instance\plain!
assert.same 1235, instance\cool!
assert A == instance\get_super!, "expected super to be B"
Thing.__parent = B
setmetatable Thing.__base, B.__base
assert.same "b", instance\plain!
assert.same 10000, instance\cool!
assert B == instance\get_super!, "expected super to be B"
it "should resolve many levels of super", ->
class One
a: =>
1
class Two extends One
a: =>
super! + 2
class Three extends Two
a: =>
super! + 3
i = Three!
assert.same 6, i\a!
it "should resolve many levels of super with a gap", ->
class One
a: =>
1
it "should resolve many levels of super with a gap", ->
class One
a: =>
1
class Two extends One
class Two extends One
class Three extends Two
a: =>
super! + 3
class Three extends Two
a: =>
super! + 3
class Four extends Three
a: =>
super! + 4
class Four extends Three
a: =>
super! + 4
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!
i = Four!
assert.same 8, i\a!

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