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
|
2010-06-12 19:05:13 -04:00
|
|
|
amI: ->
|
2010-05-31 15:13:48 -04:00
|
|
|
@ instanceof ClassName
|
|
|
|
|
|
|
|
obj: new ClassName()
|
2010-06-12 19:05:13 -04:00
|
|
|
ok obj.amI()
|
2010-05-31 15:13:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
# 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'
|
2010-06-15 00:54:02 -04:00
|
|
|
ok maya.name is 'Maya'
|
|
|
|
|
|
|
|
|
|
|
|
# Class with JS-keyword properties.
|
|
|
|
class Class
|
|
|
|
class: 'class'
|
|
|
|
|
|
|
|
ok (new Class()).class is 'class'
|