8
0
Просмотр исходного кода

Introduced bender.tools.core.getIteratorCount.

Piotr Jasiun 10 лет назад
Родитель
Сommit
9e8908b0ff

+ 18 - 0
packages/ckeditor5-engine/tests/_tools/tools.js

@@ -47,6 +47,24 @@
 
 				return TestCreator;
 			}
+		},
+
+		/**
+		 * Returns the number of elements return by the iterator.
+		 *
+		 *	  bender.tools.core.getIteratorCount( [ 1, 2, 3, 4, 5 ] ); // 5;
+		 *
+		 * @param {Iterable.<*>} iterator Any iterator.
+		 * @returns {Number} Number of elements returned by that iterator.
+		 */
+		getIteratorCount: ( iterator ) => {
+			let count = 0;
+
+			for ( let _ of iterator ) { // jshint ignore:line
+				count++;
+			}
+
+			return count;
 		}
 	};
 } )();

+ 7 - 0
packages/ckeditor5-engine/tests/bender/tools.js

@@ -57,4 +57,11 @@ describe( 'bender.tools.core.defineEditorCreatorMock()', () => {
 		expect( TestCreator3.prototype ).to.have.property( 'create', createFn3 );
 		expect( TestCreator3.prototype ).to.have.property( 'destroy', destroyFn3 );
 	} );
+} );
+
+describe( 'bender.tools.core.getIteratorCount()', () => {
+	it( 'should returns number of editable items ', () => {
+		const count = bender.tools.core.getIteratorCount( [ 1, 2, 3, 4, 5 ] );
+		expect( count ).to.equal( 5 );
+	} );
 } );

+ 7 - 7
packages/ckeditor5-engine/tests/document/deltas/changedelta.js

@@ -5,8 +5,12 @@
 
 /* bender-tags: document, delta */
 
+/* bender-include: ../../_tools/tools.js */
+
 'use strict';
 
+const getIteratorCount = bender.tools.core.getIteratorCount;
+
 const modules = bender.amd.require(
 	'document/transaction',
 	'document/document',
@@ -56,9 +60,7 @@ describe( 'Transaction', () => {
 		let count = 0;
 
 		for ( let delta of transaction ) {
-			for ( let operation of delta ) {
-				count++;
-			}
+			count += getIteratorCount( delta );
 		}
 
 		return count;
@@ -69,9 +71,7 @@ describe( 'Transaction', () => {
 
 		for ( let delta of transaction ) {
 			for ( let operation of delta ) {
-				for ( let value of operation.range ) {
-					count++;
-				}
+				count += getIteratorCount( operation.range );
 			}
 		}
 
@@ -81,6 +81,7 @@ describe( 'Transaction', () => {
 	function getCompressedAttrs() {
 		// default: 111---111222---111
 		const range = Range.createFromElement( root );
+
 		return Array.from( range ).map( value => value.node.getAttr( 'a' ) || '-' ).join( '' );
 	}
 
@@ -134,7 +135,6 @@ describe( 'Transaction', () => {
 		} );
 	} );
 
-
 	describe( 'removeAttr', () => {
 		it( 'should remove the attribute on the range', () => {
 			transaction.removeAttr( 'a', getRange( 0, 2 ) );