diff --git a/modules/ve2/dm/ve.dm.BranchNode.js b/modules/ve2/dm/ve.dm.BranchNode.js index e94a0e6767..58aeb5df8b 100644 --- a/modules/ve2/dm/ve.dm.BranchNode.js +++ b/modules/ve2/dm/ve.dm.BranchNode.js @@ -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++ ) { diff --git a/modules/ve2/dm/ve.dm.Node.js b/modules/ve2/dm/ve.dm.Node.js index 06e52f0541..7edcc035a6 100644 --- a/modules/ve2/dm/ve.dm.Node.js +++ b/modules/ve2/dm/ve.dm.Node.js @@ -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 */ diff --git a/modules/ve2/ve.Node.js b/modules/ve2/ve.Node.js index 3df7eecb42..9a4bb6dbc1 100644 --- a/modules/ve2/ve.Node.js +++ b/modules/ve2/ve.Node.js @@ -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; }; /** diff --git a/tests/ve2/dm/ve.dm.Node.test.js b/tests/ve2/dm/ve.dm.Node.test.js index 46f755b65c..9b8ba41f95 100644 --- a/tests/ve2/dm/ve.dm.Node.test.js +++ b/tests/ve2/dm/ve.dm.Node.test.js @@ -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() { diff --git a/tests/ve2/dm/ve.dm.TwigNode.test.js b/tests/ve2/dm/ve.dm.TwigNode.test.js index 4674f42c47..ed66dc867d 100644 --- a/tests/ve2/dm/ve.dm.TwigNode.test.js +++ b/tests/ve2/dm/ve.dm.TwigNode.test.js @@ -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] ); diff --git a/tests/ve2/ve.Node.test.js b/tests/ve2/ve.Node.test.js index 2b9e1c83af..2e4d0eb79a 100644 --- a/tests/ve2/ve.Node.test.js +++ b/tests/ve2/ve.Node.test.js @@ -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() {