'use strict'; /* This file is part of ND.JS. * * ND.JS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ND.JS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ND.JS. If not, see . */ const ARRAY_TYPES = [Array, Int8Array, Uint8Array, Uint8ClampedArray, Float32Array, Int16Array, Uint16Array, Float64Array, Int32Array, Uint32Array] const forEachItemIn = items => ({ it: (description, specFn, timeout) => { if( 'string' !== typeof description ) throw new Error('description must be string.') let item, i; const spec = it(description, () => new Promise( (resolve,reject) => { const iter = items[Symbol.iterator]() i=0 const intervalID = setInterval( () => { try { const t0 = performance.now() for(;; i++) { const { value, done } = iter.next() if(done) { console.log(`${i} tests ↴`) clearInterval(intervalID) return resolve() } specFn(item=value) if( 500 < performance.now() - t0 ) return } } catch(err) { clearInterval(intervalID) return reject(err) } }, 0) }), timeout) spec.addExpectationResult = (passed, data, isError) => { if( passed ) return try { if( !passed ) { function toStr(item) { if( ARRAY_TYPES.some( Type => item instanceof Type ) ) { let result if( item.length > 9 ) { const head = Array.from(item.slice(0,4),toStr).join(), tail = Array.from(item.slice( -4),toStr).join() result = `${head}, ..., ${item.length-8} more ..., ${tail}` } else { result = Array.from(item,toStr).join() } return item instanceof Array ? `[${result}]` : `${item.constructor.name}.of(${result})` } return 'string' === typeof item ? `"${item}"` : `${item}` } function msg( msg ) { if( msg.length > 0 ) msg = msg.slice(0,1).toLowerCase() + msg.slice(1) return `For item[${i}] = ${toStr(item)}: ${msg}` } if( 'message' in data ) data .message = msg(data .message) else data.error.message = msg(data.error.message) } } catch(err) { console.error(err) } finally { Object.getPrototypeOf(spec).addExpectationResult.call(spec, passed, data, isError) } }; return spec; } });