1
0
Fork 0

Reorganized abstract tests

closure/master
Mike Gerwitz 2011-05-22 11:33:11 -04:00
parent b359906aa3
commit 623c3df429
1 changed files with 152 additions and 97 deletions

View File

@ -68,57 +68,95 @@ var ConcreteFoo = AbstractFoo.extend(
}); });
/**
* All classes should have a method to determine if they are abstract.
*/
( function testAllClassesHaveAMethodToDetmineIfAbstract()
{
assert.ok( assert.ok(
( Foo.isAbstract instanceof Function ), ( Class( {} ).isAbstract instanceof Function ),
"All classes should have an isAbstract() method" "All classes should have an isAbstract() method"
); );
} )();
( function testClassesAreNotConsideredToBeAbstractIfTheyHaveNoAbstractMethods()
{
assert.equal( assert.equal(
Foo.isAbstract(), Class( {} ).isAbstract(),
false, false,
"Classes are not abstract if they contain no abstract methods" "Classes are not abstract if they contain no abstract methods"
); );
} )();
( function testClassesShouldBeConsideredAbstractIfTheyContainAbstractMethods()
{
assert.equal( assert.equal(
AbstractFoo.isAbstract(), AbstractFoo.isAbstract(),
true, true,
"Classes should be considered abstract if they contain any abstract methods" "Classes should be considered abstract if they contain any abstract methods"
); );
} )();
( function testSubtypesAreAbstractIfNoConcreteMethodIsProvided()
{
assert.equal( assert.equal(
SubAbstractFoo.isAbstract(), SubAbstractFoo.isAbstract(),
true, true,
"Subtypes of abstract types are abstract if they don't provide a " + "Subtypes of abstract types are abstract if they don't provide a " +
"concrete implementation for all abstract methods" "concrete implementation for all abstract methods"
); );
} )();
( function testSubtypesAreNotConisderedAbstractIfConcreteImplIsProvided()
{
assert.equal( assert.equal(
ConcreteFoo.isAbstract(), ConcreteFoo.isAbstract(),
false, false,
"Subtypes of abstract types are not abstract if they provide concrete " + "Subtypes of abstract types are not abstract if they provide concrete " +
"implementations of all abstract methods" "implementations of all abstract methods"
); );
} )();
( function testAbstractClassesCannotBeInstantiated()
{
assert.throws( function() assert.throws( function()
{ {
new AbstractFoo(); // both should fail
new SubAbstractFoo(); AbstractFoo();
SubAbstractFoo();
}, Error, "Abstract classes cannot be instantiated" ); }, Error, "Abstract classes cannot be instantiated" );
} )();
( function testConcreteSubclassesCanBeInstantiated()
{
assert.ok( assert.ok(
new ConcreteFoo(), ConcreteFoo(),
"Concrete subclasses can be instantiated" "Concrete subclasses can be instantiated"
); );
} )();
( function testCanCallConstructorsOfAbstractSupertypes()
{
ctor_called = false; ctor_called = false;
new ConcreteFoo(); ConcreteFoo();
assert.equal( assert.equal(
ctor_called, ctor_called,
true, true,
"Can call constructors of abstract supertypes" "Can call constructors of abstract supertypes"
); );
} )();
( function testConcreteMethodsMustImplementTheProperNumberOfArguments()
{
assert.throws( function() assert.throws( function()
{ {
AbstractFoo.extend( AbstractFoo.extend(
@ -129,7 +167,11 @@ assert.throws( function()
}, },
}); });
}, Error, "Concrete methods must implement the proper number of argments" ); }, Error, "Concrete methods must implement the proper number of argments" );
} )();
( function testAbstractMethodsOfSubtypesMustImplementProperNumberOfArguments()
{
assert.throws( assert.throws(
function() function()
{ {
@ -140,9 +182,14 @@ assert.throws(
}); });
}, },
TypeError, TypeError,
"Abstract methods of subtypes must implement the proper number of argments" "Abstract methods of subtypes must implement the proper number of " +
"argments"
); );
} )();
( function testAbstractMembersMayImplementMoreArgumentsThanSupertype()
{
assert.doesNotThrow( assert.doesNotThrow(
function() function()
{ {
@ -153,11 +200,15 @@ assert.doesNotThrow(
}); });
}, },
Error, Error,
"Abstract methods of subtypes may implement additional arguments, so long" + "Abstract methods of subtypes may implement additional arguments, " +
"as they implement at least the required number of arguments as defined by " + "so long as they implement at least the required number of " +
"it supertype" "arguments as defined by it supertype"
); );
} )();
( function testConcreteMethodsHaveNoArgumentRequirementsIfNoDefinitionGiven()
{
assert.doesNotThrow( assert.doesNotThrow(
function() function()
{ {
@ -169,11 +220,14 @@ assert.doesNotThrow(
}); });
}, },
Error, Error,
"Concrete methods needn't implement the proper number of arguments if " + "Concrete methods needn't implement the proper number of arguments " +
"no definition was provided" "if no definition was provided"
); );
} )();
( function testAbstractMethodsMustBeDeclaredAsArrays()
{
assert.throws( function() assert.throws( function()
{ {
Class.extend( Class.extend(
@ -182,6 +236,7 @@ assert.throws( function()
'abstract foo': 'scalar', 'abstract foo': 'scalar',
} ); } );
}, TypeError, "Abstract methods must be declared as arrays" ); }, TypeError, "Abstract methods must be declared as arrays" );
} )();
/** /**