1
0
Fork 0

[#29] Refactored interface extend() test against non-interface into ExtendTest

closure/master
Mike Gerwitz 2011-11-19 22:05:18 -05:00
parent 4fe20762c8
commit a33df4dcbe
3 changed files with 15 additions and 50 deletions

View File

@ -301,17 +301,9 @@ var extend = ( function( extending )
function inheritCheck( prototype ) function inheritCheck( prototype )
{ {
// if we're inheriting from another interface, then we're good // if we're inheriting from another interface, then we're good
if ( prototype instanceof Interface ) if ( !( prototype instanceof Interface ) )
{ {
return; throw new TypeError( "Interfaces may only extend other interfaces" );
}
if ( Class.isClassInstance( prototype ) )
{
throw new TypeError(
"Interfaces cannot extend from classes. Try creating an " +
"abstract class instead."
);
} }
} }

View File

@ -23,7 +23,7 @@
*/ */
var common = require( 'common' ), var common = require( 'common' ),
Interface = common.require( 'interface' ); Interface = common.require( 'interface' ),
// get/set test support // get/set test support
gst = !( common.require( 'util' ).definePropertyFallback() ) gst = !( common.require( 'util' ).definePropertyFallback() )
@ -330,5 +330,17 @@ common.testCase(
Interface( dfn ); Interface( dfn );
}, Error, "Interface members should not be able to be " + am ); }, Error, "Interface members should not be able to be " + am );
}, },
/**
* We only want to permit the extending of other interfaces.
*/
'Interfaces can only extend interfaces': function()
{
this.assertThrows( function()
{
Interface.extend( function() {}, {} );
}, TypeError, "Should not be able to extend from non-interface" );
},
} ); } );

View File

@ -1,39 +0,0 @@
/**
* Tests to ensure interfaces can only extend from interfaces
*
* Interface can extend from any object, so long as it only contains abstract
* methods. However, the system checks for situations that don't make sense in
* order to provide more meaningful error messages.
*
* 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' ),
Class = common.require( 'class' );
Interface = common.require( 'interface' );
assert.throws( function()
{
Interface.extend( Class.extend(), {} );
}, TypeError, "Interfaces cannot extend from classes" );