Преглед изворни кода

Tests: split one big test to multiple small ones.

Szymon Cofalik пре 9 година
родитељ
комит
3912e70201

+ 84 - 84
packages/ckeditor5-engine/tests/view/domconverter/dom-to-view.js

@@ -221,13 +221,13 @@ describe( 'DomConverter', () => {
 				expect( viewDiv.getChild( 1 ).getChild( 0 ).data ).to.equal( 'fo o' );
 			} );
 
-			it( 'spaces in a text node', () => {
-				function test( inputTexts, output ) {
-					const domElement = createElement( document, 'div', {}, [] );
+			function test( inputTexts, output ) {
+				if ( typeof inputTexts == 'string' ) {
+					inputTexts = [ inputTexts ];
+				}
 
-					if ( typeof inputTexts == 'string' ) {
-						inputTexts = [ inputTexts ];
-					}
+				it( 'spaces in a text node: ' + inputTexts.join( '|' ) + ' -> ' + output, () => {
+					const domElement = createElement( document, 'div', {}, [] );
 
 					for ( let text of inputTexts ) {
 						domElement.appendChild( document.createTextNode( text.replace( /_/g, '\u00A0' ) ) );
@@ -242,84 +242,84 @@ describe( 'DomConverter', () => {
 					}
 
 					expect( data ).to.equal( output );
-				}
-
-				// At the beginning.
-				test( '_x', ' x' );
-				test( '_ x', '  x' );
-				test( '_ _x', '   x' );
-				test( '_ _ x', '    x' );
-
-				// At the end.
-				test( 'x_', 'x ' );
-				test( 'x _', 'x  ' );
-				test( 'x_ _', 'x   ' );
-				test( 'x _ _', 'x    ' );
-
-				// In the middle.
-				test( 'x x', 'x x' );
-				test( 'x _x', 'x  x' );
-				test( 'x _ x', 'x   x' );
-				test( 'x _ _x', 'x    x' );
-
-				// Complex.
-				test( '_x_', ' x ' );
-				test( '_ x _x _', '  x  x  ' );
-				test( '_ _x x _', '   x x  ' );
-				test( '_ _x x_ _', '   x x   ' );
-				test( '_ _x _ _x_', '   x    x ' );
-				test( '_', ' ' );
-
-				// With hard  
-				test( '_x', ' x' );
-				test( '__x', ' _x' );
-				test( '___x', ' __x' );
-				test( '__ x', ' _ x' );
-
-				test( 'x_', 'x ' );
-				test( 'x__', 'x_ ' );
-				test( 'x___', 'x__ ' );
-				// This is an edge case, but it's impossible to write elegant and compact algorithm that is also
-				// 100% correct. We might assume that expected result is `x  _` but it will be converted to `x   `
-				// by the algorithm. This is acceptable, though.
-				test( 'x __', 'x   ' );
-
-				test( 'x_x', 'x_x' );
-				test( 'x___x', 'x___x' );
-				test( 'x____x', 'x____x' );
-				test( 'x__ x', 'x__ x' );
-				test( 'x___ x', 'x___ x' );
-				test( 'x_ _x', 'x_  x' );
-				test( 'x __x', 'x  _x' );
-				test( 'x _ x', 'x   x' );
-				test( 'x __ _x', 'x  _  x' );
-
-				// Two text nodes.
-				test( [ 'x', 'y' ], 'xy' );
-				test( [ 'x ', 'y' ], 'x y' );
-				test( [ 'x _', 'y' ], 'x  y' );
-				test( [ 'x _ ', 'y' ], 'x   y' );
-				test( [ 'x _  _', 'y' ], 'x    y' );
-
-				test( [ 'x', ' y' ], 'x y' );
-				test( [ 'x ', '_y' ], 'x  y' );
-				test( [ 'x_ ', '_y' ], 'x   y' );
-				test( [ 'x _ ', '_y' ], 'x    y' );
-				test( [ 'x_ _ ', '_y' ], 'x     y' );
-
-				test( [ 'x', ' _y' ], 'x  y' );
-				test( [ 'x ', '_ y' ], 'x   y' );
-				test( [ 'x_ ', '_ y' ], 'x    y' );
-				test( [ 'x _ ', '_ y' ], 'x     y' );
-				test( [ 'x_ _ ', '_ y' ], 'x      y' );
-
-				// Some tests with hard  
-				test( [ 'x', '_y' ], 'x_y' );
-				test( [ 'x_', 'y' ], 'x_y' );
-				test( [ 'x_', ' y' ], 'x_ y' );
-				test( [ 'x__', ' y' ], 'x__ y' );
-				test( [ 'x_ _', ' y' ], 'x_   y' );
-			} );
+				} );
+			}
+
+			// At the beginning.
+			test( '_x', ' x' );
+			test( '_ x', '  x' );
+			test( '_ _x', '   x' );
+			test( '_ _ x', '    x' );
+
+			// At the end.
+			test( 'x_', 'x ' );
+			test( 'x _', 'x  ' );
+			test( 'x_ _', 'x   ' );
+			test( 'x _ _', 'x    ' );
+
+			// In the middle.
+			test( 'x x', 'x x' );
+			test( 'x _x', 'x  x' );
+			test( 'x _ x', 'x   x' );
+			test( 'x _ _x', 'x    x' );
+
+			// Complex.
+			test( '_x_', ' x ' );
+			test( '_ x _x _', '  x  x  ' );
+			test( '_ _x x _', '   x x  ' );
+			test( '_ _x x_ _', '   x x   ' );
+			test( '_ _x _ _x_', '   x    x ' );
+			test( '_', ' ' );
+
+			// With hard  
+			test( '_x', ' x' );
+			test( '__x', ' _x' );
+			test( '___x', ' __x' );
+			test( '__ x', ' _ x' );
+
+			test( 'x_', 'x ' );
+			test( 'x__', 'x_ ' );
+			test( 'x___', 'x__ ' );
+			// This is an edge case, but it's impossible to write elegant and compact algorithm that is also
+			// 100% correct. We might assume that expected result is `x  _` but it will be converted to `x   `
+			// by the algorithm. This is acceptable, though.
+			test( 'x __', 'x   ' );
+
+			test( 'x_x', 'x_x' );
+			test( 'x___x', 'x___x' );
+			test( 'x____x', 'x____x' );
+			test( 'x__ x', 'x__ x' );
+			test( 'x___ x', 'x___ x' );
+			test( 'x_ _x', 'x_  x' );
+			test( 'x __x', 'x  _x' );
+			test( 'x _ x', 'x   x' );
+			test( 'x __ _x', 'x  _  x' );
+
+			// Two text nodes.
+			test( [ 'x', 'y' ], 'xy' );
+			test( [ 'x ', 'y' ], 'x y' );
+			test( [ 'x _', 'y' ], 'x  y' );
+			test( [ 'x _ ', 'y' ], 'x   y' );
+			test( [ 'x _  _', 'y' ], 'x    y' );
+
+			test( [ 'x', ' y' ], 'x y' );
+			test( [ 'x ', '_y' ], 'x  y' );
+			test( [ 'x_ ', '_y' ], 'x   y' );
+			test( [ 'x _ ', '_y' ], 'x    y' );
+			test( [ 'x_ _ ', '_y' ], 'x     y' );
+
+			test( [ 'x', ' _y' ], 'x  y' );
+			test( [ 'x ', '_ y' ], 'x   y' );
+			test( [ 'x_ ', '_ y' ], 'x    y' );
+			test( [ 'x _ ', '_ y' ], 'x     y' );
+			test( [ 'x_ _ ', '_ y' ], 'x      y' );
+
+			// Some tests with hard  
+			test( [ 'x', '_y' ], 'x_y' );
+			test( [ 'x_', 'y' ], 'x_y' );
+			test( [ 'x_', ' y' ], 'x_ y' );
+			test( [ 'x__', ' y' ], 'x__ y' );
+			test( [ 'x_ _', ' y' ], 'x_   y' );
 
 			it( 'not in preformatted blocks', () => {
 				const domDiv = createElement( document, 'div', {}, [

+ 93 - 93
packages/ckeditor5-engine/tests/view/domconverter/view-to-dom.js

@@ -241,13 +241,13 @@ describe( 'DomConverter', () => {
 				);
 			} );
 
-			it( 'spaces in a text node', () => {
-				function test( inputTexts, output ) {
-					const viewElement = new ViewContainerElement( 'p' );
+			function test( inputTexts, output ) {
+				if ( typeof inputTexts == 'string' ) {
+					inputTexts = [ inputTexts ];
+				}
 
-					if ( typeof inputTexts == 'string' ) {
-						inputTexts = [ inputTexts ];
-					}
+				it( 'spaces in a text node: ' + inputTexts.join( '|' ) + ' -> ' + output, () => {
+					const viewElement = new ViewContainerElement( 'p' );
 
 					for ( let text of inputTexts ) {
 						viewElement.appendChildren( new ViewText( text.replace( /_/g, '\u00A0' ) ) );
@@ -257,93 +257,93 @@ describe( 'DomConverter', () => {
 					const data = domElement.innerHTML.replace( / /g, '_' );
 
 					expect( data ).to.equal( output );
-				}
-
-				// At the beginning.
-				test( ' x', '_x' );
-				test( '  x', '_ x' );
-				test( '   x', '_ _x' );
-				test( '    x', '_ _ x' );
-
-				// At the end.
-				test( 'x ', 'x_' );
-				test( 'x  ', 'x _' );
-				test( 'x   ', 'x_ _' );
-				test( 'x    ', 'x _ _' );
-
-				// In the middle.
-				test( 'x x', 'x x' );
-				test( 'x  x', 'x _x' );
-				test( 'x   x', 'x _ x' );
-				test( 'x    x', 'x _ _x' );
-
-				// Complex.
-				test( ' x ', '_x_' );
-				test( '  x  x  ', '_ x _x _' );
-				test( '   x x  ', '_ _x x _' );
-				test( '   x x   ', '_ _x x_ _' );
-				test( '   x    x ', '_ _x _ _x_' );
-				test( ' ', '_' );
-
-				// With hard  
-				test( '_x', '_x' );
-				test( ' _x', '__x' );
-				test( '  _x', '_ _x' );
-				test( ' __x', '___x' );
-				test( '___x', '___x' );
-				test( '_ _x', '_ _x' );
-				test( ' _ x', '__ x' );
-				test( '  _x', '_ _x' );
-
-				test( 'x_', 'x_' );
-				test( 'x_ ', 'x__' );
-				test( 'x_  ', 'x_ _' );
-				test( 'x__ ', 'x___' );
-				test( 'x___', 'x___' );
-				test( 'x_ _', 'x_ _' );
-				test( 'x _ ', 'x __' );
-				test( 'x  _', 'x __' );
-
-				test( 'x_x', 'x_x' );
-				test( 'x___x', 'x___x' );
-				test( 'x__ x', 'x__ x' );
-				test( 'x_  x', 'x_ _x' );
-				test( 'x  _x', 'x __x' );
-				test( 'x __x', 'x __x' );
-				test( 'x _ x', 'x _ x' );
-				test( 'x  _  x', 'x __ _x' );
-
-				// Two text nodes.
-				test( [ 'x', 'y' ], 'xy' );
-				test( [ 'x ', 'y' ], 'x y' );
-				test( [ 'x  ', 'y' ], 'x _y' );
-				test( [ 'x   ', 'y' ], 'x _ y' );
-				test( [ 'x    ', 'y' ], 'x _ _y' );
-
-				test( [ 'x', ' y' ], 'x y' );
-				test( [ 'x ', ' y' ], 'x _y' );
-				test( [ 'x  ', ' y' ], 'x_ _y' );
-				test( [ 'x   ', ' y' ], 'x _ _y' );
-				test( [ 'x    ', ' y' ], 'x_ _ _y' );
-
-				test( [ 'x', '_y' ], 'x_y' );
-				test( [ 'x ', '_y' ], 'x _y' );
-				test( [ 'x  ', '_y' ], 'x_ _y' );
-				test( [ 'x   ', '_y' ], 'x _ _y' );
-				test( [ 'x    ', '_y' ], 'x_ _ _y' );
-
-				test( [ 'x', '  y' ], 'x _y' );
-				test( [ 'x ', '  y' ], 'x _ y' );
-				test( [ 'x  ', '  y' ], 'x_ _ y' );
-				test( [ 'x   ', '  y' ], 'x _ _ y' );
-				test( [ 'x    ', '  y' ], 'x_ _ _ y' );
-
-				test( [ 'x', '   y' ], 'x _ y' );
-				test( [ 'x ', '   y' ], 'x _ _y' );
-				test( [ 'x  ', '   y' ], 'x_ _ _y' );
-				test( [ 'x   ', '   y' ], 'x _ _ _y' );
-				test( [ 'x    ', '   y' ], 'x_ _ _ _y' );
-			} );
+				} );
+			}
+
+			// At the beginning.
+			test( ' x', '_x' );
+			test( '  x', '_ x' );
+			test( '   x', '_ _x' );
+			test( '    x', '_ _ x' );
+
+			// At the end.
+			test( 'x ', 'x_' );
+			test( 'x  ', 'x _' );
+			test( 'x   ', 'x_ _' );
+			test( 'x    ', 'x _ _' );
+
+			// In the middle.
+			test( 'x x', 'x x' );
+			test( 'x  x', 'x _x' );
+			test( 'x   x', 'x _ x' );
+			test( 'x    x', 'x _ _x' );
+
+			// Complex.
+			test( ' x ', '_x_' );
+			test( '  x  x  ', '_ x _x _' );
+			test( '   x x  ', '_ _x x _' );
+			test( '   x x   ', '_ _x x_ _' );
+			test( '   x    x ', '_ _x _ _x_' );
+			test( ' ', '_' );
+
+			// With hard  
+			test( '_x', '_x' );
+			test( ' _x', '__x' );
+			test( '  _x', '_ _x' );
+			test( ' __x', '___x' );
+			test( '___x', '___x' );
+			test( '_ _x', '_ _x' );
+			test( ' _ x', '__ x' );
+			test( '  _x', '_ _x' );
+
+			test( 'x_', 'x_' );
+			test( 'x_ ', 'x__' );
+			test( 'x_  ', 'x_ _' );
+			test( 'x__ ', 'x___' );
+			test( 'x___', 'x___' );
+			test( 'x_ _', 'x_ _' );
+			test( 'x _ ', 'x __' );
+			test( 'x  _', 'x __' );
+
+			test( 'x_x', 'x_x' );
+			test( 'x___x', 'x___x' );
+			test( 'x__ x', 'x__ x' );
+			test( 'x_  x', 'x_ _x' );
+			test( 'x  _x', 'x __x' );
+			test( 'x __x', 'x __x' );
+			test( 'x _ x', 'x _ x' );
+			test( 'x  _  x', 'x __ _x' );
+
+			// Two text nodes.
+			test( [ 'x', 'y' ], 'xy' );
+			test( [ 'x ', 'y' ], 'x y' );
+			test( [ 'x  ', 'y' ], 'x _y' );
+			test( [ 'x   ', 'y' ], 'x _ y' );
+			test( [ 'x    ', 'y' ], 'x _ _y' );
+
+			test( [ 'x', ' y' ], 'x y' );
+			test( [ 'x ', ' y' ], 'x _y' );
+			test( [ 'x  ', ' y' ], 'x_ _y' );
+			test( [ 'x   ', ' y' ], 'x _ _y' );
+			test( [ 'x    ', ' y' ], 'x_ _ _y' );
+
+			test( [ 'x', '_y' ], 'x_y' );
+			test( [ 'x ', '_y' ], 'x _y' );
+			test( [ 'x  ', '_y' ], 'x_ _y' );
+			test( [ 'x   ', '_y' ], 'x _ _y' );
+			test( [ 'x    ', '_y' ], 'x_ _ _y' );
+
+			test( [ 'x', '  y' ], 'x _y' );
+			test( [ 'x ', '  y' ], 'x _ y' );
+			test( [ 'x  ', '  y' ], 'x_ _ y' );
+			test( [ 'x   ', '  y' ], 'x _ _ y' );
+			test( [ 'x    ', '  y' ], 'x_ _ _ y' );
+
+			test( [ 'x', '   y' ], 'x _ y' );
+			test( [ 'x ', '   y' ], 'x _ _y' );
+			test( [ 'x  ', '   y' ], 'x_ _ _y' );
+			test( [ 'x   ', '   y' ], 'x _ _ _y' );
+			test( [ 'x    ', '   y' ], 'x_ _ _ _y' );
 
 			it( 'not in preformatted blocks', () => {
 				const viewDiv = new ViewContainerElement( 'pre', null, new ViewText( '   foo   ' ) );