diff --git a/test/fixtures/execute/tw-comparison-matrix-inline.sb3 b/test/fixtures/execute/tw-comparison-matrix-inline.sb3 new file mode 100644 index 00000000..6be9e532 Binary files /dev/null and b/test/fixtures/execute/tw-comparison-matrix-inline.sb3 differ diff --git a/test/fixtures/execute/tw-comparison-matrix-runtime.sb3 b/test/fixtures/execute/tw-comparison-matrix-runtime.sb3 new file mode 100644 index 00000000..5d77c0ee Binary files /dev/null and b/test/fixtures/execute/tw-comparison-matrix-runtime.sb3 differ diff --git a/test/fixtures/execute/tw-generate-comparison-matrix-inline.js b/test/fixtures/execute/tw-generate-comparison-matrix-inline.js new file mode 100644 index 00000000..14c97551 --- /dev/null +++ b/test/fixtures/execute/tw-generate-comparison-matrix-inline.js @@ -0,0 +1,136 @@ +const fs = require('fs'); +const Cast = require('../../../src/util/cast'); + +/* +To use output: +Blockly.Xml.domToWorkspace( + new DOMParser().parseFromString(XML_GOES_HERE, 'text/xml').documentElement, + Blockly.getMainWorkspace() +); +*/ + +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);