From a33df4dcbe00d20de67a68532f500f71c3810208 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sat, 19 Nov 2011 22:05:18 -0500 Subject: [PATCH] [#29] Refactored interface extend() test against non-interface into ExtendTest --- lib/interface.js | 12 ++------ test/Interface/ExtendTest.js | 14 ++++++++- test/test-interface-extend-permitted.js | 39 ------------------------- 3 files changed, 15 insertions(+), 50 deletions(-) delete mode 100644 test/test-interface-extend-permitted.js diff --git a/lib/interface.js b/lib/interface.js index 5798f0a..2b005cd 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -301,17 +301,9 @@ var extend = ( function( extending ) function inheritCheck( prototype ) { // if we're inheriting from another interface, then we're good - if ( prototype instanceof Interface ) + if ( !( prototype instanceof Interface ) ) { - return; - } - - if ( Class.isClassInstance( prototype ) ) - { - throw new TypeError( - "Interfaces cannot extend from classes. Try creating an " + - "abstract class instead." - ); + throw new TypeError( "Interfaces may only extend other interfaces" ); } } diff --git a/test/Interface/ExtendTest.js b/test/Interface/ExtendTest.js index 9dbeb0a..bad2eda 100644 --- a/test/Interface/ExtendTest.js +++ b/test/Interface/ExtendTest.js @@ -23,7 +23,7 @@ */ var common = require( 'common' ), - Interface = common.require( 'interface' ); + Interface = common.require( 'interface' ), // get/set test support gst = !( common.require( 'util' ).definePropertyFallback() ) @@ -330,5 +330,17 @@ common.testCase( Interface( dfn ); }, 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" ); + }, } ); diff --git a/test/test-interface-extend-permitted.js b/test/test-interface-extend-permitted.js deleted file mode 100644 index 21de47b..0000000 --- a/test/test-interface-extend-permitted.js +++ /dev/null @@ -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 . - * - * @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" ); -