Browse Source

Introduced bender.tools.core.getIteratorCount.

Piotr Jasiun 10 years ago
parent
commit
d3b24964a1

+ 18 - 0
packages/ckeditor5-ui/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-ui/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 );
+	} );
 } );