Begin moving method wrapper tests into MethodWrappersTest (#25)
parent
24e9dd2549
commit
40d555ee3f
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* Tests method sut
|
||||
*
|
||||
* Copyright (C) 2010 Mike Gerwitz
|
||||
*
|
||||
* This file is part of ease.js.
|
||||
*
|
||||
* ease.js is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author Mike Gerwitz
|
||||
* @package test
|
||||
*/
|
||||
|
||||
var common = require( './common' ),
|
||||
assert = require( 'assert' ),
|
||||
util = common.require( 'util' )
|
||||
sut = common.require( 'MethodWrappers' )
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* If the method is called when bound to a different context (e.g. for
|
||||
* protected/private members), __super may not be properly bound.
|
||||
*
|
||||
* This test is in response to a bug found after implementing visibility
|
||||
* support. The __super() method was previously defined on 'this', which may or
|
||||
* may not be the context that is actually used. Likely, it's not.
|
||||
*/
|
||||
( function testSuperMethodWorksProperlyWhenContextDiffers()
|
||||
{
|
||||
var super_called = false,
|
||||
retobj = {},
|
||||
|
||||
getInst = function()
|
||||
{
|
||||
return retobj;
|
||||
},
|
||||
|
||||
// super method to be overridden
|
||||
method = sut.standard.wrapNew(
|
||||
function()
|
||||
{
|
||||
super_called = true;
|
||||
},
|
||||
null, 0, getInst
|
||||
)
|
||||
|
||||
// the overriding method
|
||||
override = sut.standard.wrapOverride(
|
||||
function()
|
||||
{
|
||||
this.__super();
|
||||
},
|
||||
method, 0, getInst
|
||||
)
|
||||
;
|
||||
|
||||
// call the overriding method
|
||||
override();
|
||||
|
||||
// ensure that the super method was called
|
||||
assert.equal( super_called, true,
|
||||
"__super() method is called even when context differs"
|
||||
);
|
||||
|
||||
// finally, ensure that __super is no longer set on the returned object
|
||||
// after the call to ensure that the caller cannot break encapsulation by
|
||||
// stealing a method reference (sneaky, sneaky)
|
||||
assert.equal( retobj.__super, undefined,
|
||||
"__super() method is unset after being called"
|
||||
);
|
||||
} )();
|
||||
|
|
@ -283,68 +283,6 @@ mb_common.assertCommon();
|
|||
} )();
|
||||
|
||||
|
||||
/**
|
||||
* If the method is called when bound to a different context (e.g. for
|
||||
* protected/private members), __super may not be properly bound.
|
||||
*
|
||||
* This test is in response to a bug found after implementing visibility
|
||||
* support. The __super() method was previously defined on 'this', which may or
|
||||
* may not be the context that is actually used. Likely, it's not.
|
||||
*/
|
||||
( function testSuperMethodWorksProperlyWhenContextDiffers()
|
||||
{
|
||||
var members = builder.initMembers(),
|
||||
super_called = false,
|
||||
retobj = {},
|
||||
instCallback = function()
|
||||
{
|
||||
return retobj;
|
||||
},
|
||||
|
||||
// the overriding method
|
||||
newfunc = function()
|
||||
{
|
||||
this.__super();
|
||||
}
|
||||
;
|
||||
|
||||
// super method to be overridden
|
||||
members[ 'public' ].foo = function()
|
||||
{
|
||||
super_called = true;
|
||||
};
|
||||
|
||||
// XXX: Bad idea. Set the keyword in another manner. This is likely to break
|
||||
// in the future.
|
||||
members['public'].foo.___$$keywords$$ = { 'virtual': true };
|
||||
|
||||
// override
|
||||
builder.buildMethod(
|
||||
members,
|
||||
{},
|
||||
'foo',
|
||||
newfunc,
|
||||
{ 'override': true },
|
||||
instCallback
|
||||
);
|
||||
|
||||
// call the overriding method
|
||||
members[ 'public' ].foo();
|
||||
|
||||
// ensure that the super method was called
|
||||
assert.equal( super_called, true,
|
||||
"__super() method is called even when context differs"
|
||||
);
|
||||
|
||||
// finally, ensure that __super is no longer set on the returned object
|
||||
// after the call to ensure that the caller cannot break encapsulation by
|
||||
// stealing a method reference (sneaky, sneaky)
|
||||
assert.equal( retobj.__super, undefined,
|
||||
"__super() method is unset after being called"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
/**
|
||||
* Once a concrete implementation has been defined for a method, a subtype
|
||||
* cannot make it abstract.
|
||||
|
|
Loading…
Reference in New Issue