2010-04-03 10:39:32 -04:00
|
|
|
# Test classes with a four-level inheritance chain.
|
2010-02-27 18:57:45 -05:00
|
|
|
class Base
|
|
|
|
func: (string) ->
|
2010-03-29 21:43:12 -04:00
|
|
|
"zero/$string"
|
|
|
|
|
|
|
|
@static: (string) ->
|
|
|
|
"static/$string"
|
2010-02-27 18:57:45 -05:00
|
|
|
|
|
|
|
class FirstChild extends Base
|
|
|
|
func: (string) ->
|
|
|
|
super('one/') + string
|
|
|
|
|
|
|
|
class SecondChild extends FirstChild
|
|
|
|
func: (string) ->
|
|
|
|
super('two/') + string
|
|
|
|
|
|
|
|
class ThirdChild extends SecondChild
|
|
|
|
constructor: ->
|
|
|
|
@array: [1, 2, 3]
|
2010-02-27 19:03:23 -05:00
|
|
|
|
|
|
|
# Gratuitous comment for testing.
|
2010-02-27 18:57:45 -05:00
|
|
|
func: (string) ->
|
|
|
|
super('three/') + string
|
|
|
|
|
|
|
|
result: (new ThirdChild()).func 'four'
|
|
|
|
|
|
|
|
ok result is 'zero/one/two/three/four'
|
2010-03-29 21:43:12 -04:00
|
|
|
ok Base.static('word') is 'static/word'
|
2010-02-27 18:57:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
class TopClass
|
|
|
|
constructor: (arg) ->
|
|
|
|
@prop: 'top-' + arg
|
|
|
|
|
|
|
|
class SuperClass extends TopClass
|
|
|
|
constructor: (arg) ->
|
|
|
|
super 'super-' + arg
|
|
|
|
|
|
|
|
class SubClass extends SuperClass
|
|
|
|
constructor: ->
|
|
|
|
super 'sub'
|
|
|
|
|
2010-02-28 00:13:17 -05:00
|
|
|
ok (new SubClass()).prop is 'top-super-sub'
|
|
|
|
|
|
|
|
|
|
|
|
class OneClass
|
|
|
|
constructor: (name) -> @name: name
|
|
|
|
|
|
|
|
class TwoClass extends OneClass
|
|
|
|
|
2010-04-03 10:39:32 -04:00
|
|
|
ok (new TwoClass('three')).name is 'three'
|
|
|
|
|
|
|
|
|
|
|
|
# And now the same tests, but written in the manual style:
|
|
|
|
Base: ->
|
|
|
|
Base::func: (string) ->
|
|
|
|
'zero/' + string
|
2010-05-31 22:32:43 -04:00
|
|
|
Base::['func-func']: (string) ->
|
|
|
|
"dynamic-$string"
|
2010-04-03 10:39:32 -04:00
|
|
|
|
|
|
|
FirstChild: ->
|
|
|
|
FirstChild extends Base
|
|
|
|
FirstChild::func: (string) ->
|
|
|
|
super('one/') + string
|
|
|
|
|
|
|
|
SecondChild: ->
|
|
|
|
SecondChild extends FirstChild
|
|
|
|
SecondChild::func: (string) ->
|
|
|
|
super('two/') + string
|
|
|
|
|
|
|
|
ThirdChild: ->
|
|
|
|
@array: [1, 2, 3]
|
|
|
|
this
|
|
|
|
ThirdChild extends SecondChild
|
|
|
|
ThirdChild::func: (string) ->
|
|
|
|
super('three/') + string
|
|
|
|
|
|
|
|
result: (new ThirdChild()).func 'four'
|
|
|
|
|
|
|
|
ok result is 'zero/one/two/three/four'
|
|
|
|
|
2010-05-31 22:32:43 -04:00
|
|
|
ok (new ThirdChild())['func-func']('thing') is 'dynamic-thing'
|
|
|
|
|
2010-04-03 10:39:32 -04:00
|
|
|
|
|
|
|
TopClass: (arg) ->
|
|
|
|
@prop: 'top-' + arg
|
|
|
|
this
|
|
|
|
|
|
|
|
SuperClass: (arg) ->
|
|
|
|
super 'super-' + arg
|
|
|
|
this
|
|
|
|
|
|
|
|
SubClass: ->
|
|
|
|
super 'sub'
|
|
|
|
this
|
|
|
|
|
|
|
|
SuperClass extends TopClass
|
|
|
|
SubClass extends SuperClass
|
|
|
|
|
2010-05-31 15:13:48 -04:00
|
|
|
ok (new SubClass()).prop is 'top-super-sub'
|
|
|
|
|
|
|
|
|
|
|
|
# '@' referring to the current instance, and not being coerced into a call.
|
|
|
|
class ClassName
|
|
|
|
am_i: ->
|
|
|
|
@ instanceof ClassName
|
|
|
|
|
|
|
|
obj: new ClassName()
|
|
|
|
ok obj.am_i()
|
|
|
|
|
|
|
|
|
|
|
|
# super() calls in constructors of classes that are defined as object properties.
|
|
|
|
class Hive
|
|
|
|
constructor: (name) -> @name: name
|
|
|
|
|
|
|
|
class Hive.Bee extends Hive
|
|
|
|
constructor: (name) -> super name
|
|
|
|
|
|
|
|
maya: new Hive.Bee 'Maya'
|
|
|
|
ok maya.name is 'Maya'
|