浏览代码

Removed _getAttrCount() and replaced it with getIteratorCount( element.getAttrIterator() ).

Piotr Jasiun 10 年之前
父节点
当前提交
faf3ef210d

+ 0 - 16
packages/ckeditor5-utils/src/document/node.js

@@ -241,22 +241,6 @@ CKEDITOR.define( [ 'document/attribute', 'utils', 'ckeditorerror' ], ( Attribute
 		getAttrIterator() {
 			return this._attrs[ Symbol.iterator ]();
 		}
-
-		/**
-		 * Gets the number of attributes.
-		 *
-		 * @protected
-		 * @returns {Number} Number of attributes.
-		 */
-		_getAttrCount() {
-			let count = 0;
-
-			for ( let attr of this._attrs ) { // jshint ignore:line
-				count++;
-			}
-
-			return count;
-		}
 	}
 
 	return Node;

+ 6 - 2
packages/ckeditor5-utils/tests/document/character.js

@@ -7,8 +7,12 @@
 
 /* bender-tags: document */
 
+/* bender-include: ../_tools/tools.js */
+
 'use strict';
 
+const getIteratorCount = bender.tools.core.getIteratorCount;
+
 const modules = bender.amd.require(
 	'document/character',
 	'document/node',
@@ -34,7 +38,7 @@ describe( 'Character', () => {
 			expect( character ).to.be.an.instanceof( Node );
 			expect( character ).to.have.property( 'character' ).that.equals( 'f' );
 			expect( character ).to.have.property( 'parent' ).that.equals( parent );
-			expect( character._getAttrCount() ).to.equal( 0 );
+			expect( getIteratorCount( character.getAttrIterator() ) ).to.equal( 0 );
 		} );
 
 		it( 'should create character with attributes', () => {
@@ -45,7 +49,7 @@ describe( 'Character', () => {
 			expect( character ).to.be.an.instanceof( Node );
 			expect( character ).to.have.property( 'character' ).that.equals( 'f' );
 			expect( character ).to.have.property( 'parent' ).that.equals( parent );
-			expect( character._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( character.getAttrIterator() ) ).to.equal( 1 );
 			expect( character.getAttr( attr.key ) ).to.equal( attr.value );
 		} );
 	} );

+ 5 - 1
packages/ckeditor5-utils/tests/document/deltas/mergedelta.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/document',
 	'document/position',
@@ -44,7 +48,7 @@ describe( 'Transaction', () => {
 			expect( root.getChildCount() ).to.equal( 1 );
 			expect( root.getChild( 0 ).name ).to.equal( 'p' );
 			expect( root.getChild( 0 ).getChildCount() ).to.equal( 6 );
-			expect( root.getChild( 0 )._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 1 );
 			expect( root.getChild( 0 ).getAttr( 'key1' ) ).to.equal( 'value1' );
 			expect( root.getChild( 0 ).getChild( 0 ).character ).to.equal( 'f' );
 			expect( root.getChild( 0 ).getChild( 1 ).character ).to.equal( 'o' );

+ 8 - 4
packages/ckeditor5-utils/tests/document/deltas/splitdelta.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/document',
 	'document/position',
@@ -44,7 +48,7 @@ describe( 'Transaction', () => {
 
 			expect( root.getChild( 0 ).name ).to.equal( 'p' );
 			expect( root.getChild( 0 ).getChildCount() ).to.equal( 3 );
-			expect( root.getChild( 0 )._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 1 );
 			expect( root.getChild( 0 ).getAttr( 'key' ) ).to.equal( 'value' );
 			expect( root.getChild( 0 ).getChild( 0 ).character ).to.equal( 'f' );
 			expect( root.getChild( 0 ).getChild( 1 ).character ).to.equal( 'o' );
@@ -52,7 +56,7 @@ describe( 'Transaction', () => {
 
 			expect( root.getChild( 1 ).name ).to.equal( 'p' );
 			expect( root.getChild( 1 ).getChildCount() ).to.equal( 3 );
-			expect( root.getChild( 1 )._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( root.getChild( 1 ).getAttrIterator() ) ).to.equal( 1 );
 			expect( root.getChild( 1 ).getAttr( 'key' ) ).to.equal( 'value' );
 			expect( root.getChild( 1 ).getChild( 0 ).character ).to.equal( 'b' );
 			expect( root.getChild( 1 ).getChild( 1 ).character ).to.equal( 'a' );
@@ -66,7 +70,7 @@ describe( 'Transaction', () => {
 
 			expect( root.getChild( 0 ).name ).to.equal( 'p' );
 			expect( root.getChild( 0 ).getChildCount() ).to.equal( 6 );
-			expect( root.getChild( 0 )._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 1 );
 			expect( root.getChild( 0 ).getAttr( 'key' ) ).to.equal( 'value' );
 			expect( root.getChild( 0 ).getChild( 0 ).character ).to.equal( 'f' );
 			expect( root.getChild( 0 ).getChild( 1 ).character ).to.equal( 'o' );
@@ -77,7 +81,7 @@ describe( 'Transaction', () => {
 
 			expect( root.getChild( 1 ).name ).to.equal( 'p' );
 			expect( root.getChild( 1 ).getChildCount() ).to.equal( 0 );
-			expect( root.getChild( 1 )._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( root.getChild( 1 ).getAttrIterator() ) ).to.equal( 1 );
 			expect( root.getChild( 1 ).getAttr( 'key' ) ).to.equal( 'value' );
 		} );
 

+ 6 - 2
packages/ckeditor5-utils/tests/document/element.js

@@ -7,8 +7,12 @@
 
 /* bender-tags: document */
 
+/* bender-include: ../_tools/tools.js */
+
 'use strict';
 
+const getIteratorCount = bender.tools.core.getIteratorCount;
+
 const modules = bender.amd.require(
 	'document/node',
 	'document/nodelist',
@@ -34,7 +38,7 @@ describe( 'Element', () => {
 			expect( element ).to.be.an.instanceof( Node );
 			expect( element ).to.have.property( 'name' ).that.equals( 'elem' );
 			expect( element ).to.have.property( 'parent' ).that.equals( parent );
-			expect( element._getAttrCount() ).to.equal( 0 );
+			expect( getIteratorCount( element.getAttrIterator() ) ).to.equal( 0 );
 		} );
 
 		it( 'should create element with attributes', () => {
@@ -46,7 +50,7 @@ describe( 'Element', () => {
 			expect( element ).to.be.an.instanceof( Node );
 			expect( element ).to.have.property( 'name' ).that.equals( 'elem' );
 			expect( element ).to.have.property( 'parent' ).that.equals( parent );
-			expect( element._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( element.getAttrIterator() ) ).to.equal( 1 );
 			expect( element.getAttr( attr.key ) ).to.equal( attr.value );
 		} );
 

+ 5 - 5
packages/ckeditor5-utils/tests/document/node.js

@@ -107,8 +107,8 @@ describe( 'Node', () => {
 
 			foo.removeAttr( 'attr' );
 
-			expect( foo._getAttrCount() ).to.equal( 0 );
-			expect( bar._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( foo.getAttrIterator() ) ).to.equal( 0 );
+			expect( getIteratorCount( bar.getAttrIterator() ) ).to.equal( 1 );
 		} );
 	} );
 
@@ -136,7 +136,7 @@ describe( 'Node', () => {
 
 			element.setAttr( attr );
 
-			expect( element._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( element.getAttrIterator() ) ).to.equal( 1 );
 			expect( element.getAttr( attr.key ) ).to.equal( attr.value );
 		} );
 
@@ -147,7 +147,7 @@ describe( 'Node', () => {
 
 			element.setAttr( newAttr );
 
-			expect( element._getAttrCount() ).to.equal( 1 );
+			expect( getIteratorCount( element.getAttrIterator() ) ).to.equal( 1 );
 			expect( element.getAttr( newAttr.key ) ).to.equal( newAttr.value );
 		} );
 	} );
@@ -161,7 +161,7 @@ describe( 'Node', () => {
 
 			element.removeAttr( attrB.key );
 
-			expect( element._getAttrCount() ).to.equal( 2 );
+			expect( getIteratorCount( element.getAttrIterator() ) ).to.equal( 2 );
 			expect( element.getAttr( attrA.key ) ).to.equal( attrA.value );
 			expect( element.getAttr( attrC.key ) ).to.equal( attrC.value );
 			expect( element.getAttr( attrB.key ) ).to.be.null;

+ 20 - 16
packages/ckeditor5-utils/tests/document/operation/changeoperation.js

@@ -5,8 +5,12 @@
 
 /* bender-tags: document */
 
+/* bender-include: ../../_tools/tools.js */
+
 'use strict';
 
+const getIteratorCount = bender.tools.core.getIteratorCount;
+
 const modules = bender.amd.require(
 	'document/document',
 	'document/operation/changeoperation',
@@ -59,7 +63,7 @@ describe( 'ChangeOperation', () => {
 		expect( root.getChildCount() ).to.equal( 3 );
 		expect( root.getChild( 0 ).hasAttr( newAttr ) ).to.be.true;
 		expect( root.getChild( 1 ).hasAttr( newAttr ) ).to.be.true;
-		expect( root.getChild( 2 )._getAttrCount() ).to.equal( 0 );
+		expect( getIteratorCount( root.getChild( 2 ).getAttrIterator() ) ).to.equal( 0 );
 	} );
 
 	it( 'should add attribute to the existing attributes', () => {
@@ -80,7 +84,7 @@ describe( 'ChangeOperation', () => {
 
 		expect( doc.version ).to.equal( 1 );
 		expect( root.getChildCount() ).to.equal( 1 );
-		expect( root.getChild( 0 )._getAttrCount() ).to.equal( 3 );
+		expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 3 );
 		expect( root.getChild( 0 ).hasAttr( newAttr ) ).to.be.true;
 		expect( root.getChild( 0 ).hasAttr( fooAttr ) ).to.be.true;
 		expect( root.getChild( 0 ).hasAttr( barAttr ) ).to.be.true;
@@ -103,11 +107,11 @@ describe( 'ChangeOperation', () => {
 
 		expect( doc.version ).to.equal( 1 );
 		expect( root.getChildCount() ).to.equal( 3 );
-		expect( root.getChild( 0 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 0 ).hasAttr( newAttr ) ).to.be.true;
-		expect( root.getChild( 1 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 1 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 1 ).hasAttr( newAttr ) ).to.be.true;
-		expect( root.getChild( 2 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 2 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 2 ).hasAttr( oldAttr ) ).to.be.true;
 	} );
 
@@ -130,7 +134,7 @@ describe( 'ChangeOperation', () => {
 
 		expect( doc.version ).to.equal( 1 );
 		expect( root.getChildCount() ).to.equal( 1 );
-		expect( root.getChild( 0 )._getAttrCount() ).to.equal( 3 );
+		expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 3 );
 		expect( root.getChild( 0 ).hasAttr( fooAttr ) ).to.be.true;
 		expect( root.getChild( 0 ).hasAttr( x2Attr ) ).to.be.true;
 		expect( root.getChild( 0 ).hasAttr( barAttr ) ).to.be.true;
@@ -154,7 +158,7 @@ describe( 'ChangeOperation', () => {
 
 		expect( doc.version ).to.equal( 1 );
 		expect( root.getChildCount() ).to.equal( 1 );
-		expect( root.getChild( 0 )._getAttrCount() ).to.equal( 2 );
+		expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 2 );
 		expect( root.getChild( 0 ).hasAttr( fooAttr ) ).to.be.true;
 		expect( root.getChild( 0 ).hasAttr( barAttr ) ).to.be.true;
 	} );
@@ -192,9 +196,9 @@ describe( 'ChangeOperation', () => {
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.getChildCount() ).to.equal( 3 );
-		expect( root.getChild( 0 )._getAttrCount() ).to.equal( 0 );
-		expect( root.getChild( 1 )._getAttrCount() ).to.equal( 0 );
-		expect( root.getChild( 2 )._getAttrCount() ).to.equal( 0 );
+		expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 0 );
+		expect( getIteratorCount( root.getChild( 1 ).getAttrIterator() ) ).to.equal( 0 );
+		expect( getIteratorCount( root.getChild( 2 ).getAttrIterator() ) ).to.equal( 0 );
 	} );
 
 	it( 'should undo changing attribute by applying reverse operation', () => {
@@ -218,11 +222,11 @@ describe( 'ChangeOperation', () => {
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.getChildCount() ).to.equal( 3 );
-		expect( root.getChild( 0 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 0 ).hasAttr( oldAttr ) ).to.be.true;
-		expect( root.getChild( 1 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 1 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 1 ).hasAttr( oldAttr ) ).to.be.true;
-		expect( root.getChild( 2 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 2 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 2 ).hasAttr( oldAttr ) ).to.be.true;
 	} );
 
@@ -246,11 +250,11 @@ describe( 'ChangeOperation', () => {
 
 		expect( doc.version ).to.equal( 2 );
 		expect( root.getChildCount() ).to.equal( 3 );
-		expect( root.getChild( 0 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 0 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 0 ).hasAttr( fooAttr ) ).to.be.true;
-		expect( root.getChild( 1 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 1 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 1 ).hasAttr( fooAttr ) ).to.be.true;
-		expect( root.getChild( 2 )._getAttrCount() ).to.equal( 1 );
+		expect( getIteratorCount( root.getChild( 2 ).getAttrIterator() ) ).to.equal( 1 );
 		expect( root.getChild( 2 ).hasAttr( fooAttr ) ).to.be.true;
 	} );
 

+ 5 - 1
packages/ckeditor5-utils/tests/document/rootelement.js

@@ -7,8 +7,12 @@
 
 /* bender-tags: document */
 
+/* bender-include: ../_tools/tools.js */
+
 'use strict';
 
+const getIteratorCount = bender.tools.core.getIteratorCount;
+
 const modules = bender.amd.require(
 	'document/document',
 	'document/element',
@@ -31,7 +35,7 @@ describe( 'Element', () => {
 
 			expect( root ).to.be.an.instanceof( Element );
 			expect( root ).to.have.property( 'document' ).that.equals( doc );
-			expect( root._getAttrCount() ).to.equal( 0 );
+			expect( getIteratorCount( root.getAttrIterator() ) ).to.equal( 0 );
 			expect( root.getChildCount() ).to.equal( 0 );
 		} );
 	} );