Added tests for all exceptions

We are now checking for the exception messages as well.

Change-Id: I3a306ce9fe82afe6fd1e46a2e4da4d0a70952688
This commit is contained in:
Trevor Parscal 2012-04-19 18:05:48 -07:00
parent 9a3784301b
commit b004b22241
6 changed files with 73 additions and 37 deletions

View file

@ -129,8 +129,8 @@ ve.dm.BranchNode.prototype.splice = function( index, howmany ) {
// Check all children are valid before inserting any so we don't end up in an insane state
for ( i = 2; i < length; i++ ) {
if ( !this.canHaveGrandchildren() && args[i].canHaveChildren() ) {
throw 'Node that can have children can not be inserted into' +
'node that can not have grandchildren';
throw 'Node that can have children can not be inserted into ' +
'node that can\'t have grandchildren';
}
}
for ( i = 2; i < length; i++ ) {

View file

@ -28,7 +28,7 @@ ve.dm.Node = function( type, length, attributes ) {
* @returns {ve.ce.Node} New item view associated with this model
*/
ve.dm.Node.prototype.createView = function() {
throw 'DocumentModelNode.createView not implemented in this subclass:' + this.constructor;
throw 've.dm.Node.createView not implemented in this subclass: ' + this.constructor;
};
/* Methods */

View file

@ -34,7 +34,7 @@ ve.Node = function( type ) {
* @returns {Boolean} Whether this node can have children
*/
ve.Node.prototype.canHaveChildren = function() {
throw 've.Node.canHaveChildren not implemented in this subclass:' + this.constructor;
throw 've.Node.canHaveChildren not implemented in this subclass: ' + this.constructor;
};
/**
@ -48,7 +48,7 @@ ve.Node.prototype.canHaveChildren = function() {
* @returns {Boolean} Whether this node can have grandchildren
*/
ve.Node.prototype.canHaveGrandchildren = function() {
throw 've.Node.canHaveGrandchildren not implemented in this subclass:' + this.constructor;
throw 've.Node.canHaveGrandchildren not implemented in this subclass: ' + this.constructor;
};
/**

View file

@ -12,27 +12,39 @@ ve.extendClass( ve.dm.NodeStub, ve.dm.Node );
/* Tests */
test( 'prototype.canHaveChildren', 1, function() {
raises( function() {
var node = new ve.dm.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.canHaveChildren();
}, 'throws exception when called' );
raises(
function() {
var node = new ve.dm.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.canHaveChildren();
},
/^ve.Node.canHaveChildren not implemented in this subclass: /,
'throws exception when called'
);
} );
test( 'prototype.canHaveGrandchildren', 1, function() {
raises( function() {
var node = new ve.dm.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.canHaveGrandchildren();
}, 'throws exception when called' );
raises(
function() {
var node = new ve.dm.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.canHaveGrandchildren();
},
/^ve.Node.canHaveGrandchildren not implemented in this subclass: /,
'throws exception when called'
);
} );
test( 'prototype.createView', 1, function() {
raises( function() {
var node = new ve.dm.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.createView();
}, 'throws exception when called' );
raises(
function() {
var node = new ve.dm.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.createView();
},
/^ve.dm.Node.createView not implemented in this subclass: /,
'throws exception when called'
);
} );
test( 'prototype.getLength', 2, function() {
@ -49,10 +61,18 @@ test( 'prototype.getOuterLength', 2, function() {
strictEqual( node2.getOuterLength(), 1234 );
} );
test( 'prototype.setLength', 1, function() {
test( 'prototype.setLength', 2, function() {
var node = new ve.dm.NodeStub();
node.setLength( 1234 );
strictEqual( node.getLength(), 1234 );
raises(
function() {
// Length can not be negative
node.setLength( -1 );
},
/^Length cannot be negative$/,
'throws exception if length is negative'
);
} );
test( 'prototype.adjustLength', 1, function() {

View file

@ -34,12 +34,20 @@ test( 'prototype.splice', 8, function() {
// Will be called 1 time
ok( true, 'afterSplice was emitted' );
} );
raises( function() {
node4.splice( 0, 0, node1 );
}, 'inserting a branch into twig throws an exception' );
raises( function() {
node4.splice( 0, 0, node2 );
}, 'inserting a twig into another twig throws an exception' );
raises(
function() {
node4.splice( 0, 0, node1 );
},
/^Node that can have children can not be inserted into node that can't have grandchildren$/,
'inserting a branch into twig throws an exception'
);
raises(
function() {
node4.splice( 0, 0, node2 );
},
/^Node that can have children can not be inserted into node that can't have grandchildren$/,
'inserting a twig into another twig throws an exception'
);
// Insert leaf
deepEqual( node4.splice( 0, 0, node3 ), [] );
deepEqual( node4.getChildren(), [node3] );

View file

@ -12,19 +12,27 @@ ve.extendClass( ve.NodeStub, ve.Node );
/* Tests */
test( 'prototype.canHaveChildren', 1, function() {
raises( function() {
var node = new ve.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.canHaveChildren();
}, 'throws exception when called' );
raises(
function() {
var node = new ve.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.canHaveChildren();
},
/^ve.Node.canHaveChildren not implemented in this subclass: /,
'throws exception when called'
);
} );
test( 'prototype.canHaveGrandchildren', 1, function() {
raises( function() {
var node = new ve.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.canHaveGrandchildren();
}, 'throws exception when called' );
raises(
function() {
var node = new ve.NodeStub();
// Abstract method, must be overridden, throws exception when called
node.canHaveGrandchildren();
},
/^ve.Node.canHaveGrandchildren not implemented in this subclass: /,
'throws exception when called'
);
} );
test( 'prototype.getType', 1, function() {