浏览代码

Fixed tests for Position, PositionIterator, Range and Text.

Szymon Cofalik 10 年之前
父节点
当前提交
ecbe34b609

+ 55 - 79
packages/ckeditor5-engine/tests/document/position.js

@@ -16,7 +16,7 @@ var modules = bender.amd.require(
 	'document/nodelist' );
 	'document/nodelist' );
 
 
 describe( 'position', function() {
 describe( 'position', function() {
-	var Element, Character, Document, NodeList;
+	var Element, Character, Document, NodeList, Position, CKEditorError;
 
 
 	var doc, root, p, ul, li1, li2, f, o, z, b, a, r;
 	var doc, root, p, ul, li1, li2, f, o, z, b, a, r;
 
 
@@ -36,10 +36,12 @@ describe( 'position', function() {
 		Character = modules[ 'document/character' ];
 		Character = modules[ 'document/character' ];
 		Document = modules[ 'document/document' ];
 		Document = modules[ 'document/document' ];
 		NodeList = modules[ 'document/nodelist' ];
 		NodeList = modules[ 'document/nodelist' ];
+		Position = modules[ 'document/position' ];
+		CKEditorError = modules.ckeditorerror;
 
 
 		doc = new Document();
 		doc = new Document();
 
 
-		root = doc.root;
+		root = doc.createRoot( 'root' );
 
 
 		f = new Character( 'f' );
 		f = new Character( 'f' );
 		o = new Character( 'o' );
 		o = new Character( 'o' );
@@ -61,17 +63,13 @@ describe( 'position', function() {
 	} );
 	} );
 
 
 	it( 'should create a position with path and document', function() {
 	it( 'should create a position with path and document', function() {
-		var Position = modules[ 'document/position' ];
-
-		var position = new Position( [ 0 ], doc.root );
+		var position = new Position( [ 0 ], root );
 
 
 		expect( position ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
 		expect( position ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
-		expect( position ).to.have.property( 'root' ).that.equals( doc.root );
+		expect( position ).to.have.property( 'root' ).that.equals( root );
 	} );
 	} );
 
 
 	it( 'should make positions form node and offset', function() {
 	it( 'should make positions form node and offset', function() {
-		var Position = modules[ 'document/position' ];
-
 		expect( Position.createFromParentAndOffset( root, 0 ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
 		expect( Position.createFromParentAndOffset( root, 0 ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
 		expect( Position.createFromParentAndOffset( root, 1 ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
 		expect( Position.createFromParentAndOffset( root, 1 ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
 		expect( Position.createFromParentAndOffset( root, 2 ) ).to.have.property( 'path' ).that.deep.equals( [ 2 ] );
 		expect( Position.createFromParentAndOffset( root, 2 ) ).to.have.property( 'path' ).that.deep.equals( [ 2 ] );
@@ -89,8 +87,6 @@ describe( 'position', function() {
 	} );
 	} );
 
 
 	it( 'should make positions before elements', function() {
 	it( 'should make positions before elements', function() {
-		var Position = modules[ 'document/position' ];
-
 		expect( Position.createBefore( p ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
 		expect( Position.createBefore( p ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
 
 
 		expect( Position.createBefore( ul ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
 		expect( Position.createBefore( ul ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
@@ -109,17 +105,12 @@ describe( 'position', function() {
 	} );
 	} );
 
 
 	it( 'should throw error if one try to make positions before root', function() {
 	it( 'should throw error if one try to make positions before root', function() {
-		var Position = modules[ 'document/position' ];
-		var CKEditorError = modules.ckeditorerror;
-
 		expect( function() {
 		expect( function() {
 			Position.createBefore( root );
 			Position.createBefore( root );
 		} ).to.throw( CKEditorError, /position-before-root/ );
 		} ).to.throw( CKEditorError, /position-before-root/ );
 	} );
 	} );
 
 
 	it( 'should make positions after elements', function() {
 	it( 'should make positions after elements', function() {
-		var Position = modules[ 'document/position' ];
-
 		expect( Position.createAfter( p ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
 		expect( Position.createAfter( p ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
 
 
 		expect( Position.createAfter( ul ) ).to.have.property( 'path' ).that.deep.equals( [ 2 ] );
 		expect( Position.createAfter( ul ) ).to.have.property( 'path' ).that.deep.equals( [ 2 ] );
@@ -138,105 +129,90 @@ describe( 'position', function() {
 	} );
 	} );
 
 
 	it( 'should throw error if one try to make positions after root', function() {
 	it( 'should throw error if one try to make positions after root', function() {
-		var Position = modules[ 'document/position' ];
-		var CKEditorError = modules.ckeditorerror;
-
 		expect( function() {
 		expect( function() {
 			Position.createAfter( root );
 			Position.createAfter( root );
 		} ).to.throw( CKEditorError, /position-after-root/ );
 		} ).to.throw( CKEditorError, /position-after-root/ );
 	} );
 	} );
 
 
 	it( 'should have parent', function() {
 	it( 'should have parent', function() {
-		var Position = modules[ 'document/position' ];
+		expect( new Position( [ 0 ], root ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( [ 1 ], root ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( [ 2 ], root ) ).to.have.property( 'parent' ).that.equals( root );
 
 
-		expect( new Position( [ 0 ], doc.root ) ).to.have.property( 'parent' ).that.equals( root );
-		expect( new Position( [ 1 ], doc.root ) ).to.have.property( 'parent' ).that.equals( root );
-		expect( new Position( [ 2 ], doc.root ) ).to.have.property( 'parent' ).that.equals( root );
+		expect( new Position( [ 0, 0 ], root ) ).to.have.property( 'parent' ).that.equals( p );
 
 
-		expect( new Position( [ 0, 0 ], doc.root ) ).to.have.property( 'parent' ).that.equals( p );
+		expect( new Position( [ 1, 0 ], root ) ).to.have.property( 'parent' ).that.equals( ul );
+		expect( new Position( [ 1, 1 ], root ) ).to.have.property( 'parent' ).that.equals( ul );
+		expect( new Position( [ 1, 2 ], root ) ).to.have.property( 'parent' ).that.equals( ul );
 
 
-		expect( new Position( [ 1, 0 ], doc.root ) ).to.have.property( 'parent' ).that.equals( ul );
-		expect( new Position( [ 1, 1 ], doc.root ) ).to.have.property( 'parent' ).that.equals( ul );
-		expect( new Position( [ 1, 2 ], doc.root ) ).to.have.property( 'parent' ).that.equals( ul );
-
-		expect( new Position( [ 1, 0, 0 ], doc.root ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 1 ], doc.root ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 2 ], doc.root ) ).to.have.property( 'parent' ).that.equals( li1 );
-		expect( new Position( [ 1, 0, 3 ], doc.root ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( [ 1, 0, 0 ], root ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( [ 1, 0, 1 ], root ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( [ 1, 0, 2 ], root ) ).to.have.property( 'parent' ).that.equals( li1 );
+		expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'parent' ).that.equals( li1 );
 	} );
 	} );
 
 
 	it( 'should have offset', function() {
 	it( 'should have offset', function() {
-		var Position = modules[ 'document/position' ];
-
-		expect( new Position( [ 0 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 2 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( [ 0 ], root ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( [ 1 ], root ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( [ 2 ], root ) ).to.have.property( 'offset' ).that.equals( 2 );
 
 
-		expect( new Position( [ 0, 0 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( [ 0, 0 ], root ) ).to.have.property( 'offset' ).that.equals( 0 );
 
 
-		expect( new Position( [ 1, 0 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1, 1 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 1, 2 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( [ 1, 0 ], root ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( [ 1, 1 ], root ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( [ 1, 2 ], root ) ).to.have.property( 'offset' ).that.equals( 2 );
 
 
-		expect( new Position( [ 1, 0, 0 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 0 );
-		expect( new Position( [ 1, 0, 1 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 1 );
-		expect( new Position( [ 1, 0, 2 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 2 );
-		expect( new Position( [ 1, 0, 3 ], doc.root ) ).to.have.property( 'offset' ).that.equals( 3 );
+		expect( new Position( [ 1, 0, 0 ], root ) ).to.have.property( 'offset' ).that.equals( 0 );
+		expect( new Position( [ 1, 0, 1 ], root ) ).to.have.property( 'offset' ).that.equals( 1 );
+		expect( new Position( [ 1, 0, 2 ], root ) ).to.have.property( 'offset' ).that.equals( 2 );
+		expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'offset' ).that.equals( 3 );
 	} );
 	} );
 
 
 	it( 'should have nodeBefore', function() {
 	it( 'should have nodeBefore', function() {
-		var Position = modules[ 'document/position' ];
-
-		expect( new Position( [ 0 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( p );
-		expect( new Position( [ 2 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( ul );
+		expect( new Position( [ 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( [ 1 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( p );
+		expect( new Position( [ 2 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( ul );
 
 
-		expect( new Position( [ 0, 0 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( [ 0, 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
 
 
-		expect( new Position( [ 1, 0 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1, 1 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( li1 );
-		expect( new Position( [ 1, 2 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( li2 );
+		expect( new Position( [ 1, 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( [ 1, 1 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( li1 );
+		expect( new Position( [ 1, 2 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( li2 );
 
 
-		expect( new Position( [ 1, 0, 0 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.is.null;
-		expect( new Position( [ 1, 0, 1 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( f );
-		expect( new Position( [ 1, 0, 2 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( o );
-		expect( new Position( [ 1, 0, 3 ], doc.root ) ).to.have.property( 'nodeBefore' ).that.equals( z );
+		expect( new Position( [ 1, 0, 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
+		expect( new Position( [ 1, 0, 1 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( f );
+		expect( new Position( [ 1, 0, 2 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( o );
+		expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( z );
 	} );
 	} );
 
 
 	it( 'should have nodeAfter', function() {
 	it( 'should have nodeAfter', function() {
-		var Position = modules[ 'document/position' ];
+		expect( new Position( [ 0 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( p );
+		expect( new Position( [ 1 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( ul );
+		expect( new Position( [ 2 ], root ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
 
-		expect( new Position( [ 0 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( p );
-		expect( new Position( [ 1 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( ul );
-		expect( new Position( [ 2 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( [ 0, 0 ], root ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
 
-		expect( new Position( [ 0, 0 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( [ 1, 0 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( li1 );
+		expect( new Position( [ 1, 1 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( li2 );
+		expect( new Position( [ 1, 2 ], root ) ).to.have.property( 'nodeAfter' ).that.is.null;
 
 
-		expect( new Position( [ 1, 0 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( li1 );
-		expect( new Position( [ 1, 1 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( li2 );
-		expect( new Position( [ 1, 2 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.is.null;
-
-		expect( new Position( [ 1, 0, 0 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( f );
-		expect( new Position( [ 1, 0, 1 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( o );
-		expect( new Position( [ 1, 0, 2 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.equals( z );
-		expect( new Position( [ 1, 0, 3 ], doc.root ) ).to.have.property( 'nodeAfter' ).that.is.null;
+		expect( new Position( [ 1, 0, 0 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( f );
+		expect( new Position( [ 1, 0, 1 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( o );
+		expect( new Position( [ 1, 0, 2 ], root ) ).to.have.property( 'nodeAfter' ).that.equals( z );
+		expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'nodeAfter' ).that.is.null;
 	} );
 	} );
 
 
 	it( 'should equals another position with the same path', function() {
 	it( 'should equals another position with the same path', function() {
-		var Position = modules[ 'document/position' ];
-
-		var position = new Position( [ 1, 1, 2 ], doc.root );
-		var samePosition = new Position( [ 1, 1, 2 ], doc.root );
+		var position = new Position( [ 1, 1, 2 ], root );
+		var samePosition = new Position( [ 1, 1, 2 ], root );
 
 
 		expect( position.isEqual( samePosition ) ).to.be.true;
 		expect( position.isEqual( samePosition ) ).to.be.true;
 	} );
 	} );
 
 
 	it( 'should not equals another position with the different path', function() {
 	it( 'should not equals another position with the different path', function() {
-		var Position = modules[ 'document/position' ];
-
-		var position = new Position( [ 1, 1, 1 ], doc.root );
-		var differentNode = new Position( [ 1, 2, 2 ], doc.root );
+		var position = new Position( [ 1, 1, 1 ], root );
+		var differentNode = new Position( [ 1, 2, 2 ], root );
 
 
 		expect( position.isEqual( differentNode ) ).to.be.false;
 		expect( position.isEqual( differentNode ) ).to.be.false;
 	} );
 	} );
-} );
+} );

+ 27 - 44
packages/ckeditor5-engine/tests/document/positioniterator.js

@@ -16,25 +16,25 @@ var modules = bender.amd.require(
 	'document/range' );
 	'document/range' );
 
 
 describe( 'range iterator', function() {
 describe( 'range iterator', function() {
-	var doc, expectedItems;
+	var Document, Element, Character, PositionIterator, Position, Range;
 
 
-	var root, img1, paragraph, b, a, r, img2, x;
-
-	var OPENING_TAG, CLOSING_TAG, CHARACTER;
+	var doc, expectedItems, root, img1, paragraph, b, a, r, img2, x;
+	var ELEMENT_ENTER, ELEMENT_LEAVE, CHARACTER;
 
 
 	before( function() {
 	before( function() {
-		var Document = modules[ 'document/document' ];
-
-		var Element = modules[ 'document/element' ];
-		var Character = modules[ 'document/character' ];
-
-		var PositionIterator = modules[ 'document/positioniterator' ];
-		OPENING_TAG = PositionIterator.OPENING_TAG;
-		CLOSING_TAG = PositionIterator.CLOSING_TAG;
+		Document = modules[ 'document/document' ];
+		Element = modules[ 'document/element' ];
+		Character = modules[ 'document/character' ];
+		PositionIterator = modules[ 'document/positioniterator' ];
+		Position = modules[ 'document/position' ];
+		Range = modules[ 'document/range' ];
+
+		ELEMENT_ENTER = PositionIterator.ELEMENT_ENTER;
+		ELEMENT_LEAVE = PositionIterator.ELEMENT_LEAVE;
 		CHARACTER = PositionIterator.CHARACTER;
 		CHARACTER = PositionIterator.CHARACTER;
 
 
 		doc = new Document();
 		doc = new Document();
-		root = doc.root;
+		root = doc.createRoot( 'root' );
 
 
 		// root
 		// root
 		//  |- img1
 		//  |- img1
@@ -59,24 +59,21 @@ describe( 'range iterator', function() {
 		root.insertChildren( 0, [ img1, paragraph ] );
 		root.insertChildren( 0, [ img1, paragraph ] );
 
 
 		expectedItems = [
 		expectedItems = [
-				{ type: OPENING_TAG, node: img1 },
-				{ type: CLOSING_TAG, node: img1 },
-				{ type: OPENING_TAG, node: paragraph },
+				{ type: ELEMENT_ENTER, node: img1 },
+				{ type: ELEMENT_LEAVE, node: img1 },
+				{ type: ELEMENT_ENTER, node: paragraph },
 				{ type: CHARACTER, node: b },
 				{ type: CHARACTER, node: b },
 				{ type: CHARACTER, node: a },
 				{ type: CHARACTER, node: a },
 				{ type: CHARACTER, node: r },
 				{ type: CHARACTER, node: r },
-				{ type: OPENING_TAG, node: img2 },
-				{ type: CLOSING_TAG, node: img2 },
+				{ type: ELEMENT_ENTER, node: img2 },
+				{ type: ELEMENT_LEAVE, node: img2 },
 				{ type: CHARACTER, node: x },
 				{ type: CHARACTER, node: x },
-				{ type: CLOSING_TAG, node: paragraph }
+				{ type: ELEMENT_LEAVE, node: paragraph }
 			];
 			];
 	} );
 	} );
 
 
 	it( 'should return next position', function() {
 	it( 'should return next position', function() {
-		var PositionIterator = modules[ 'document/positioniterator' ];
-		var Position = modules[ 'document/position' ];
-
-		var iterator = new PositionIterator( new Position( [ 0 ], doc.root ) ); // beginning of root
+		var iterator = new PositionIterator( new Position( [ 0 ], root ) ); // beginning of root
 		var i, len;
 		var i, len;
 
 
 		for ( i = 0, len = expectedItems.length; i < len; i++ ) {
 		for ( i = 0, len = expectedItems.length; i < len; i++ ) {
@@ -86,10 +83,7 @@ describe( 'range iterator', function() {
 	} );
 	} );
 
 
 	it( 'should return previous position', function() {
 	it( 'should return previous position', function() {
-		var PositionIterator = modules[ 'document/positioniterator' ];
-		var Position = modules[ 'document/position' ];
-
-		var iterator = new PositionIterator( new Position( [ 2 ], doc.root ) ); // ending of root
+		var iterator = new PositionIterator( new Position( [ 2 ], root ) ); // ending of root
 
 
 		for ( var i = expectedItems.length - 1; i >= 0; i-- ) {
 		for ( var i = expectedItems.length - 1; i >= 0; i-- ) {
 			expect( iterator.previous() ).to.deep.equal( { done: false, value: expectedItems[ i ] } );
 			expect( iterator.previous() ).to.deep.equal( { done: false, value: expectedItems[ i ] } );
@@ -98,12 +92,8 @@ describe( 'range iterator', function() {
 	} );
 	} );
 
 
 	it( 'should return next position in the boundaries', function() {
 	it( 'should return next position in the boundaries', function() {
-		var PositionIterator = modules[ 'document/positioniterator' ];
-		var Position = modules[ 'document/position' ];
-		var Range = modules[ 'document/range' ];
-
-		var start = new Position( [ 1, 0 ], doc.root ); // p, 0
-		var end = new Position( [ 1, 3, 0 ], doc.root ); // img, 0
+		var start = new Position( [ 1, 0 ], root ); // p, 0
+		var end = new Position( [ 1, 3, 0 ], root ); // img, 0
 
 
 		var iterator = new PositionIterator( new Range( start, end ) );
 		var iterator = new PositionIterator( new Range( start, end ) );
 
 
@@ -116,12 +106,8 @@ describe( 'range iterator', function() {
 	} );
 	} );
 
 
 	it( 'should return previous position in the boundaries', function() {
 	it( 'should return previous position in the boundaries', function() {
-		var PositionIterator = modules[ 'document/positioniterator' ];
-		var Position = modules[ 'document/position' ];
-		var Range = modules[ 'document/range' ];
-
-		var start = new Position( [ 1, 0 ], doc.root ); // p, 0
-		var end = new Position( [ 1, 3, 0 ], doc.root ); // img, 0
+		var start = new Position( [ 1, 0 ], root ); // p, 0
+		var end = new Position( [ 1, 3, 0 ], root ); // img, 0
 
 
 		var iterator = new PositionIterator( new Range( start, end ), end );
 		var iterator = new PositionIterator( new Range( start, end ), end );
 
 
@@ -134,11 +120,8 @@ describe( 'range iterator', function() {
 	} );
 	} );
 
 
 	it( 'should return iterate over the range', function() {
 	it( 'should return iterate over the range', function() {
-		var Position = modules[ 'document/position' ];
-		var Range = modules[ 'document/range' ];
-
-		var start = new Position( [ 0 ], doc.root ); // begging of root
-		var end = new Position( [ 2 ], doc.root ); // ending of root
+		var start = new Position( [ 0 ], root ); // begging of root
+		var end = new Position( [ 2 ], root ); // ending of root
 		var range = new Range( start, end );
 		var range = new Range( start, end );
 
 
 		var i = 0;
 		var i = 0;

+ 39 - 48
packages/ckeditor5-engine/tests/document/range.js

@@ -9,70 +9,61 @@
 
 
 var modules = bender.amd.require(
 var modules = bender.amd.require(
 	'document/range',
 	'document/range',
-	'document/position' );
+	'document/position'
+);
 
 
-describe( 'range', function() {
-	it( 'should create a range with given positions', function() {
-		var Position = modules[ 'document/position' ];
-		var Range = modules[ 'document/range' ];
+describe( 'Range', function() {
+	var Range, Position, start, end;
 
 
-		var start = new Position( [ 0 ] );
-		var end = new Position( [ 1 ] );
+	before( function() {
+		Position = modules[ 'document/position' ];
+		Range = modules[ 'document/range' ];
 
 
-		var range = new Range( start, end );
-
-		expect( range ).to.have.property( 'start' ).that.equal( start );
-		expect( range ).to.have.property( 'end' ).that.equal( end );
+		start = new Position( [ 0 ] );
+		end = new Position( [ 1 ] );
 	} );
 	} );
 
 
-	it( 'should be equals same range', function() {
-		var Position = modules[ 'document/position' ];
-		var Range = modules[ 'document/range' ];
-
-		var start = new Position( [ 0 ] );
-		var end = new Position( [ 1 ] );
-
-		var range = new Range( start, end );
-
-		var sameStart = new Position( [ 0 ] );
-		var sameEnd = new Position( [ 1 ] );
+	var range;
 
 
-		var sameRange = new Range( sameStart, sameEnd );
-
-		expect( range.isEqual( sameRange ) ).to.be.true;
+	beforeEach( function() {
+		range = new Range( start, end );
 	} );
 	} );
 
 
-	it( 'should not be equals if the start position is different', function() {
-		var Position = modules[ 'document/position' ];
-		var Range = modules[ 'document/range' ];
-
-		var start = new Position( [ 0 ] );
-		var end = new Position( [ 1 ] );
+	describe( 'constructor', function() {
+		it( 'should create a range with given positions', function() {
+			expect( range ).to.have.property( 'start' ).that.equal( start );
+			expect( range ).to.have.property( 'end' ).that.equal( end );
+		} );
+	} );
 
 
-		var range = new Range( start, end );
+	describe( 'isEqual', function() {
+		it( 'should return true if the ranges are the same', function() {
+			var sameStart = new Position( [ 0 ] );
+			var sameEnd = new Position( [ 1 ] );
 
 
-		var sameStart = new Position( [ 1 ] );
-		var sameEnd = new Position( [ 1 ] );
+			var sameRange = new Range( sameStart, sameEnd );
 
 
-		var sameRange = new Range( sameStart, sameEnd );
+			expect( range.isEqual( sameRange ) ).to.be.true;
+		} );
 
 
-		expect( range.isEqual( sameRange ) ).to.not.be.true;
-	} );
+		it( 'should return false if the start position is different', function() {
+			var range = new Range( start, end );
 
 
-	it( 'should not be equals if the end position is different', function() {
-		var Position = modules[ 'document/position' ];
-		var Range = modules[ 'document/range' ];
+			var diffStart = new Position( [ 1 ] );
+			var sameEnd = new Position( [ 1 ] );
 
 
-		var start = new Position( [ 0 ] );
-		var end = new Position( [ 1 ] );
+			var diffRange = new Range( diffStart, sameEnd );
 
 
-		var range = new Range( start, end );
+			expect( range.isEqual( diffRange ) ).to.not.be.true;
+		} );
 
 
-		var sameStart = new Position( [ 0 ] );
-		var sameEnd = new Position( [ 0 ] );
+		it( 'should return false if the end position is different', function() {
+			var sameStart = new Position( [ 0 ] );
+			var diffEnd = new Position( [ 0 ] );
 
 
-		var sameRange = new Range( sameStart, sameEnd );
+			var diffRange = new Range( sameStart, diffEnd );
 
 
-		expect( range.isEqual( sameRange ) ).to.not.be.true;
+			expect( range.isEqual( diffRange ) ).to.not.be.true;
+		} );
 	} );
 	} );
-} );
+} );

+ 12 - 10
packages/ckeditor5-engine/tests/document/text.js

@@ -13,16 +13,18 @@ var modules = bender.amd.require(
 	'document/text',
 	'document/text',
 	'document/attribute' );
 	'document/attribute' );
 
 
-describe( 'constructor', function() {
-	it( 'should create character without attributes', function() {
-		var Text = modules[ 'document/text' ];
-		var Attribute = modules[ 'document/attribute' ];
+describe( 'Text', function() {
+	describe( 'constructor', function() {
+		it( 'should create character without attributes', function() {
+			var Text = modules[ 'document/text' ];
+			var Attribute = modules[ 'document/attribute' ];
 
 
-		var attrs = [ new Attribute( 'bold', true ) ];
-		var text = new Text( 'bar', attrs );
+			var attrs = [ new Attribute( 'bold', true ) ];
+			var text = new Text( 'bar', attrs );
 
 
-		expect( text ).to.have.property( 'text' ).that.equals( 'bar' );
-		expect( text ).to.have.property( 'attrs' ).that.is.an( 'array' );
-		expect( text.attrs ).to.be.deep.equals( attrs );
-	} );
+			expect( text ).to.have.property( 'text' ).that.equals( 'bar' );
+			expect( text ).to.have.property( 'attrs' ).that.is.an( 'array' );
+			expect( text.attrs ).to.be.deep.equals( attrs );
+		} );
+	} )
 } );
 } );