@@ -69,12 +69,14 @@ describe('Case-specific tests:', () => {
6969	it ( "Check input's hash" ,  ( )  =>  expect ( sha256 ( originalInput ) ) . toBe ( '928c256346d0b16e69cd4c4ddd56e5608335f9ad16d1a25c26a9d8ff4b3e4edf' ) ) 
7070} ) 
7171
72+ const  testsNum  =  allOptions . length 
73+ 
7274afterAll ( ( )  =>  { 
73- 	for  ( let  i  =  0 ;  i  <  allOptions . length ;  ++ i ) 
75+ 	for  ( let  i  =  0 ;  i  <  testsNum ;  ++ i ) 
7476		fs . writeFile ( outputPath ( i ) ,  outputs [ i ] ,  err  =>  { if  ( err )  console . error ( err ) } ) 
7577} ) 
7678
77- for  ( let  testNum  =  0 ;  testNum  <  allOptions . length ;  ++ testNum )  { 
79+ for  ( let  testNum  =  0 ;  testNum  <  testsNum ;  ++ testNum )  { 
7880	const  options  =  allOptions [ testNum ] 
7981	const  textWrap  =  new  TextWrap ( options ) 
8082	const  maxLineLength  =  textWrap . wrapOn 
@@ -138,22 +140,24 @@ for (let testNum = 0; testNum < allOptions.length; ++testNum) {
138140
139141						const  upBound  =  regExp . test ( input )  ? regExp . lastIndex  : input . length 
140142						const  slice  =  indentsN  +  input . slice ( a ,  upBound )  // is not strict in first cycle of the loop that hasn't indentsN 
141- 						const  distance  =  textWrap . getVisualLength ( slice ) 
142143
143- 						expect ( distance ,  `[${ slice } ${ regExp }  ) . toBeGreaterThan ( maxLineLength ) 
144+ 						// WARNING: Due to performance issues, never expose `expect` method outside of an `if` block (that 
145+ 						// checks the test condition) in a loop. 
146+ 						if  ( textWrap . getVisualLength ( slice )  <=  maxLineLength ) 
147+ 							expect ( textWrap . getVisualLength ( slice ) ) . toBeGreaterThan ( maxLineLength ,  `[${ slice } ${ regExp }  ) 
144148
145149						a  =  b 
146150					} 
147151				} ) 
148152
149- 		it ( " Try to find an illegal long line" ,  // A line that should to be wrapped, but hasn't 
153+ 		it ( ' Try to find an illegal long line' ,  // A line that should to be wrapped, but hasn't 
150154				( )  =>  { 
151155					// https://regex101.com/r/4DaiXE/1/ 
152- 					const  regexp  =  new  RegExp ( `^([^\\n]*)(?:(?!\\n)${ bc . source } ${ ec . source }  , 
156+ 					const  regExp  =  new  RegExp ( `^([^\\n]*)(?:(?!\\n)${ bc . source } ${ ec . source }  , 
153157							bc . flags . appendIfNot ( 'g' ) . appendIfNot ( 'm' ) ) 
154158
155159					while  ( true )  { 
156- 						const  match  =  regexp . exec ( output ) 
160+ 						const  match  =  regExp . exec ( output ) 
157161						if  ( match  ===  null )  break 
158162
159163						const  vLen  =  textWrap . getVisualLength ( match [ 0 ] ) 
@@ -163,13 +167,13 @@ for (let testNum = 0; testNum < allOptions.length; ++testNum) {
163167								// Check to sure the line is breakable: 
164168								textWrap . getVisualLength ( match [ 1 ] )  >  textWrap . getVisualLength ( indentsN ) 
165169						) 
166- 							expect ( vLen ,  `[${ match [ 0 ] } ${ regexp } `  ) . toBeLessThanOrEqual ( maxLineLength ) 
170+ 							expect ( vLen ) . toBeLessThanOrEqual ( maxLineLength ,  `[${ match [ 0 ] } ${ regExp } `  ) 
167171					} 
168172				} ) 
169173
170174		// it("Try to find an illegal long line using RegExp", // Same as above but using RegExp. This one is not strict and accurate because can only calculate length, but not vLen (visual-length) 
171175		// 		() => { 
172- 		// 			expect(output).not.toMatch1 ( 
176+ 		// 			expect(output).not.toMatch ( 
173177		// 					// https://regex101.com/r/OfQoDb/1 
174178		// 					new RegExp( 
175179		// 							`^(?=.{${indentsN.length},}[^\\w\\xA0\\n](?![^\\S\\n]|$)).{${maxLineLength},}\\S`, 
@@ -184,24 +188,47 @@ for (let testNum = 0; testNum < allOptions.length; ++testNum) {
184188} 
185189//*************************************************************************************/ 
186190
191+ // noinspection JSUnusedGlobalSymbols 
187192expect . extend ( { 
188- 	toMatch1 ( text : string ,  regExp : RegExp ,  msg : string  |  ( ( )  =>  string ) )  { 
189- 		const  match1  =  regExp . exec ( text ) 
190- 		const  passed  =  match1  !==  null 
191- 		
192- 		const  message  =  ( toClause : ( )  =>  string )  => 
193- 				( )  =>  `Expected the text to ${ toClause ( ) } ${ typeof  msg  ===  'string'  ? msg  : msg ( ) }  
194- 		
195- 		return  passed  ?
193+ 	toBeGreaterThan ( received : number ,  floor : number ,  msg : string  |  ( ( )  =>  string ) )  { 
194+ 		return  received  >  floor  ?
195+ 				{ 
196+ 					message : ( )  =>  `Expected: ${ received } ${ floor } ${ typeof  msg  ===  'string'  ? msg  : msg ( ) }  , 
197+ 					pass : true , 
198+ 				}  :
199+ 				{ 
200+ 					message : ( )  =>  `Expected: ${ received } ${ floor } ${ typeof  msg  ===  'string'  ? msg  : msg ( ) }  , 
201+ 					pass : false , 
202+ 				} 
203+ 	} , 
204+ 	toBeLessThanOrEqual ( received : number ,  roof : number ,  msg : string  |  ( ( )  =>  string ) )  { 
205+ 		return  received  <=  roof  ?
196206				{ 
197- 					message : message ( ( )  =>  `not match  ${ regExp } \nFirst match:\n[ ${ match1 } ]`  ) , 
207+ 					message : ( )  =>  `Expected:  ${ received }  >  ${ roof } \n ${ typeof   msg   ===   'string'  ?  msg  :  msg ( ) } `  , 
198208					pass : true , 
199209				}  :
200210				{ 
201- 					message : message ( ( )  =>  `match  ${ regExp } `  ) , 
211+ 					message : ( )  =>  `Expected:  ${ received }  ≤  ${ roof } \n ${ typeof   msg   ===   'string'  ?  msg  :  msg ( ) } `  , 
202212					pass : false , 
203213				} 
204214	} , 
215+ 	// toMatch(text: string, regExp: RegExp, msg: string | (() => string)) { 
216+ 	// 	const match1 = regExp.exec(text) 
217+ 	// 	const passed = match1 !== null 
218+ 	// 
219+ 	// 	const message = (toClause: () => string) => 
220+ 	// 			() => `Expected the text to ${toClause()}\n${typeof msg === 'string' ? msg : msg()}` 
221+ 	// 
222+ 	// 	return passed ? 
223+ 	// 			{ 
224+ 	// 				message: message(() => `not match ${regExp}\nFirst match:\n[${match1}]`), 
225+ 	// 				pass: true, 
226+ 	// 			} : 
227+ 	// 			{ 
228+ 	// 				message: message(() => `match ${regExp}`), 
229+ 	// 				pass: false, 
230+ 	// 			} 
231+ 	// }, 
205232} ) 
206233
207234String . prototype . appendIfNot  =  function  ( part : string ) : string  { 
@@ -212,7 +239,9 @@ declare global {
212239	namespace  jest  { 
213240		// noinspection JSUnusedGlobalSymbols 
214241		interface  Matchers < R >  { 
215- 			toMatch1 ( regExp : RegExp ,  msg : string ) : R 
242+ 			//toMatch(regExp: RegExp, msg: string | (() => string)): R 
243+ 			toBeGreaterThan ( floor : number ,  msg : string  |  ( ( )  =>  string ) ) : R 
244+ 			toBeLessThanOrEqual ( roof : number ,  msg : string  |  ( ( )  =>  string ) ) : R 
216245		} 
217246	} 
218247
0 commit comments