const fs = require('fs'); const Cast = require('../../../src/util/cast'); /* This is a command-line tool to generate the tw-comparison-matrix-inline test project. To use output: Blockly.Xml.domToWorkspace( new DOMParser().parseFromString(XML_GOES_HERE, 'text/xml').documentElement, Blockly.getMainWorkspace() ); */ /* eslint-disable no-console */ const VALUES = [ '0', '0.0', '1.23', '.23', '0.123', '-0', '-1', 'true', 'false', 'NaN', 'Infinity', 'banana', '🎉', '' ]; const OPERATORS = [ { opcode: 'operator_lt', symbol: '<', execute: (a, b) => Cast.compare(a, b) < 0 }, { opcode: 'operator_equals', symbol: '=', execute: (a, b) => Cast.compare(a, b) === 0 }, { opcode: 'operator_gt', symbol: '>', execute: (a, b) => Cast.compare(a, b) > 0 } ]; const NEXT = '{{NEXT}}'; let result = ` plan 0 ${NEXT} `; let n = 0; for (const i of VALUES) { for (const j of VALUES) { for (const operator of OPERATORS) { n++; result = result.replace(NEXT, ` ${i} ${j} ${operator.execute(i, j)} fail ${n}: ${i} should be ${operator.symbol} ${j} ${NEXT} `.replace(/ {4}/g, ' ')); } } } result = result.replace(NEXT, ` end `); result = result.replace(NEXT, ''); console.log(`Expecting ${n}`); fs.writeFileSync('matrix-inline-output-do-not-commit.xml', result);