mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
Added tests for all exceptions
We are now checking for the exception messages as well. Change-Id: I3a306ce9fe82afe6fd1e46a2e4da4d0a70952688
This commit is contained in:
parent
9a3784301b
commit
b004b22241
|
@ -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
|
// Check all children are valid before inserting any so we don't end up in an insane state
|
||||||
for ( i = 2; i < length; i++ ) {
|
for ( i = 2; i < length; i++ ) {
|
||||||
if ( !this.canHaveGrandchildren() && args[i].canHaveChildren() ) {
|
if ( !this.canHaveGrandchildren() && args[i].canHaveChildren() ) {
|
||||||
throw 'Node that can have children can not be inserted into' +
|
throw 'Node that can have children can not be inserted into ' +
|
||||||
'node that can not have grandchildren';
|
'node that can\'t have grandchildren';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( i = 2; i < length; i++ ) {
|
for ( i = 2; i < length; i++ ) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ ve.dm.Node = function( type, length, attributes ) {
|
||||||
* @returns {ve.ce.Node} New item view associated with this model
|
* @returns {ve.ce.Node} New item view associated with this model
|
||||||
*/
|
*/
|
||||||
ve.dm.Node.prototype.createView = function() {
|
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 */
|
/* Methods */
|
||||||
|
|
|
@ -34,7 +34,7 @@ ve.Node = function( type ) {
|
||||||
* @returns {Boolean} Whether this node can have children
|
* @returns {Boolean} Whether this node can have children
|
||||||
*/
|
*/
|
||||||
ve.Node.prototype.canHaveChildren = function() {
|
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
|
* @returns {Boolean} Whether this node can have grandchildren
|
||||||
*/
|
*/
|
||||||
ve.Node.prototype.canHaveGrandchildren = function() {
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,27 +12,39 @@ ve.extendClass( ve.dm.NodeStub, ve.dm.Node );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
test( 'prototype.canHaveChildren', 1, function() {
|
test( 'prototype.canHaveChildren', 1, function() {
|
||||||
raises( function() {
|
raises(
|
||||||
var node = new ve.dm.NodeStub();
|
function() {
|
||||||
// Abstract method, must be overridden, throws exception when called
|
var node = new ve.dm.NodeStub();
|
||||||
node.canHaveChildren();
|
// Abstract method, must be overridden, throws exception when called
|
||||||
}, 'throws exception when called' );
|
node.canHaveChildren();
|
||||||
|
},
|
||||||
|
/^ve.Node.canHaveChildren not implemented in this subclass: /,
|
||||||
|
'throws exception when called'
|
||||||
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'prototype.canHaveGrandchildren', 1, function() {
|
test( 'prototype.canHaveGrandchildren', 1, function() {
|
||||||
raises( function() {
|
raises(
|
||||||
var node = new ve.dm.NodeStub();
|
function() {
|
||||||
// Abstract method, must be overridden, throws exception when called
|
var node = new ve.dm.NodeStub();
|
||||||
node.canHaveGrandchildren();
|
// Abstract method, must be overridden, throws exception when called
|
||||||
}, 'throws exception when called' );
|
node.canHaveGrandchildren();
|
||||||
|
},
|
||||||
|
/^ve.Node.canHaveGrandchildren not implemented in this subclass: /,
|
||||||
|
'throws exception when called'
|
||||||
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'prototype.createView', 1, function() {
|
test( 'prototype.createView', 1, function() {
|
||||||
raises( function() {
|
raises(
|
||||||
var node = new ve.dm.NodeStub();
|
function() {
|
||||||
// Abstract method, must be overridden, throws exception when called
|
var node = new ve.dm.NodeStub();
|
||||||
node.createView();
|
// Abstract method, must be overridden, throws exception when called
|
||||||
}, 'throws exception when called' );
|
node.createView();
|
||||||
|
},
|
||||||
|
/^ve.dm.Node.createView not implemented in this subclass: /,
|
||||||
|
'throws exception when called'
|
||||||
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'prototype.getLength', 2, function() {
|
test( 'prototype.getLength', 2, function() {
|
||||||
|
@ -49,10 +61,18 @@ test( 'prototype.getOuterLength', 2, function() {
|
||||||
strictEqual( node2.getOuterLength(), 1234 );
|
strictEqual( node2.getOuterLength(), 1234 );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'prototype.setLength', 1, function() {
|
test( 'prototype.setLength', 2, function() {
|
||||||
var node = new ve.dm.NodeStub();
|
var node = new ve.dm.NodeStub();
|
||||||
node.setLength( 1234 );
|
node.setLength( 1234 );
|
||||||
strictEqual( node.getLength(), 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() {
|
test( 'prototype.adjustLength', 1, function() {
|
||||||
|
|
|
@ -34,12 +34,20 @@ test( 'prototype.splice', 8, function() {
|
||||||
// Will be called 1 time
|
// Will be called 1 time
|
||||||
ok( true, 'afterSplice was emitted' );
|
ok( true, 'afterSplice was emitted' );
|
||||||
} );
|
} );
|
||||||
raises( function() {
|
raises(
|
||||||
node4.splice( 0, 0, node1 );
|
function() {
|
||||||
}, 'inserting a branch into twig throws an exception' );
|
node4.splice( 0, 0, node1 );
|
||||||
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' );
|
'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
|
// Insert leaf
|
||||||
deepEqual( node4.splice( 0, 0, node3 ), [] );
|
deepEqual( node4.splice( 0, 0, node3 ), [] );
|
||||||
deepEqual( node4.getChildren(), [node3] );
|
deepEqual( node4.getChildren(), [node3] );
|
||||||
|
|
|
@ -12,19 +12,27 @@ ve.extendClass( ve.NodeStub, ve.Node );
|
||||||
/* Tests */
|
/* Tests */
|
||||||
|
|
||||||
test( 'prototype.canHaveChildren', 1, function() {
|
test( 'prototype.canHaveChildren', 1, function() {
|
||||||
raises( function() {
|
raises(
|
||||||
var node = new ve.NodeStub();
|
function() {
|
||||||
// Abstract method, must be overridden, throws exception when called
|
var node = new ve.NodeStub();
|
||||||
node.canHaveChildren();
|
// Abstract method, must be overridden, throws exception when called
|
||||||
}, 'throws exception when called' );
|
node.canHaveChildren();
|
||||||
|
},
|
||||||
|
/^ve.Node.canHaveChildren not implemented in this subclass: /,
|
||||||
|
'throws exception when called'
|
||||||
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'prototype.canHaveGrandchildren', 1, function() {
|
test( 'prototype.canHaveGrandchildren', 1, function() {
|
||||||
raises( function() {
|
raises(
|
||||||
var node = new ve.NodeStub();
|
function() {
|
||||||
// Abstract method, must be overridden, throws exception when called
|
var node = new ve.NodeStub();
|
||||||
node.canHaveGrandchildren();
|
// Abstract method, must be overridden, throws exception when called
|
||||||
}, 'throws exception when called' );
|
node.canHaveGrandchildren();
|
||||||
|
},
|
||||||
|
/^ve.Node.canHaveGrandchildren not implemented in this subclass: /,
|
||||||
|
'throws exception when called'
|
||||||
|
);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'prototype.getType', 1, function() {
|
test( 'prototype.getType', 1, function() {
|
||||||
|
|
Loading…
Reference in a new issue