Reorganized abstract tests
parent
b359906aa3
commit
623c3df429
|
@ -68,57 +68,95 @@ var ConcreteFoo = AbstractFoo.extend(
|
|||
});
|
||||
|
||||
|
||||
/**
|
||||
* All classes should have a method to determine if they are abstract.
|
||||
*/
|
||||
( function testAllClassesHaveAMethodToDetmineIfAbstract()
|
||||
{
|
||||
assert.ok(
|
||||
( Foo.isAbstract instanceof Function ),
|
||||
( Class( {} ).isAbstract instanceof Function ),
|
||||
"All classes should have an isAbstract() method"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testClassesAreNotConsideredToBeAbstractIfTheyHaveNoAbstractMethods()
|
||||
{
|
||||
assert.equal(
|
||||
Foo.isAbstract(),
|
||||
Class( {} ).isAbstract(),
|
||||
false,
|
||||
"Classes are not abstract if they contain no abstract methods"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testClassesShouldBeConsideredAbstractIfTheyContainAbstractMethods()
|
||||
{
|
||||
assert.equal(
|
||||
AbstractFoo.isAbstract(),
|
||||
true,
|
||||
"Classes should be considered abstract if they contain any abstract methods"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( 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"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testSubtypesAreNotConisderedAbstractIfConcreteImplIsProvided()
|
||||
{
|
||||
assert.equal(
|
||||
ConcreteFoo.isAbstract(),
|
||||
false,
|
||||
"Subtypes of abstract types are not abstract if they provide concrete " +
|
||||
"implementations of all abstract methods"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testAbstractClassesCannotBeInstantiated()
|
||||
{
|
||||
assert.throws( function()
|
||||
{
|
||||
new AbstractFoo();
|
||||
new SubAbstractFoo();
|
||||
// both should fail
|
||||
AbstractFoo();
|
||||
SubAbstractFoo();
|
||||
}, Error, "Abstract classes cannot be instantiated" );
|
||||
} )();
|
||||
|
||||
|
||||
( function testConcreteSubclassesCanBeInstantiated()
|
||||
{
|
||||
assert.ok(
|
||||
new ConcreteFoo(),
|
||||
ConcreteFoo(),
|
||||
"Concrete subclasses can be instantiated"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testCanCallConstructorsOfAbstractSupertypes()
|
||||
{
|
||||
ctor_called = false;
|
||||
new ConcreteFoo();
|
||||
ConcreteFoo();
|
||||
|
||||
assert.equal(
|
||||
ctor_called,
|
||||
true,
|
||||
"Can call constructors of abstract supertypes"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testConcreteMethodsMustImplementTheProperNumberOfArguments()
|
||||
{
|
||||
assert.throws( function()
|
||||
{
|
||||
AbstractFoo.extend(
|
||||
|
@ -129,7 +167,11 @@ assert.throws( function()
|
|||
},
|
||||
});
|
||||
}, Error, "Concrete methods must implement the proper number of argments" );
|
||||
} )();
|
||||
|
||||
|
||||
( function testAbstractMethodsOfSubtypesMustImplementProperNumberOfArguments()
|
||||
{
|
||||
assert.throws(
|
||||
function()
|
||||
{
|
||||
|
@ -140,9 +182,14 @@ 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"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testAbstractMembersMayImplementMoreArgumentsThanSupertype()
|
||||
{
|
||||
assert.doesNotThrow(
|
||||
function()
|
||||
{
|
||||
|
@ -153,11 +200,15 @@ 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"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testConcreteMethodsHaveNoArgumentRequirementsIfNoDefinitionGiven()
|
||||
{
|
||||
assert.doesNotThrow(
|
||||
function()
|
||||
{
|
||||
|
@ -169,11 +220,14 @@ 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"
|
||||
);
|
||||
} )();
|
||||
|
||||
|
||||
( function testAbstractMethodsMustBeDeclaredAsArrays()
|
||||
{
|
||||
assert.throws( function()
|
||||
{
|
||||
Class.extend(
|
||||
|
@ -182,6 +236,7 @@ assert.throws( function()
|
|||
'abstract foo': 'scalar',
|
||||
} );
|
||||
}, TypeError, "Abstract methods must be declared as arrays" );
|
||||
} )();
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue