Explorar el Código

Moved treemodel's test utils to a separate file and added basic test.

Piotrek Koszuliński hace 10 años
padre
commit
a4d4215325

+ 0 - 30
packages/ckeditor5-engine/tests/_utils/utils.js

@@ -65,34 +65,4 @@ const utils = {
 	}
 };
 
-utils.treemodel = {
-	/**
-	 * Returns tree structure as a simplified string. Elements are uppercase and characters are lowercase.
-	 * Start and end of an element is marked the same way, by the element's name (in uppercase).
-	 *
-	 *		let element = new Element( 'div', [], [ 'abc', new Element( 'p', [], 'foo' ), 'xyz' ] );
-	 *		treemodelUtils.getNodesAndText( element ); // abcPfooPxyz
-	 *
-	 * @param {treeModel.Range} range Range to stringify.
-	 * @returns {String} String representing element inner structure.
-	 */
-	getNodesAndText( range ) {
-		console.error( 'This should be moved to ckeditor5-core/tests/treemodel/_utils/' ); /* jshint ignore:line */
-
-		let txt = '';
-
-		for ( let step of range ) {
-			let node = step.node;
-
-			if ( node.character ) {
-				txt += node.character.toLowerCase();
-			} else if ( node.name ) {
-				txt += node.name.toUpperCase();
-			}
-		}
-
-		return txt;
-	}
-};
-
 export default utils;

+ 36 - 0
packages/ckeditor5-engine/tests/treemodel/_utils/utils.js

@@ -0,0 +1,36 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+const utils = {
+	/**
+	 * Returns tree structure as a simplified string. Elements are uppercase and characters are lowercase.
+	 * Start and end of an element is marked the same way, by the element's name (in uppercase).
+	 *
+	 *		let element = new Element( 'div', [], [ 'abc', new Element( 'p', [], 'foo' ), 'xyz' ] );
+	 *		treemodelUtils.getNodesAndText( element ); // abcPfooPxyz
+	 *
+	 * @param {treeModel.Range} range Range to stringify.
+	 * @returns {String} String representing element inner structure.
+	 */
+	getNodesAndText( range ) {
+		let txt = '';
+
+		for ( let step of range ) {
+			let node = step.node;
+
+			if ( node.character ) {
+				txt += node.character.toLowerCase();
+			} else if ( node.name ) {
+				txt += node.name.toUpperCase();
+			}
+		}
+
+		return txt;
+	}
+};
+
+export default utils;

+ 2 - 2
packages/ckeditor5-engine/tests/treemodel/delta/movedelta.js

@@ -7,14 +7,14 @@
 
 'use strict';
 
-import coreTestUtils from '/tests/core/_utils/utils.js';
+import treeModelTestUtils from '/tests/core/treemodel/_utils/utils.js';
 import Document from '/ckeditor5/core/treemodel/document.js';
 import Position from '/ckeditor5/core/treemodel/position.js';
 import Range from '/ckeditor5/core/treemodel/range.js';
 import Element from '/ckeditor5/core/treemodel/element.js';
 import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
 
-const getNodesAndText = coreTestUtils.treemodel.getNodesAndText;
+const getNodesAndText = treeModelTestUtils.getNodesAndText;
 
 describe( 'Batch', () => {
 	let doc, root, div, p, batch, chain;

+ 2 - 2
packages/ckeditor5-engine/tests/treemodel/delta/removedelta.js

@@ -7,13 +7,13 @@
 
 'use strict';
 
-import coreTestUtils from '/tests/core/_utils/utils.js';
+import treeModelTestUtils from '/tests/core/treemodel/_utils/utils.js';
 import Document from '/ckeditor5/core/treemodel/document.js';
 import Position from '/ckeditor5/core/treemodel/position.js';
 import Range from '/ckeditor5/core/treemodel/range.js';
 import Element from '/ckeditor5/core/treemodel/element.js';
 
-const getNodesAndText = coreTestUtils.treemodel.getNodesAndText;
+const getNodesAndText = treeModelTestUtils.getNodesAndText;
 
 describe( 'Batch', () => {
 	let doc, root, div, p, batch, chain, range;

+ 31 - 0
packages/ckeditor5-engine/tests/treemodel/utils-tests/utils.js

@@ -0,0 +1,31 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+'use strict';
+
+import treeModelTestUtils from '/tests/core/treemodel/_utils/utils.js';
+import Document from '/ckeditor5/core/treemodel/document.js';
+import Range from '/ckeditor5/core/treemodel/range.js';
+import Element from '/ckeditor5/core/treemodel/element.js';
+
+const getNodesAndText = treeModelTestUtils.getNodesAndText;
+
+describe( 'getNodesAndText', () => {
+	let doc, root, div, p;
+
+	beforeEach( () => {
+		doc = new Document();
+		root = doc.createRoot( 'root' );
+
+		div = new Element( 'div', [], 'foobar' );
+		p = new Element( 'p', [], 'abcxyz' );
+
+		root.insertChildren( 0, [ div, p ] );
+	} );
+
+	it( 'reads two elements with text', () => {
+		expect( getNodesAndText( Range.createFromElement( root ) ) ).to.equal( 'DIVfoobarDIVPabcxyzP' );
+	} );
+} );