Includes scratch-gui, scratch-vm, scratch-blocks, scratch-render, scratch-l10n, and deployment config. Co-authored-by: Cursor <cursoragent@cursor.com>
141 lines
4.2 KiB
JavaScript
141 lines
4.2 KiB
JavaScript
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 = `
|
|
<xml>
|
|
<block type="event_whenflagclicked">
|
|
<next>
|
|
<block type="looks_say">
|
|
<value name="MESSAGE">
|
|
<shadow type="text">
|
|
<field name="TEXT">plan 0</field>
|
|
</shadow>
|
|
</value>
|
|
${NEXT}
|
|
</block>
|
|
</next>
|
|
</block>
|
|
</xml>
|
|
`;
|
|
|
|
let n = 0;
|
|
for (const i of VALUES) {
|
|
for (const j of VALUES) {
|
|
for (const operator of OPERATORS) {
|
|
n++;
|
|
result = result.replace(NEXT, `
|
|
<next>
|
|
<block type="control_if">
|
|
<value name="CONDITION">
|
|
<block type="operator_not">
|
|
<value name="OPERAND">
|
|
<block type="operator_equals">
|
|
<value name="OPERAND1">
|
|
<shadow type="text">
|
|
<field name="TEXT"></field>
|
|
</shadow>
|
|
<block type="${operator.opcode}">
|
|
<value name="OPERAND1">
|
|
<shadow type="text">
|
|
<field name="TEXT">${i}</field>
|
|
</shadow>
|
|
</value>
|
|
<value name="OPERAND2">
|
|
<shadow type="text">
|
|
<field name="TEXT">${j}</field>
|
|
</shadow>
|
|
</value>
|
|
</block>
|
|
</value>
|
|
<value name="OPERAND2">
|
|
<shadow type="text">
|
|
<field name="TEXT">${operator.execute(i, j)}</field>
|
|
</shadow>
|
|
</value>
|
|
</block>
|
|
</value>
|
|
</block>
|
|
</value>
|
|
<statement name="SUBSTACK">
|
|
<block type="looks_say">
|
|
<value name="MESSAGE">
|
|
<shadow type="text">
|
|
<field name="TEXT">fail ${n}: ${i} should be ${operator.symbol} ${j}</field>
|
|
</shadow>
|
|
</value>
|
|
</block>
|
|
</statement>
|
|
${NEXT}
|
|
</block>
|
|
</next>
|
|
`.replace(/ {4}/g, ' '));
|
|
}
|
|
}
|
|
}
|
|
|
|
result = result.replace(NEXT, `
|
|
<next>
|
|
<block type="looks_say">
|
|
<value name="MESSAGE">
|
|
<shadow type="text">
|
|
<field name="TEXT">end</field>
|
|
</shadow>
|
|
</value>
|
|
</block>
|
|
</next>
|
|
`);
|
|
|
|
result = result.replace(NEXT, '');
|
|
|
|
console.log(`Expecting ${n}`);
|
|
fs.writeFileSync('matrix-inline-output-do-not-commit.xml', result);
|