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,59 +68,97 @@ var ConcreteFoo = AbstractFoo.extend(
}); });
assert.ok( /**
( Foo.isAbstract instanceof Function ), * All classes should have a method to determine if they are abstract.
*/
( function testAllClassesHaveAMethodToDetmineIfAbstract()
{
assert.ok(
( Class( {} ).isAbstract instanceof Function ),
"All classes should have an isAbstract() method" "All classes should have an isAbstract() method"
); );
} )();
assert.equal(
Foo.isAbstract(), ( function testClassesAreNotConsideredToBeAbstractIfTheyHaveNoAbstractMethods()
{
assert.equal(
Class( {} ).isAbstract(),
false, false,
"Classes are not abstract if they contain no abstract methods" "Classes are not abstract if they contain no abstract methods"
); );
} )();
assert.equal(
( function testClassesShouldBeConsideredAbstractIfTheyContainAbstractMethods()
{
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"
); );
} )();
assert.equal(
( function testSubtypesAreAbstractIfNoConcreteMethodIsProvided()
{
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"
); );
} )();
assert.equal(
( function testSubtypesAreNotConisderedAbstractIfConcreteImplIsProvided()
{
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"
); );
} )();
assert.throws( function()
( function testAbstractClassesCannotBeInstantiated()
{ {
new AbstractFoo(); assert.throws( function()
new SubAbstractFoo(); {
}, Error, "Abstract classes cannot be instantiated" ); // both should fail
AbstractFoo();
SubAbstractFoo();
}, Error, "Abstract classes cannot be instantiated" );
} )();
assert.ok(
new ConcreteFoo(), ( function testConcreteSubclassesCanBeInstantiated()
{
assert.ok(
ConcreteFoo(),
"Concrete subclasses can be instantiated" "Concrete subclasses can be instantiated"
); );
} )();
ctor_called = false;
new ConcreteFoo(); ( function testCanCallConstructorsOfAbstractSupertypes()
assert.equal( {
ctor_called = false;
ConcreteFoo();
assert.equal(
ctor_called, ctor_called,
true, true,
"Can call constructors of abstract supertypes" "Can call constructors of abstract supertypes"
); );
} )();
assert.throws( function() ( function testConcreteMethodsMustImplementTheProperNumberOfArguments()
{ {
assert.throws( function()
{
AbstractFoo.extend( AbstractFoo.extend(
{ {
// incorrect number of arguments // incorrect number of arguments
@ -128,9 +166,13 @@ assert.throws( function()
{ {
}, },
}); });
}, Error, "Concrete methods must implement the proper number of argments" ); }, Error, "Concrete methods must implement the proper number of argments" );
} )();
assert.throws(
( function testAbstractMethodsOfSubtypesMustImplementProperNumberOfArguments()
{
assert.throws(
function() function()
{ {
AbstractFoo.extend( AbstractFoo.extend(
@ -140,10 +182,15 @@ 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"
);
} )();
assert.doesNotThrow(
( function testAbstractMembersMayImplementMoreArgumentsThanSupertype()
{
assert.doesNotThrow(
function() function()
{ {
AbstractFoo.extend( AbstractFoo.extend(
@ -153,12 +200,16 @@ 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"
); );
} )();
assert.doesNotThrow(
( function testConcreteMethodsHaveNoArgumentRequirementsIfNoDefinitionGiven()
{
assert.doesNotThrow(
function() function()
{ {
AbstractFoo.extend( AbstractFoo.extend(
@ -169,19 +220,23 @@ 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"
); );
} )();
assert.throws( function() ( function testAbstractMethodsMustBeDeclaredAsArrays()
{ {
assert.throws( function()
{
Class.extend( Class.extend(
{ {
// not an array (invalid) // not an array (invalid)
'abstract foo': 'scalar', 'abstract foo': 'scalar',
} ); } );
}, TypeError, "Abstract methods must be declared as arrays" ); }, TypeError, "Abstract methods must be declared as arrays" );
} )();
/** /**