Added tests for getOffsetFromNode

Change-Id: I4dc06e9ea3b634fbd5034df721162098441ea368
This commit is contained in:
Trevor Parscal 2012-05-03 11:52:17 -07:00
parent 619f10108c
commit 71f36aa52b
2 changed files with 25 additions and 0 deletions

View file

@ -7,8 +7,15 @@ ve.dm.BranchNodeStub = function( children ) {
ve.dm.BranchNode.call( this, 'branch-stub', children );
};
ve.dm.BranchNodeStub.rules = {
'canHaveChildren': true,
'canHaveGrandchildren': true
};
ve.extendClass( ve.dm.BranchNodeStub, ve.dm.BranchNode );
ve.dm.factory.register( 'branch-stub', ve.dm.BranchNodeStub );
/* Tests */
test( 'setRoot', 3, function() {
@ -89,3 +96,14 @@ test( 'splice', 9, function() {
deepEqual( node4.splice( 1, 1, node3 ), [node2] );
deepEqual( node4.getChildren(), [node1, node3] );
} );
test( 'getOffsetFromNode', 4, function() {
var node1 = new ve.dm.BranchNodeStub(),
node2 = new ve.dm.BranchNodeStub(),
node3 = new ve.dm.BranchNodeStub( [node1, node2] ),
node4 = new ve.dm.BranchNodeStub( [node3] );
strictEqual( node4.getOffsetFromNode( node1 ), 1 );
strictEqual( node4.getOffsetFromNode( node2 ), 3 );
strictEqual( node4.getOffsetFromNode( node3 ), 0 );
strictEqual( node4.getOffsetFromNode( node4 ), 0 );
} );

View file

@ -7,6 +7,13 @@ ve.dm.LeafNodeStub = function() {
ve.dm.LeafNode.call( this, 'leaf-stub' );
};
ve.dm.LeafNodeStub.rules = {
'canHaveChildren': false,
'canHaveGrandchildren': false
};
ve.extendClass( ve.dm.LeafNodeStub, ve.dm.LeafNode );
ve.dm.factory.register( 'leaf-stub', ve.dm.LeafNodeStub );
/* Tests */