1
0
Fork 0

test-class-parent no longer relies on member visibility to succeed

- This is important for pending changes
closure/master
Mike Gerwitz 2011-03-02 07:51:18 -05:00
parent 02d0c07f98
commit 40228361a1
1 changed files with 45 additions and 40 deletions

View File

@ -26,80 +26,85 @@ var common = require( './common' ),
assert = require( 'assert' ), assert = require( 'assert' ),
Class = common.require( 'class' ); Class = common.require( 'class' );
var Foo = Class.extend( // we store these outside of the class to ensure that visibility bugs do not
{ // get in the way of our assertions
hitMethod: false, hitMethod = false,
hitMethod2: false, hitMethod2 = false,
method2Arg: null, method2Arg = null,
myMethod: function() Foo = Class.extend(
{ {
this.hitMethod = true; myMethod: function()
return this; {
}, hitMethod = true;
return this;
},
myMethod2: function( arg ) myMethod2: function( arg )
{
hitMethod2 = true;
method2Arg = arg;
return this;
},
}),
SubFoo = Foo.extend(
{ {
this.hitMethod2 = true; myMethod: function()
this.method2Arg = arg; {
return this;
},
return this; myMethod2: function( arg )
}, {
}); return this.__super( arg );
},
var SubFoo = Foo.extend( callParentAlt: function()
{ {
myMethod: function() return this.parent.myMethod2.apply( this, arguments );
{ },
return this; }),
},
myMethod2: function( arg ) foo = new Foo(),
{ sub_foo = new SubFoo()
return this.__super( arg ); ;
},
callParentAlt: function()
{
return this.parent.myMethod2.apply( this, arguments );
},
});
var foo = new Foo(),
sub_foo = new SubFoo();
// make sure we're working properly before we run the important assertions // make sure we're working properly before we run the important assertions
foo.myMethod().myMethod2(); foo.myMethod().myMethod2();
assert.equal( assert.equal(
foo.hitMethod, hitMethod,
true, true,
"Sanity check" "Sanity check"
); );
assert.equal( assert.equal(
foo.hitMethod2, hitMethod2,
true, true,
"Sanity check" "Sanity check"
); );
hitMethod = hitMethod2 = false;
var arg = 'foobar'; var arg = 'foobar';
sub_foo.myMethod().myMethod2( arg ); sub_foo.myMethod().myMethod2( arg );
// myMethod overrides without calling parent // myMethod overrides without calling parent
assert.equal( assert.equal(
sub_foo.hitMethod, hitMethod,
false, false,
"Subtype should be able to override parent properties" "Subtype should be able to override parent properties"
); );
// myMethod2 overrides parent then calls super method // myMethod2 overrides parent then calls super method
assert.equal( assert.equal(
sub_foo.hitMethod2, hitMethod2,
true, true,
"Subtype should be able to call parent method" "Subtype should be able to call parent method"
); );
assert.equal( assert.equal(
sub_foo.method2Arg, method2Arg,
arg, arg,
"Arguments should be passed to super method via _super argument list" "Arguments should be passed to super method via _super argument list"
); );
@ -112,7 +117,7 @@ assert.deepEqual(
sub_foo.callParentAlt( arg = 'moo' ); sub_foo.callParentAlt( arg = 'moo' );
assert.equal( assert.equal(
sub_foo.method2Arg, method2Arg,
arg, arg,
"The parent property may also be used to invoke parent methods" "The parent property may also be used to invoke parent methods"
); );