2011-07-06 19:34:35 -04:00
|
|
|
/**
|
|
|
|
* Tests hidden methods
|
|
|
|
*
|
|
|
|
* 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' ),
|
|
|
|
warn = common.require( 'warn' )
|
2011-08-31 00:24:19 -04:00
|
|
|
|
|
|
|
// XXX: get rid of this disgusting mess; we're mid-refactor and all these
|
|
|
|
// dependencies should not be necessary for testing
|
|
|
|
ClassBuilder = common.require( '/ClassBuilder' ),
|
|
|
|
MethodWrapperFactory = common.require( '/MethodWrapperFactory' ),
|
|
|
|
wrappers = common.require( '/MethodWrappers' ).standard,
|
|
|
|
|
|
|
|
builder = ClassBuilder(
|
|
|
|
common.require( '/MemberBuilder' )(
|
|
|
|
MethodWrapperFactory( wrappers.wrapNew ),
|
|
|
|
MethodWrapperFactory( wrappers.wrapOverride )
|
|
|
|
),
|
|
|
|
common.require( '/VisibilityObjectFactoryFactory' ).fromEnvironment()
|
2011-08-09 17:27:26 -04:00
|
|
|
)
|
2011-07-06 19:34:35 -04:00
|
|
|
;
|
|
|
|
|
2011-10-22 13:57:17 -04:00
|
|
|
// XXX: Disabled until we begin re-development of this feature
|
|
|
|
return;
|
|
|
|
|
2011-07-06 19:34:35 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores warning handler to the default
|
|
|
|
*/
|
|
|
|
function restoreWarningHandler()
|
|
|
|
{
|
|
|
|
warn.setHandler( warn.handlers.log );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If a non-virtual method is implicitly hidden (redefined without the 'new'
|
|
|
|
* keyword), a warning should be provided. This will ensure that, should a
|
2011-08-03 22:40:55 -04:00
|
|
|
* parent introduce a method that is already defined by a subtype, the
|
2011-07-06 19:34:35 -04:00
|
|
|
* developer of the subtype is made aware of the issue.
|
|
|
|
*/
|
2011-08-03 22:40:55 -04:00
|
|
|
( function testThrowsWarningWhenHidingNonVirtualSuperMethod()
|
2011-07-06 19:34:35 -04:00
|
|
|
{
|
|
|
|
var thrown = false;
|
|
|
|
|
|
|
|
// mock the warning handler to ensure a warning is thrown
|
|
|
|
warn.setHandler( function( e )
|
|
|
|
{
|
|
|
|
thrown = true;
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
( e.message.search( 'foo' ) !== -1 ),
|
2011-08-03 22:40:55 -04:00
|
|
|
"Non-virtual method hiding warning should contain method name"
|
2011-07-06 19:34:35 -04:00
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
var Foo = builder.build(
|
|
|
|
{
|
|
|
|
// non-virtual method
|
|
|
|
'public foo': function() {},
|
|
|
|
} );
|
|
|
|
|
2011-08-03 22:40:55 -04:00
|
|
|
// implicitly hide the non-virtual method
|
2011-07-06 19:34:35 -04:00
|
|
|
builder.build( Foo,
|
|
|
|
{
|
|
|
|
'public foo': function() {},
|
|
|
|
} );
|
|
|
|
|
2011-08-03 22:40:55 -04:00
|
|
|
assert.equal( thrown, true,
|
|
|
|
"No warning for implicit non-virtual hiding was thrown"
|
|
|
|
);
|
|
|
|
} )();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Same concept as above. The API of the supertype could just as easily be
|
|
|
|
* changed to include a virtual method that has already been implemented by the
|
|
|
|
* subtype. The default behavior is to hide the method of the supertype.
|
|
|
|
*/
|
|
|
|
( function testThrowsWarningWhenHidingVirtualSuperMethod()
|
|
|
|
{
|
|
|
|
var thrown = false;
|
|
|
|
|
|
|
|
// mock the warning handler to ensure a warning is thrown
|
|
|
|
warn.setHandler( function( e )
|
|
|
|
{
|
|
|
|
thrown = true;
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
( e.message.search( 'foo' ) !== -1 ),
|
|
|
|
"Virtual method hiding warning should contain method name"
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
var Foo = builder.build(
|
|
|
|
{
|
|
|
|
'virtual public foo': function() {},
|
|
|
|
} );
|
|
|
|
|
|
|
|
// implicitly hide the virtual method
|
|
|
|
builder.build( Foo,
|
|
|
|
{
|
|
|
|
'public foo': function() {},
|
|
|
|
} );
|
|
|
|
|
|
|
|
assert.equal( thrown, true,
|
|
|
|
"No warning for implicit virtual hiding was thrown"
|
|
|
|
);
|
2011-07-06 19:34:35 -04:00
|
|
|
} )();
|
|
|
|
|
|
|
|
|
|
|
|
// important, otherwise tests in combined file may fail
|
|
|
|
restoreWarningHandler();
|
|
|
|
|