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"
);
);
} )();
assert.equal(
Foo.isAbstract(),
( function testClassesAreNotConsideredToBeAbstractIfTheyHaveNoAbstractMethods()
{
assert.equal(
Class( {} ).isAbstract(),
false,
"Classes are not abstract if they contain no abstract methods"
);
);
} )();
assert.equal(
( function testClassesShouldBeConsideredAbstractIfTheyContainAbstractMethods()
{
assert.equal(
AbstractFoo.isAbstract(),
true,
"Classes should be considered abstract if they contain any abstract methods"
);
);
} )();
assert.equal(
( function testSubtypesAreAbstractIfNoConcreteMethodIsProvided()
{
assert.equal(
SubAbstractFoo.isAbstract(),
true,
"Subtypes of abstract types are abstract if they don't provide a " +
"concrete implementation for all abstract methods"
);
);
} )();
assert.equal(
( function testSubtypesAreNotConisderedAbstractIfConcreteImplIsProvided()
{
assert.equal(
ConcreteFoo.isAbstract(),
false,
"Subtypes of abstract types are not abstract if they provide concrete " +
"implementations of all abstract methods"
);
);
} )();
assert.throws( function()
( function testAbstractClassesCannotBeInstantiated()
{
new AbstractFoo();
new SubAbstractFoo();
}, Error, "Abstract classes cannot be instantiated" );
assert.throws( function()
{
// 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"
);
);
} )();
ctor_called = false;
new ConcreteFoo();
assert.equal(
( function testCanCallConstructorsOfAbstractSupertypes()
{
ctor_called = false;
ConcreteFoo();
assert.equal(
ctor_called,
true,
"Can call constructors of abstract supertypes"
);
);
} )();
assert.throws( function()
( function testConcreteMethodsMustImplementTheProperNumberOfArguments()
{
assert.throws( function()
{
AbstractFoo.extend(
{
// 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()
{
AbstractFoo.extend(
@ -140,10 +182,15 @@ assert.throws(
});
},
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()
{
AbstractFoo.extend(
@ -153,12 +200,16 @@ assert.doesNotThrow(
});
},
Error,
"Abstract methods of subtypes may implement additional arguments, so long" +
"as they implement at least the required number of arguments as defined by " +
"it supertype"
);
"Abstract methods of subtypes may implement additional arguments, " +
"so long as they implement at least the required number of " +
"arguments as defined by it supertype"
);
} )();
assert.doesNotThrow(
( function testConcreteMethodsHaveNoArgumentRequirementsIfNoDefinitionGiven()
{
assert.doesNotThrow(
function()
{
AbstractFoo.extend(
@ -169,19 +220,23 @@ assert.doesNotThrow(
});
},
Error,
"Concrete methods needn't implement the proper number of arguments if " +
"no definition was provided"
);
"Concrete methods needn't implement the proper number of arguments " +
"if no definition was provided"
);
} )();
assert.throws( function()
( function testAbstractMethodsMustBeDeclaredAsArrays()
{
assert.throws( function()
{
Class.extend(
{
// not an array (invalid)
'abstract foo': 'scalar',
} );
}, TypeError, "Abstract methods must be declared as arrays" );
}, TypeError, "Abstract methods must be declared as arrays" );
} )();
/**