Put class-implement tests into self-executing functions in testdox format to make them more easily recognized
- Eventually, I'd like for all the tests to be in this formatclosure/master
parent
ab46e52a37
commit
1b40451aad
|
@ -30,27 +30,38 @@ var common = require( './common' ),
|
||||||
|
|
||||||
var Type = Interface.extend( {
|
var Type = Interface.extend( {
|
||||||
'abstract foo': [],
|
'abstract foo': [],
|
||||||
});
|
}),
|
||||||
|
|
||||||
var Type2 = Interface.extend( {
|
Type2 = Interface.extend( {
|
||||||
'abstract foo2': [],
|
'abstract foo2': [],
|
||||||
});
|
}),
|
||||||
|
|
||||||
|
Foo = {},
|
||||||
|
PlainFoo = Class.extend(),
|
||||||
|
PlainFoo2 = {}
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
( function testClassExportsContainImplementMethodToExtendFromNoBaseClass()
|
||||||
|
{
|
||||||
assert.ok(
|
assert.ok(
|
||||||
( Class.implement instanceof Function ),
|
( Class.implement instanceof Function ),
|
||||||
"Class provides method to implement interfaces"
|
"Class provides method to implement interfaces"
|
||||||
);
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
var Foo = {},
|
|
||||||
PlainFoo = Class.extend(),
|
|
||||||
PlainFoo2 = {};
|
|
||||||
|
|
||||||
|
( function testClassObjectsContainImplementMethodToImplementUsingItselfAsABase()
|
||||||
|
{
|
||||||
assert.ok(
|
assert.ok(
|
||||||
( PlainFoo.implement instanceof Function ),
|
( PlainFoo.implement instanceof Function ),
|
||||||
"Classes contain an implement() method"
|
"Classes contain an implement() method"
|
||||||
);
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
( function testCanImplementInterfaceFromAnEmptyBase()
|
||||||
|
{
|
||||||
assert.doesNotThrow( function()
|
assert.doesNotThrow( function()
|
||||||
{
|
{
|
||||||
Foo = Class.implement( Type, Type2 );
|
Foo = Class.implement( Type, Type2 );
|
||||||
|
@ -61,33 +72,60 @@ assert.ok(
|
||||||
"Class returned from implementing interfaces on an empty base is a " +
|
"Class returned from implementing interfaces on an empty base is a " +
|
||||||
"valid class"
|
"valid class"
|
||||||
);
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
( function testAbstractMethodsCopiedIntoNewClassUsingEmptyBase()
|
||||||
|
{
|
||||||
assert.ok(
|
assert.ok(
|
||||||
( ( Foo.prototype.foo instanceof Function )
|
( ( Foo.prototype.foo instanceof Function )
|
||||||
&& ( Foo.prototype.foo2 instanceof Function )
|
&& ( Foo.prototype.foo2 instanceof Function )
|
||||||
),
|
),
|
||||||
"Abstract methods are copied into the new class prototype (empty base)"
|
"Abstract methods are copied into the new class prototype (empty base)"
|
||||||
);
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
( function testCanImplementInterfaceAtopAnExistingClass()
|
||||||
|
{
|
||||||
assert.doesNotThrow( function()
|
assert.doesNotThrow( function()
|
||||||
{
|
{
|
||||||
PlainFoo2 = PlainFoo.implement( Type, Type2 );
|
PlainFoo2 = PlainFoo.implement( Type, Type2 );
|
||||||
}, Error, "Concrete classes can implement interfaces" );
|
}, Error, "Classes can implement interfaces" );
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
( Class.isClass( PlainFoo2 ) ),
|
||||||
|
"Class returned from implementing interfaces on an existing base is a " +
|
||||||
|
"valid class"
|
||||||
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
( function testAbstractMethodsCopiedIntoNewClassUsingExistingBase()
|
||||||
|
{
|
||||||
assert.ok(
|
assert.ok(
|
||||||
( ( PlainFoo2.prototype.foo instanceof Function )
|
( ( PlainFoo2.prototype.foo instanceof Function )
|
||||||
&& ( PlainFoo2.prototype.foo2 instanceof Function )
|
&& ( PlainFoo2.prototype.foo2 instanceof Function )
|
||||||
),
|
),
|
||||||
"Abstract methods are copied into the new class prototype (concrete base)"
|
"Abstract methods are copied into the new class prototype (concrete base)"
|
||||||
);
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
( function testClassesImplementingInterfacesAreConsideredAbstractByDefault()
|
||||||
|
{
|
||||||
assert.equal(
|
assert.equal(
|
||||||
( Foo.isAbstract() && PlainFoo2.isAbstract() ),
|
( Foo.isAbstract() && PlainFoo2.isAbstract() ),
|
||||||
true,
|
true,
|
||||||
"Classes that implements interface(s) are considered abstract if the " +
|
"Classes that implements interface(s) are considered abstract if the " +
|
||||||
"implemented methods have no concrete implementations"
|
"implemented methods have no concrete implementations"
|
||||||
);
|
);
|
||||||
|
} ) ();
|
||||||
|
|
||||||
|
|
||||||
|
( function testAbstractMethodListUpdatedWhenInterfaceImplemented()
|
||||||
|
{
|
||||||
|
// no base
|
||||||
assert.equal(
|
assert.equal(
|
||||||
Foo.abstractMethods.length,
|
Foo.abstractMethods.length,
|
||||||
2,
|
2,
|
||||||
|
@ -95,13 +133,18 @@ assert.equal(
|
||||||
"(empty base)"
|
"(empty base)"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// PlainFoo base
|
||||||
assert.equal(
|
assert.equal(
|
||||||
PlainFoo2.abstractMethods.length,
|
PlainFoo2.abstractMethods.length,
|
||||||
2,
|
2,
|
||||||
"Abstract methods list is updated when interface is implemented " +
|
"Abstract methods list is updated when interface is implemented " +
|
||||||
"(concrete base)"
|
"(concrete base)"
|
||||||
);
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
( function testProperAbstractMethodsAreCopiedFromInterface()
|
||||||
|
{
|
||||||
assert.ok(
|
assert.ok(
|
||||||
( ( Foo.abstractMethods[ 0 ] == 'foo' )
|
( ( Foo.abstractMethods[ 0 ] == 'foo' )
|
||||||
&& ( Foo.abstractMethods[ 1 ] == 'foo2' )
|
&& ( Foo.abstractMethods[ 1 ] == 'foo2' )
|
||||||
|
@ -111,8 +154,11 @@ assert.ok(
|
||||||
),
|
),
|
||||||
"Abstract methods list contains names of implemented methods"
|
"Abstract methods list contains names of implemented methods"
|
||||||
);
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
||||||
|
( function testInstancesOfClassesAreInstancesOfTheirImplementedInterfaces()
|
||||||
|
{
|
||||||
// concrete implementation so that we can instantiate it
|
// concrete implementation so that we can instantiate it
|
||||||
var ConcreteFoo = Foo.extend(
|
var ConcreteFoo = Foo.extend(
|
||||||
{
|
{
|
||||||
|
@ -129,4 +175,5 @@ assert.ok(
|
||||||
"Instances of classes implementing interfaces are considered to be " +
|
"Instances of classes implementing interfaces are considered to be " +
|
||||||
"instances of the implemented interfaces"
|
"instances of the implemented interfaces"
|
||||||
);
|
);
|
||||||
|
} )();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue