diff options
Diffstat (limited to 'blockly/tests')
28 files changed, 21459 insertions, 0 deletions
diff --git a/blockly/tests/generators/colour.xml b/blockly/tests/generators/colour.xml new file mode 100644 index 0000000..bae853d --- /dev/null +++ b/blockly/tests/generators/colour.xml @@ -0,0 +1,261 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="procedures_defnoreturn" x="260" y="14"> + <field name="NAME">test colour picker</field> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">static colour</field> + </block> + </value> + <value name="ACTUAL"> + <block type="colour_picker"> + <field name="COLOUR">#ff6600</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">#ff6600</field> + </block> + </value> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="630" y="13"> + <field name="NAME">test rgb</field> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">from rgb</field> + </block> + </value> + <value name="ACTUAL"> + <block type="colour_rgb" inline="false"> + <value name="RED"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + <value name="GREEN"> + <block type="math_number"> + <field name="NUM">40</field> + </block> + </value> + <value name="BLUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">#ff6600</field> + </block> + </value> + </block> + </statement> + </block> + <block type="unittest_main" x="-5" y="49"> + <statement name="DO"> + <block type="procedures_callnoreturn"> + <mutation name="test colour picker"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test blend"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test rgb"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test colour random"></mutation> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="-7" y="223"> + <field name="NAME">test colour random</field> + <statement name="STACK"> + <block type="controls_repeat_ext" inline="true"> + <value name="TIMES"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + <statement name="DO"> + <block type="variables_set" inline="false"> + <field name="VAR">item</field> + <value name="VALUE"> + <block type="colour_random"></block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">test name</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">item</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">7</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">test name</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">item</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">#</field> + </block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">i</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">7</field> + </block> + </value> + <statement name="DO"> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">test name</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">NEQ</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="text_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">abcdefABDEF0123456789</field> + </block> + </value> + <value name="FIND"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">item</field> + </block> + </value> + <value name="AT"> + <block type="variables_get"> + <field name="VAR">i</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </statement> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="520" y="205"> + <field name="NAME">test blend</field> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">blend</field> + </block> + </value> + <value name="ACTUAL"> + <block type="colour_blend" inline="false"> + <value name="COLOUR1"> + <block type="colour_picker"> + <field name="COLOUR">#ff0000</field> + </block> + </value> + <value name="COLOUR2"> + <block type="colour_rgb" inline="false"> + <value name="RED"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + <value name="GREEN"> + <block type="math_number"> + <field name="NUM">40</field> + </block> + </value> + <value name="BLUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="RATIO"> + <block type="math_number"> + <field name="NUM">0.4</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">#ff2900</field> + </block> + </value> + </block> + </statement> + </block> +</xml> diff --git a/blockly/tests/generators/functions.xml b/blockly/tests/generators/functions.xml new file mode 100644 index 0000000..b189ed3 --- /dev/null +++ b/blockly/tests/generators/functions.xml @@ -0,0 +1,559 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="0" y="1"> + <statement name="DO"> + <block type="procedures_callnoreturn"> + <mutation name="test procedure"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test function"></mutation> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">test recurse</field> + </block> + </value> + <value name="ACTUAL"> + <block type="procedures_callreturn" inline="false"> + <mutation name="recurse"> + <arg name="n"></arg> + </mutation> + <value name="ARG0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">-1-2-1-3-1-2-1-</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="-3" y="249"> + <field name="NAME">test procedure</field> + <statement name="STACK"> + <block type="procedures_callnoreturn" inline="false"> + <mutation name="procedure 1"> + <arg name="proc x"></arg> + <arg name="proc y"></arg> + </mutation> + <value name="ARG0"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="ARG1"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">procedure with global</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">proc z</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">proc w</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="false"> + <mutation name="procedure 2"> + <arg name="proc x"></arg> + </mutation> + <value name="ARG0"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">procedure no return</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">proc w</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">proc w</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="false"> + <mutation name="procedure 2"> + <arg name="proc x"></arg> + </mutation> + <value name="ARG0"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">procedure return</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">proc w</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="302" y="277"> + <mutation> + <arg name="proc x"></arg> + <arg name="proc y"></arg> + </mutation> + <field name="NAME">procedure 1</field> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">proc z</field> + <value name="VALUE"> + <block type="math_arithmetic"> + <field name="OP">DIVIDE</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">proc x</field> + </block> + </value> + <value name="B"> + <block type="variables_get"> + <field name="VAR">proc y</field> + </block> + </value> + </block> + </value> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="307" y="435"> + <mutation> + <arg name="proc x"></arg> + </mutation> + <field name="NAME">procedure 2</field> + <statement name="STACK"> + <block type="procedures_ifreturn"> + <mutation value="0"></mutation> + <value name="CONDITION"> + <block type="variables_get"> + <field name="VAR">proc x</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">proc w</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="-2" y="731"> + <field name="NAME">test function</field> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">function with arguments</field> + </block> + </value> + <value name="ACTUAL"> + <block type="procedures_callreturn" inline="false"> + <mutation name="function 1"> + <arg name="func x"></arg> + <arg name="func y"></arg> + </mutation> + <value name="ARG0"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <value name="ARG1"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">function with side effect</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">func z</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">side effect</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">func a</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">unchanged</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">func c</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">global</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">function with global</field> + </block> + </value> + <value name="ACTUAL"> + <block type="procedures_callreturn" inline="false"> + <mutation name="function 2"> + <arg name="func a"></arg> + </mutation> + <value name="ARG0"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">3global</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">function with scope</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">func a</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">unchanged</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">function return</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="procedures_callreturn" inline="false"> + <mutation name="function 3"> + <arg name="func a"></arg> + </mutation> + <value name="ARG0"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">function no return</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="procedures_callreturn" inline="false"> + <mutation name="function 3"> + <arg name="func a"></arg> + </mutation> + <value name="ARG0"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" inline="false" x="-3" y="1384"> + <mutation> + <arg name="func x"></arg> + <arg name="func y"></arg> + </mutation> + <field name="NAME">function 1</field> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">func z</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">side effect</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="math_arithmetic"> + <field name="OP">MINUS</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">func x</field> + </block> + </value> + <value name="B"> + <block type="variables_get"> + <field name="VAR">func y</field> + </block> + </value> + </block> + </value> + </block> + <block type="procedures_defreturn" inline="false" x="-1" y="1503"> + <mutation> + <arg name="func a"></arg> + </mutation> + <field name="NAME">function 2</field> + <statement name="STACK"> + <block type="math_change" inline="false"> + <field name="VAR">func a</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="text_join" inline="false"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="variables_get"> + <field name="VAR">func a</field> + </block> + </value> + <value name="ADD1"> + <block type="variables_get"> + <field name="VAR">func c</field> + </block> + </value> + </block> + </value> + </block> + <block type="procedures_defreturn" inline="false" x="0" y="1655"> + <mutation> + <arg name="func a"></arg> + </mutation> + <field name="NAME">function 3</field> + <statement name="STACK"> + <block type="procedures_ifreturn"> + <mutation value="1"></mutation> + <value name="CONDITION"> + <block type="variables_get"> + <field name="VAR">func a</field> + </block> + </value> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + </block> + <block type="procedures_defreturn" inline="false" x="0" y="1789"> + <mutation> + <arg name="n"></arg> + </mutation> + <field name="NAME">recurse</field> + <statement name="STACK"> + <block type="controls_if" inline="false"> + <mutation else="1"></mutation> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">n</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="variables_set" inline="false"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text_join" inline="false"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="procedures_callreturn" inline="false"> + <mutation name="recurse"> + <arg name="n"></arg> + </mutation> + <value name="ARG0"> + <block type="math_arithmetic"> + <field name="OP">MINUS</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">n</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="ADD1"> + <block type="variables_get"> + <field name="VAR">n</field> + </block> + </value> + <value name="ADD2"> + <block type="procedures_callreturn" inline="false"> + <mutation name="recurse"> + <arg name="n"></arg> + </mutation> + <value name="ARG0"> + <block type="math_arithmetic"> + <field name="OP">MINUS</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">n</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </statement> + <statement name="ELSE"> + <block type="variables_set" inline="false"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">-</field> + </block> + </value> + </block> + </statement> + </block> + </statement> + <value name="RETURN"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> +</xml> diff --git a/blockly/tests/generators/index.html b/blockly/tests/generators/index.html new file mode 100644 index 0000000..d227f60 --- /dev/null +++ b/blockly/tests/generators/index.html @@ -0,0 +1,345 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>Blockly Generator Tests</title> +<script src="../../blockly_uncompressed.js"></script> + +<script src="../../generators/javascript.js"></script> +<script src="unittest_javascript.js"></script> +<script src="../../generators/javascript/logic.js"></script> +<script src="../../generators/javascript/loops.js"></script> +<script src="../../generators/javascript/math.js"></script> +<script src="../../generators/javascript/text.js"></script> +<script src="../../generators/javascript/lists.js"></script> +<script src="../../generators/javascript/colour.js"></script> +<script src="../../generators/javascript/variables.js"></script> +<script src="../../generators/javascript/procedures.js"></script> + +<script src="../../generators/python.js"></script> +<script src="unittest_python.js"></script> +<script src="../../generators/python/logic.js"></script> +<script src="../../generators/python/loops.js"></script> +<script src="../../generators/python/math.js"></script> +<script src="../../generators/python/text.js"></script> +<script src="../../generators/python/lists.js"></script> +<script src="../../generators/python/colour.js"></script> +<script src="../../generators/python/variables.js"></script> +<script src="../../generators/python/procedures.js"></script> + +<script src="../../generators/php.js"></script> +<script src="unittest_php.js"></script> +<script src="../../generators/php/logic.js"></script> +<script src="../../generators/php/loops.js"></script> +<script src="../../generators/php/math.js"></script> +<script src="../../generators/php/text.js"></script> +<script src="../../generators/php/lists.js"></script> +<script src="../../generators/php/colour.js"></script> +<script src="../../generators/php/variables.js"></script> +<script src="../../generators/php/procedures.js"></script> + +<script src="../../generators/lua.js"></script> +<script src="unittest_lua.js"></script> +<script src="../../generators/lua/logic.js"></script> +<script src="../../generators/lua/loops.js"></script> +<script src="../../generators/lua/math.js"></script> +<script src="../../generators/lua/text.js"></script> +<script src="../../generators/lua/lists.js"></script> +<script src="../../generators/lua/colour.js"></script> +<script src="../../generators/lua/variables.js"></script> +<script src="../../generators/lua/procedures.js"></script> + +<script src="../../generators/dart.js"></script> +<script src="unittest_dart.js"></script> +<script src="../../generators/dart/logic.js"></script> +<script src="../../generators/dart/loops.js"></script> +<script src="../../generators/dart/math.js"></script> +<script src="../../generators/dart/text.js"></script> +<script src="../../generators/dart/lists.js"></script> +<script src="../../generators/dart/colour.js"></script> +<script src="../../generators/dart/variables.js"></script> +<script src="../../generators/dart/procedures.js"></script> + +<script src="unittest.js"></script> +<script src="../../msg/messages.js"></script> +<script src="../../blocks/logic.js"></script> +<script src="../../blocks/loops.js"></script> +<script src="../../blocks/math.js"></script> +<script src="../../blocks/text.js"></script> +<script src="../../blocks/lists.js"></script> +<script src="../../blocks/colour.js"></script> +<script src="../../blocks/variables.js"></script> +<script src="../../blocks/procedures.js"></script> +<script> +'use strict'; + +var workspace = null; + +function start() { + workspace = Blockly.inject('blocklyDiv', + {grid: + {spacing: 25, + length: 3, + colour: '#ccc', + snap: true}, + media: '../../media/', + toolbox: document.getElementById('toolbox'), + zoom: {controls: true, wheel: true} + }); +} + +function loadXml() { + var dropdown = document.getElementById('testUrl'); + var url = dropdown.options[dropdown.selectedIndex].value; + if (!url) { + url = window.prompt('Enter URL of test file.'); + if (!url) { + return; + } + } + var xmlText = fetchFile(url); + if (xmlText !== null) { + fromXml(xmlText); + } +} + +function fetchFile(xmlUrl) { + try { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.open('GET', xmlUrl, false); + xmlHttp.setRequestHeader('Content-Type', 'text/xml'); + xmlHttp.send(''); + } catch (e) { + // Attempt to diagnose the problem. + var msg = 'Error: Unable to load XML data.\n'; + if (window.location.protocol == 'file:') { + msg += 'This may be due to a security restriction preventing\n' + + 'access when using the file:// protocol.\n' + + 'Use an http webserver, or a less paranoid browser.\n'; + } + alert(msg + '\n' + e); + return null; + } + return xmlHttp.responseText; +} + +function fromXml(xmlText) { + var output = document.getElementById('importExport'); + output.value = xmlText; + output.scrollTop = 0; + output.scrollLeft = 0; + workspace.clear(); + try { + var xmlDoc = Blockly.Xml.textToDom(xmlText); + } catch (e) { + alert('Error parsing XML:\n' + e); + return; + } + Blockly.Xml.domToWorkspace(xmlDoc, workspace); +} + +function setOutput(text) { + var output = document.getElementById('importExport'); + output.value = text; + output.focus(); + output.select(); +} + +function toXml() { + var xmlDom = Blockly.Xml.workspaceToDom(workspace); + var xmlText = Blockly.Xml.domToPrettyText(xmlDom); + xmlText = xmlText.replace(/ id="\d+"/g, ''); + setOutput(xmlText); +} + +function toJavaScript() { + var oneBasedIndexing = document.getElementById('indexing').checked; + Blockly.JavaScript.ONE_BASED_INDEXING = oneBasedIndexing; + var code = '\'use strict\';\n\n' + code += Blockly.JavaScript.workspaceToCode(workspace); + setOutput(code); +} + +function toPython() { + var oneBasedIndexing = document.getElementById('indexing').checked; + Blockly.Python.ONE_BASED_INDEXING = oneBasedIndexing; + var code = Blockly.Python.workspaceToCode(workspace); + setOutput(code); +} + +function toPhp() { + var oneBasedIndexing = document.getElementById('indexing').checked; + Blockly.PHP.ONE_BASED_INDEXING = oneBasedIndexing; + var code = Blockly.PHP.workspaceToCode(workspace); + setOutput(code); +} + +function toLua() { + var code = Blockly.Lua.workspaceToCode(workspace); + setOutput(code); +} + +function toDart() { + var oneBasedIndexing = document.getElementById('indexing').checked; + Blockly.Dart.ONE_BASED_INDEXING = oneBasedIndexing; + var code = Blockly.Dart.workspaceToCode(workspace); + setOutput(code); +} +</script> + +<style> +html, body { + height: 100%; + overflow: hidden; +} +body { + background-color: #fff; + font-family: sans-serif; + margin: 0 5px; +} +h1 { + font-weight: normal; + font-size: 140%; +} +#blocklyDiv { + float: right; + height: 95%; + width: 69%; + margin-top: 5px; +} +#importExport { + height: 100%; + width: 100%; +} +</style> +</head> +<body onload="start()"> + + <div id="blocklyDiv"></div> + + <xml id="toolbox" style="display: none"> + <category name="Unit test" colour="65"> + <block type="unittest_main"></block> + <block type="unittest_assertequals"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + </block> + <block type="unittest_assertvalue"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + </block> + <block type="unittest_fail"></block> + <block type="unittest_adjustindex"></block> + </category> + <category name="Logic" colour="210"> + <block type="controls_if"></block> + <block type="logic_compare"></block> + <block type="logic_operation"></block> + <block type="logic_negate"></block> + <block type="logic_boolean"></block> + <block type="logic_null"></block> + <block type="logic_ternary"></block> + </category> + <category name="Loops" colour="120"> + <block type="controls_repeat_ext"></block> + <block type="controls_whileUntil"></block> + <block type="controls_for"></block> + <block type="controls_forEach"></block> + <block type="controls_flow_statements"></block> + </category> + <category name="Math" colour="230"> + <block type="math_number"></block> + <block type="math_arithmetic"></block> + <block type="math_single"></block> + <block type="math_trig"></block> + <block type="math_constant"></block> + <block type="math_number_property"></block> + <block type="math_round"></block> + <block type="math_on_list"></block> + <block type="math_modulo"></block> + <block type="math_constrain"></block> + <block type="math_random_int"></block> + <block type="math_random_float"></block> + </category> + <category name="Text" colour="160"> + <block type="text"></block> + <block type="text_join"></block> + <block type="text_append"></block> + <block type="text_length"></block> + <block type="text_isEmpty"></block> + <block type="text_indexOf"></block> + <block type="text_charAt"></block> + <block type="text_getSubstring"></block> + <block type="text_changeCase"></block> + <block type="text_trim"></block> + <block type="text_print"></block> + <block type="text_prompt_ext"></block> + </category> + <category name="Lists" colour="260"> + <block type="lists_create_empty"></block> + <block type="lists_create_with"></block> + <block type="lists_repeat"></block> + <block type="lists_length"></block> + <block type="lists_isEmpty"></block> + <block type="lists_indexOf"></block> + <block type="lists_getIndex"></block> + <block type="lists_setIndex"></block> + <block type="lists_getSublist"></block> + <block type="lists_sort"></block> + <block type="lists_split"></block> + </category> + <category name="Colour" colour="20"> + <block type="colour_picker"></block> + <block type="colour_random"></block> + <block type="colour_rgb"></block> + <block type="colour_blend"></block> + </category> + <sep></sep> + <category name="Variables" colour="330" custom="VARIABLE"></category> + <category name="Functions" colour="290" custom="PROCEDURE"></category> + </xml> + + <table height="95%" width="30%"><tr><td valign="top"> + <h1>Blockly Generator Tests</h1> + + <p> + <select id="testUrl"> + <option value="logic.xml">Logic</option> + <option value="loops1.xml">Loops 1 (repeat, while, foreach)</option> + <option value="loops2.xml">Loops 2 (count)</option> + <option value="loops3.xml">Loops 3 (continue, break)</option> + <option value="math.xml">Math</option> + <option value="text.xml">Text</option> + <option value="lists.xml">Lists</option> + <option value="colour.xml">Colour</option> + <option value="variables.xml">Variables</option> + <option value="functions.xml">Functions</option> + <option value="">Other...</option> + </select> + <input type="button" value="Load" onclick="loadXml()"> + </p> + + <p> + <input id="indexing" type="checkbox" checked> Generate with one-based indexing + </p> + + <p> + Generate: + <input type="button" value="XML" onclick="toXml()"> + <input type="button" value="JavaScript" onclick="toJavaScript()"> + <input type="button" value="Python" onclick="toPython()"> + <input type="button" value="PHP" onclick="toPhp()"> + <input type="button" value="Lua" onclick="toLua()"> + <input type="button" value="Dart" onclick="toDart()"> + </p> + </td></tr><tr><td height="99%"> + <textarea id="importExport" readonly="readonly" wrap="off"></textarea> + </td></tr></table> +</body> +</html> diff --git a/blockly/tests/generators/lists.xml b/blockly/tests/generators/lists.xml new file mode 100644 index 0000000..88e4946 --- /dev/null +++ b/blockly/tests/generators/lists.xml @@ -0,0 +1,8134 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="13" y="13"> + <statement name="DO"> + <block type="procedures_callnoreturn"> + <mutation name="test create"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test empty"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test length"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test find simple"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test find complex"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test get simple"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test get complex"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test getRemove"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test remove"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test set"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test insert"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test sublist simple"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test sublist complex"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test join"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test split"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test sort alphabetic"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test sort ignoreCase"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test sort numeric"></mutation> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="538"> + <mutation> + <arg name="test name"></arg> + </mutation> + <field name="NAME">check number of calls</field> + <comment pinned="false" h="78" w="257">Checks that the number of calls is one in order to confirm that a function was only called once.</comment> + <statement name="STACK"> + <block type="text_append"> + <field name="VAR">test name</field> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">number of calls</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="variables_get"> + <field name="VAR">test name</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">number of calls</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="713"> + <field name="NAME">test create</field> + <comment pinned="false" h="80" w="160">Tests the "create list with" and "create empty list" blocks.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create empty</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_create_with"> + <mutation items="0"></mutation> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_empty"></block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create items</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">love</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">love</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create repeated</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_repeat" inline="true"> + <value name="ITEM"> + <block type="text"> + <field name="TEXT">Eject</field> + </block> + </value> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Eject</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Eject</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Eject</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create repeated order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_repeat" inline="true"> + <value name="ITEM"> + <block type="text"> + <field name="TEXT">Eject</field> + </block> + </value> + <value name="NUM"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Eject</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Eject</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Eject</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" x="13" y="1163"> + <mutation statements="false"></mutation> + <field name="NAME">get empty list</field> + <comment pinned="false" h="80" w="160">Creates an empty list for use with the empty test.</comment> + <value name="RETURN"> + <block type="lists_create_empty"></block> + </value> + </block> + <block type="procedures_defnoreturn" x="13" y="1238"> + <field name="NAME">test empty</field> + <comment pinned="false" h="80" w="160">Tests the "is empty" block.</comment> + <statement name="STACK"> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">FALSE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">not empty</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_isEmpty" inline="true"> + <value name="VALUE"> + <block type="lists_create_with" inline="false"> + <mutation items="1"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">empty</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_isEmpty" inline="true"> + <value name="VALUE"> + <block type="lists_create_empty"></block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">empty complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_isEmpty" inline="true"> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get empty list"></mutation> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">empty order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_isEmpty" inline="true"> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="lists_create_empty"></block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="1563"> + <field name="NAME">test length</field> + <comment pinned="false" h="80" w="160">Tests the "length" block.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">zero length</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="lists_create_empty"></block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">one length</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="lists_create_with" inline="false"> + <mutation items="1"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">cat</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">three length</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">cat</field> + </block> + </value> + <value name="ADD1"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="ADD2"> + <block type="lists_create_empty"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">two length order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="lists_create_with" inline="false"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">cat</field> + </block> + </value> + <value name="ADD1"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="1988"> + <field name="NAME">test find simple</field> + <comment pinned="false" h="80" w="160">Tests the "find" block with a variable.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Alice</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Bob</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find first simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">LAST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find none simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Dave</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" x="13" y="2438"> + <field name="NAME">get names</field> + <comment pinned="false" h="80" w="160">Creates a list for use with the find test.</comment> + <statement name="STACK"> + <block type="math_change"> + <field name="VAR">number of calls</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Alice</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Bob</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + </block> + </value> + </block> + <block type="procedures_defnoreturn" x="13" y="2563"> + <field name="NAME">test find complex</field> + <comment pinned="false" h="80" w="160">Tests the "find" block with a function call.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find first complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get names"></mutation> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find first complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find first order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get names"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find first order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find last complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">LAST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get names"></mutation> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find last complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find last order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">LAST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get names"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Eve</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find last order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find none complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get names"></mutation> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Dave</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find none complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find none order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get names"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Dave</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find none order complex</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="3738"> + <field name="NAME">test get simple</field> + <comment pinned="false" h="80" w="160">Tests the "get" block with a variable.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get first simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get random simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="FIND"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get # order simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_END</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get #-end order simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_END</field> + <comment pinned="false" h="81" w="289">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" x="13" y="4538"> + <field name="NAME">get star wars</field> + <comment pinned="false" h="80" w="160">Creates a list for use with the get test.</comment> + <statement name="STACK"> + <block type="math_change"> + <field name="VAR">number of calls</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + </block> + <block type="procedures_defnoreturn" x="13" y="4663"> + <field name="NAME">test get complex</field> + <comment pinned="false" h="80" w="160">Tests the "get" block with a function call.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get first complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get first complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get first order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get first order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get last complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get last complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get last order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get last order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get random complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="FIND"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get random complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get random order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="FIND"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get random order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get # order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get # order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_END</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get #-end order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET</field> + <field name="WHERE">FROM_END</field> + <comment pinned="false" h="87" w="299">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get star wars"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get #-end order complex</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="6488"> + <field name="NAME">test getRemove</field> + <comment pinned="false" h="80" w="160">Tests the "get and remove" block.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove first</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove first list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove first order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove first order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove last</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove last list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove last order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove last order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove random</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="FIND"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove random list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove random order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="FIND"> + <block type="lists_getIndex"> + <mutation statement="false" at="false"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove random order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove #</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove # list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove # order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove # order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove #-end</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">FROM_END</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove #-end list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove #-end order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getIndex"> + <mutation statement="false" at="true"></mutation> + <field name="MODE">GET_REMOVE</field> + <field name="WHERE">FROM_END</field> + <comment pinned="false" h="94" w="258">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">getremove #-end order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="8888"> + <field name="NAME">test remove</field> + <comment pinned="false" h="80" w="160">Tests the "remove" block.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="false"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove first list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="false"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove first order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="false"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove last list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="false"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove last order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="false"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove random list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="false"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove random order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="true"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove # list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="true"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove # order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="true"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">FROM_END</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove #-end list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Kirk</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="true"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">FROM_END</field> + <comment pinned="false" h="94" w="256">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">remove #-end order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Spock</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">McCoy</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="10713"> + <field name="NAME">test set</field> + <comment pinned="false" h="80" w="160">Tests the "set" block.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">FIRST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Jean-Luc</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set first list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Jean-Luc</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">FIRST</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Jean-Luc</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set first order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Jean-Luc</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Beverly</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set last list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Beverly</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Beverly</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set last order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Beverly</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">RANDOM</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set random list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">RANDOM</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set random order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="true"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">FROM_START</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Pulaski</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set # list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Pulaski</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="true"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">FROM_START</field> + <value name="LIST"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Pulaski</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set # order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Pulaski</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="true"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">FROM_END</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Pulaski</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set #-end list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Pulaski</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="true"></mutation> + <field name="MODE">SET</field> + <field name="WHERE">FROM_END</field> + <comment pinned="false" h="88" w="258">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Pulaski</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">set #-end order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Pulaski</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="12538"> + <field name="NAME">test insert</field> + <comment pinned="false" h="80" w="160">Tests the "insert" block.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">FIRST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert first list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">FIRST</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert first order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert last list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert last order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">RANDOM</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert random list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">RANDOM</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert random order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_length" inline="false"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="true"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">FROM_START</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert # list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="true"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">FROM_START</field> + <value name="LIST"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert # order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="true"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">FROM_END</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert #-end list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_setIndex"> + <mutation at="true"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">FROM_END</field> + <comment pinned="false" h="77" w="263">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">insert #-end order list</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Picard</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Data</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Riker</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Crusher</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="14363"> + <field name="NAME">test sublist simple</field> + <comment pinned="false" h="80" w="160">Tests the "get sub-list" block with a variable.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="5"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Columbia</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + <value name="ADD4"> + <block type="text"> + <field name="TEXT">Endeavour</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # simple order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT2"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_END</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist #-end simple order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_END</field> + <comment pinned="false" h="80" w="265">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist first-last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="false" at2="false"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">changing list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="5"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Columbia</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + <value name="ADD4"> + <block type="text"> + <field name="TEXT">Endeavour</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">list copy</field> + <value name="VALUE"> + <block type="lists_getSublist"> + <mutation at1="false" at2="false"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">changing list</field> + </block> + </value> + </block> + </value> + <next> + <block type="lists_getIndex"> + <mutation statement="true" at="false"></mutation> + <field name="MODE">REMOVE</field> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">changing list</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist first-last simple copy check</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">list copy</field> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist #-end # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist first # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="false" at2="true"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Columbia</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist first #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="false" at2="true"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">FROM_END</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Columbia</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="false"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Endeavour</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist #-end last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="false"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Endeavour</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist all with # #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist all with #-end # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist all with # #-end math simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <comment pinned="false" h="93" w="347">Checks that the whole list is properly retrieved even if the value for start and end is not a simple number. This is especially important in generators where sublist uses [x:length - y] for # #-end.</comment> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="AT1"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" x="13" y="16238"> + <field name="NAME">get space shuttles</field> + <comment pinned="false" h="80" w="160">Creates a list for use with the sublist test.</comment> + <statement name="STACK"> + <block type="math_change"> + <field name="VAR">number of calls</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="lists_create_with" inline="true"> + <mutation items="5"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Columbia</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + <value name="ADD4"> + <block type="text"> + <field name="TEXT">Endeavour</field> + </block> + </value> + </block> + </value> + </block> + <block type="procedures_defnoreturn" x="13" y="16363"> + <field name="NAME">test sublist complex</field> + <comment pinned="false" h="80" w="160">Tests the "get sub-list" block with a function call.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # start complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist # start complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # start order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT1"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT2"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist # start order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_END</field> + <comment pinned="false" h="78" w="267">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # end complex number of calls</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">number of calls</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # end order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_END</field> + <value name="LIST"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT1"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist # end order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist first-last complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="false" at2="false"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">LAST</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist first-last complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist # #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist #-end # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist #-end # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist first # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="false" at2="true"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Columbia</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist first # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist first #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="false" at2="true"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">FROM_END</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Columbia</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist first #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist # last complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="false"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">LAST</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Endeavour</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist # last complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist #-end last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="false"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">LAST</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Challenger</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Discovery</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Atlantis</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">Endeavour</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist #-end last simple</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist all with # #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist all with # #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist all with #-end # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_START</field> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist all with #-end # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sublist all with # #-end math complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_getSublist"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <comment pinned="false" h="96" w="315">Checks that the whole list is properly retrieved even if the value for start and end is not a simple number. This is especially important in generators where sublist uses [x:length - y] for # #-end.</comment> + <value name="LIST"> + <block type="procedures_callreturn"> + <mutation name="get space shuttles"></mutation> + </block> + </value> + <value name="AT1"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">sublist all with # #-end math complex</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="18963"> + <field name="NAME">test join</field> + <comment pinned="false" h="80" w="160">Tests the "join" block.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Klingon</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">join</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_split"> + <mutation mode="JOIN"></mutation> + <field name="MODE">JOIN</field> + <value name="INPUT"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="DELIM"> + <block type="text"> + <field name="TEXT">,</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Vulcan,Klingon,Borg</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">join order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_split"> + <mutation mode="JOIN"></mutation> + <field name="MODE">JOIN</field> + <value name="INPUT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="DELIM"> + <block type="text"> + <field name="TEXT">,</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Vulcan,Klingon,Borg</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="19263"> + <field name="NAME">test split</field> + <comment pinned="false" h="80" w="160">Tests the "split" block.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Vulcan,Klingon,Borg</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">split</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_split"> + <mutation mode="SPLIT"></mutation> + <field name="MODE">SPLIT</field> + <value name="INPUT"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="DELIM"> + <block type="text"> + <field name="TEXT">,</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Klingon</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">split order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_split"> + <mutation mode="SPLIT"></mutation> + <field name="MODE">SPLIT</field> + <value name="INPUT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="DELIM"> + <block type="text"> + <field name="TEXT">,</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Klingon</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="19563"> + <field name="NAME">test sort alphabetic</field> + <comment pinned="false" h="80" w="160">Tests the "alphabetic sort" block.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">klingon</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sort alphabetic ascending</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_sort"> + <field name="TYPE">TEXT</field> + <field name="DIRECTION">1</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">klingon</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sort alphabetic ascending order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_sort"> + <field name="TYPE">TEXT</field> + <field name="DIRECTION">1</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">klingon</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="19863"> + <field name="NAME">test sort ignoreCase</field> + <comment pinned="false" h="80" w="160">Tests the "alphabetic sort ignore case" block.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">klingon</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sort ignore case ascending</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_sort"> + <field name="TYPE">IGNORE_CASE</field> + <field name="DIRECTION">1</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">klingon</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sort ignore case ascending order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_sort"> + <field name="TYPE">IGNORE_CASE</field> + <field name="DIRECTION">1</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Borg</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">klingon</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">Vulcan</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="20163"> + <field name="NAME">test sort numeric</field> + <comment pinned="false" h="80" w="160">Tests the "numeric sort" block.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">list</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">18</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sort numeric descending</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_sort"> + <field name="TYPE">NUMERIC</field> + <field name="DIRECTION">-1</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">18</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sort numeric descending order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="lists_sort"> + <field name="TYPE">NUMERIC</field> + <field name="DIRECTION">-1</field> + <value name="LIST"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">18</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> +</xml>
\ No newline at end of file diff --git a/blockly/tests/generators/logic.xml b/blockly/tests/generators/logic.xml new file mode 100644 index 0000000..acea1c7 --- /dev/null +++ b/blockly/tests/generators/logic.xml @@ -0,0 +1,906 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="-4" y="-12"> + <statement name="DO"> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">True</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">False</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Not true</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_negate" inline="false"> + <value name="BOOL"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Not false</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_negate" inline="false"> + <value name="BOOL"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test if"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test equalities"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test and"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test or"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test ternary"></mutation> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="385" y="-3"> + <field name="NAME">test if</field> + <statement name="STACK"> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <statement name="DO0"> + <block type="unittest_fail"> + <field name="MESSAGE">if false</field> + </block> + </statement> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">ok</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <next> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <statement name="DO0"> + <block type="variables_set" inline="false"> + <field name="VAR">ok</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">if true</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">ok</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">ok</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <next> + <block type="controls_if" inline="false"> + <mutation else="1"></mutation> + <value name="IF0"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <statement name="DO0"> + <block type="unittest_fail"> + <field name="MESSAGE">if/else false</field> + </block> + </statement> + <statement name="ELSE"> + <block type="variables_set" inline="false"> + <field name="VAR">ok</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">if/else false</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">ok</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">ok</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <next> + <block type="controls_if" inline="false"> + <mutation else="1"></mutation> + <value name="IF0"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <statement name="DO0"> + <block type="variables_set" inline="false"> + <field name="VAR">ok</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </statement> + <statement name="ELSE"> + <block type="unittest_fail"> + <field name="MESSAGE">if/else true</field> + </block> + </statement> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">if/else true</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">ok</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">ok</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <next> + <block type="controls_if" inline="false"> + <mutation elseif="2" else="1"></mutation> + <value name="IF0"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <statement name="DO0"> + <block type="unittest_fail"> + <field name="MESSAGE">elseif 1</field> + </block> + </statement> + <value name="IF1"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <statement name="DO1"> + <block type="variables_set" inline="false"> + <field name="VAR">ok</field> + <value name="VALUE"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </statement> + <value name="IF2"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <statement name="DO2"> + <block type="unittest_fail"> + <field name="MESSAGE">elseif 2</field> + </block> + </statement> + <statement name="ELSE"> + <block type="unittest_fail"> + <field name="MESSAGE">elseif 3</field> + </block> + </statement> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">elseif 4</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">ok</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="-7" y="384"> + <field name="NAME">test equalities</field> + <statement name="STACK"> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Equal yes</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Equal no</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Not equal yes</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">NEQ</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Not equal no</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Smaller yes</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">LT</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Smaller no</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">LT</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">7</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">7</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Greater yes</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">9</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Greater no</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Smaller-equal yes</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">LTE</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">11</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">11</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Smaller-equal no</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">LTE</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">13</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">12</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Greater-equal yes</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GTE</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">14</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">14</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Greater-equal no</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GTE</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">15</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">16</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="-5" y="1200"> + <field name="NAME">test or</field> + <statement name="STACK"> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Or true/true</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">OR</field> + <value name="A"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="B"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Or false/true</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">OR</field> + <value name="A"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <value name="B"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Or true/false</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">OR</field> + <value name="A"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="B"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">Or false/false</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">OR</field> + <value name="A"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <value name="B"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="385" y="1208"> + <field name="NAME">test and</field> + <statement name="STACK"> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">And true/true</field> + </block> + </value> + <field name="EXPECTED">TRUE</field> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">AND</field> + <value name="A"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="B"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">And false/true</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">AND</field> + <value name="A"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <value name="B"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">And true/false</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">AND</field> + <value name="A"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="B"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">And false/false</field> + </block> + </value> + <field name="EXPECTED">FALSE</field> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">AND</field> + <value name="A"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <value name="B"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="3" y="1527"> + <field name="NAME">test ternary</field> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">if true</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + <value name="ELSE"> + <block type="math_number"> + <field name="NUM">99</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">if true</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <value name="THEN"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + <value name="ELSE"> + <block type="math_number"> + <field name="NUM">99</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">99</field> + </block> + </value> + </block> + </next> + </block> + </statement> + </block> +</xml> diff --git a/blockly/tests/generators/loops1.xml b/blockly/tests/generators/loops1.xml new file mode 100644 index 0000000..7cdff07 --- /dev/null +++ b/blockly/tests/generators/loops1.xml @@ -0,0 +1,291 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="33" y="140"> + <statement name="DO"> + <block type="procedures_callnoreturn"> + <mutation name="test repeat"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test while"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test foreach"></mutation> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="31" y="296"> + <mutation></mutation> + <field name="NAME">test foreach</field> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_forEach" inline="false"> + <field name="VAR">x</field> + <value name="LIST"> + <block type="lists_create_with" inline="false"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">a</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">b</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">c</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">for loop</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">abc</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="30" y="624"> + <mutation></mutation> + <field name="NAME">test while</field> + <statement name="STACK"> + <block type="controls_whileUntil" inline="false"> + <field name="MODE">WHILE</field> + <value name="BOOL"> + <block type="logic_boolean"> + <field name="BOOL">FALSE</field> + </block> + </value> + <statement name="DO"> + <block type="unittest_fail"> + <field name="MESSAGE">while 0</field> + </block> + </statement> + <next> + <block type="controls_whileUntil" inline="false"> + <field name="MODE">UNTIL</field> + <value name="BOOL"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <statement name="DO"> + <block type="unittest_fail"> + <field name="MESSAGE">until 0</field> + </block> + </statement> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">count</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="controls_whileUntil" inline="false"> + <field name="MODE">WHILE</field> + <value name="BOOL"> + <block type="logic_compare"> + <field name="OP">NEQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="math_change" inline="false"> + <field name="VAR">count</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">while 10</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">count</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="controls_whileUntil" inline="false"> + <field name="MODE">UNTIL</field> + <value name="BOOL"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="math_change" inline="false"> + <field name="VAR">count</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">until 10</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="397" y="628"> + <mutation></mutation> + <field name="NAME">test repeat</field> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">count</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="controls_repeat_ext" inline="true"> + <value name="TIMES"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <statement name="DO"> + <block type="math_change" inline="false"> + <field name="VAR">count</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">repeat 10</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> +</xml> diff --git a/blockly/tests/generators/loops2.xml b/blockly/tests/generators/loops2.xml new file mode 100644 index 0000000..c35623a --- /dev/null +++ b/blockly/tests/generators/loops2.xml @@ -0,0 +1,890 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="66" y="-2"> + <statement name="DO"> + <block type="procedures_callnoreturn"> + <mutation name="test count"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test count by"></mutation> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="679" y="-10"> + <field name="NAME">test count by</field> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <statement name="DO"> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count up ints</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">1357</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <statement name="DO"> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count down ints</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">8642</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">loglist</field> + <value name="VALUE"> + <block type="lists_create_empty"></block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">1.5</field> + </block> + </value> + <statement name="DO"> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count with floats</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="false"> + <mutation items="5"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">2.5</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD3"> + <block type="math_number"> + <field name="NUM">5.5</field> + </block> + </value> + <value name="ADD4"> + <block type="math_number"> + <field name="NUM">7</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">loglist</field> + <value name="VALUE"> + <block type="lists_create_empty"></block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="BY"> + <block type="math_arithmetic"> + <field name="OP">MINUS</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count up non-trivial ints</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="false"> + <mutation items="8"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD3"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD4"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <value name="ADD5"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + <value name="ADD6"> + <block type="math_number"> + <field name="NUM">7</field> + </block> + </value> + <value name="ADD7"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">loglist</field> + <value name="VALUE"> + <block type="lists_create_empty"></block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="BY"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <statement name="DO"> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count down non-trivial ints</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="false"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD3"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">loglist</field> + <value name="VALUE"> + <block type="lists_create_empty"></block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0.5</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="BY"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count with floats</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="false"> + <mutation items="5"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">5.5</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4.5</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">3.5</field> + </block> + </value> + <value name="ADD3"> + <block type="math_number"> + <field name="NUM">2.5</field> + </block> + </value> + <value name="ADD4"> + <block type="math_number"> + <field name="NUM">1.5</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="29" y="184"> + <field name="NAME">test count</field> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <statement name="DO"> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count up</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">12345678</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <statement name="DO"> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count down</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">87654321</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">loglist</field> + <value name="VALUE"> + <block type="lists_create_empty"></block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count up non-trivial</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="false"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD3"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">loglist</field> + <value name="VALUE"> + <block type="lists_create_empty"></block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="TO"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="lists_setIndex"> + <mutation at="false"></mutation> + <field name="MODE">INSERT</field> + <field name="WHERE">LAST</field> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="TO"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count down non-trivial</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">loglist</field> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="false"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <value name="ADD3"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> +</xml> diff --git a/blockly/tests/generators/loops3.xml b/blockly/tests/generators/loops3.xml new file mode 100644 index 0000000..508b887 --- /dev/null +++ b/blockly/tests/generators/loops3.xml @@ -0,0 +1,734 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="19" y="106"> + <statement name="DO"> + <block type="procedures_callnoreturn"> + <mutation name="test break"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test continue"></mutation> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="300"> + <field name="NAME">test continue</field> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">count</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="controls_whileUntil" inline="false"> + <field name="MODE">WHILE</field> + <value name="BOOL"> + <block type="logic_compare"> + <field name="OP">NEQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="math_change" inline="false"> + <field name="VAR">count</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="controls_flow_statements"> + <field name="FLOW">CONTINUE</field> + </block> + </statement> + <next> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">while continue</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">1234678</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">count</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="controls_whileUntil" inline="false"> + <field name="MODE">UNTIL</field> + <value name="BOOL"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="math_change" inline="false"> + <field name="VAR">count</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="controls_flow_statements"> + <field name="FLOW">CONTINUE</field> + </block> + </statement> + <next> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">until continue</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">1234678</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <statement name="DO"> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="controls_flow_statements"> + <field name="FLOW">CONTINUE</field> + </block> + </statement> + <next> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </next> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count continue</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">1234678</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_forEach" inline="false"> + <field name="VAR">x</field> + <value name="LIST"> + <block type="lists_create_with" inline="false"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">a</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">b</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">c</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">d</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="B"> + <block type="text"> + <field name="TEXT">c</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="controls_flow_statements"> + <field name="FLOW">CONTINUE</field> + </block> + </statement> + <next> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </next> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">for continue</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">abd</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="600" y="300"> + <field name="NAME">test break</field> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">count</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="controls_whileUntil" inline="false"> + <field name="MODE">WHILE</field> + <value name="BOOL"> + <block type="logic_compare"> + <field name="OP">NEQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="controls_flow_statements"> + <field name="FLOW">BREAK</field> + </block> + </statement> + <next> + <block type="math_change" inline="false"> + <field name="VAR">count</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </next> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">while break</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">count</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="controls_whileUntil" inline="false"> + <field name="MODE">UNTIL</field> + <value name="BOOL"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="controls_flow_statements"> + <field name="FLOW">BREAK</field> + </block> + </statement> + <next> + <block type="math_change" inline="false"> + <field name="VAR">count</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </next> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">until break</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">count</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_for"> + <field name="VAR">x</field> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + <statement name="DO"> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="controls_flow_statements"> + <field name="FLOW">BREAK</field> + </block> + </statement> + <next> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </next> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">count break</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">1234</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">log</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="controls_forEach" inline="false"> + <field name="VAR">x</field> + <value name="LIST"> + <block type="lists_create_with" inline="false"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">a</field> + </block> + </value> + <value name="ADD1"> + <block type="text"> + <field name="TEXT">b</field> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">c</field> + </block> + </value> + <value name="ADD3"> + <block type="text"> + <field name="TEXT">d</field> + </block> + </value> + </block> + </value> + <statement name="DO"> + <block type="controls_if" inline="false"> + <value name="IF0"> + <block type="logic_compare"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + <value name="B"> + <block type="text"> + <field name="TEXT">c</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="controls_flow_statements"> + <field name="FLOW">BREAK</field> + </block> + </statement> + <next> + <block type="text_append" inline="false"> + <field name="VAR">log</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">x</field> + </block> + </value> + </block> + </next> + </block> + </statement> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">for break</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">log</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">ab</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> +</xml> diff --git a/blockly/tests/generators/math.xml b/blockly/tests/generators/math.xml new file mode 100644 index 0000000..9c1f644 --- /dev/null +++ b/blockly/tests/generators/math.xml @@ -0,0 +1,1884 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="13" y="13"> + <statement name="DO"> + <block type="procedures_callnoreturn"> + <mutation name="test arithmetic"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test single"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test trig"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test constant"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test change"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test number properties"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test round"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test operations on list"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test constraint"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test mod"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test random integer"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test random fraction"></mutation> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="388"> + <field name="NAME">test single</field> + <comment pinned="false" h="80" w="160">Tests the "single" block.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sqrt</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_single" inline="false"> + <field name="OP">ROOT</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">25</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">abs</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_single" inline="false"> + <field name="OP">ABS</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">-25</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">25</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">negate</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_single" inline="false"> + <field name="OP">NEG</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">-25</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">25</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">ln</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_single" inline="false"> + <field name="OP">LN</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">log10</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_single" inline="false"> + <field name="OP">LOG10</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">exp</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_single" inline="false"> + <field name="OP">EXP</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">7.38905609893065</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">power10</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_single" inline="false"> + <field name="OP">POW10</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="1013"> + <field name="NAME">test arithmetic</field> + <comment pinned="false" h="80" w="272">Tests the "arithmetic" block for all operations and checks parenthesis are properly generated for different orders.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">add</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">subtract</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">MINUS</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">subtract order with add</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">MINUS</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">subtract order with subtract</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">MINUS</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="B"> + <block type="math_arithmetic"> + <field name="OP">MINUS</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">multiply</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">MULTIPLY</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">2.5</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">multiply order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">MULTIPLY</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="B"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">2.5</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">divide</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">DIVIDE</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">8.2</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">-5</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">-1.64</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">divide order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">DIVIDE</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">8.2</field> + </block> + </value> + <value name="B"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">-5</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">-1.64</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">power</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">POWER</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">10000</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">power order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_arithmetic"> + <field name="OP">POWER</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + <value name="B"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">10000</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="2013"> + <field name="NAME">test trig</field> + <comment pinned="false" h="80" w="160">Tests the "trig" block.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sin</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_trig" inline="false"> + <field name="OP">SIN</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">90</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">cos</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_trig" inline="false"> + <field name="OP">COS</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">180</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">tan</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_trig" inline="false"> + <field name="OP">TAN</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">asin</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_trig" inline="false"> + <field name="OP">ASIN</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">-90</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">acos</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_trig" inline="false"> + <field name="OP">ACOS</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">atan</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_trig" inline="false"> + <field name="OP">ATAN</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">45</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="2538"> + <field name="NAME">test constant</field> + <comment pinned="false" h="80" w="160">Tests the "constant" blocks.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">const pi</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_round" inline="false"> + <field name="OP">ROUNDDOWN</field> + <value name="NUM"> + <block type="math_arithmetic"> + <field name="OP">MULTIPLY</field> + <value name="A"> + <block type="math_constant"> + <field name="CONSTANT">PI</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1000</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3141</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">const e</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_round" inline="false"> + <field name="OP">ROUNDDOWN</field> + <value name="NUM"> + <block type="math_arithmetic"> + <field name="OP">MULTIPLY</field> + <value name="A"> + <block type="math_constant"> + <field name="CONSTANT">E</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1000</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">2718</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">const golden</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_round" inline="false"> + <field name="OP">ROUNDDOWN</field> + <value name="NUM"> + <block type="math_arithmetic"> + <field name="OP">MULTIPLY</field> + <value name="A"> + <block type="math_constant"> + <field name="CONSTANT">GOLDEN_RATIO</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1000</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">1618</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">const sqrt 2</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_round" inline="false"> + <field name="OP">ROUNDDOWN</field> + <value name="NUM"> + <block type="math_arithmetic"> + <field name="OP">MULTIPLY</field> + <value name="A"> + <block type="math_constant"> + <field name="CONSTANT">SQRT2</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1000</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">1414</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">const sqrt 0.5</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_round" inline="false"> + <field name="OP">ROUNDDOWN</field> + <value name="NUM"> + <block type="math_arithmetic"> + <field name="OP">MULTIPLY</field> + <value name="A"> + <block type="math_constant"> + <field name="CONSTANT">SQRT1_2</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1000</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">707</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">const infinity</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">LT</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">9999</field> + </block> + </value> + <value name="B"> + <block type="math_constant"> + <field name="CONSTANT">INFINITY</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="3113"> + <field name="NAME">test number properties</field> + <comment pinned="false" h="80" w="160">Tests the "number property" blocks.</comment> + <statement name="STACK"> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">even</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">EVEN</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">FALSE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">odd</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">ODD</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_number"> + <field name="NUM">42.1</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">prime 5</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">PRIME</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">FALSE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">prime 25</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">PRIME</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_number"> + <field name="NUM">25</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">FALSE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">prime negative</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">PRIME</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_number"> + <field name="NUM">-31.1</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">FALSE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">whole</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">WHOLE</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_constant"> + <field name="CONSTANT">PI</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">positive</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">POSITIVE</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_constant"> + <field name="CONSTANT">INFINITY</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">negative</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">NEGATIVE</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_number"> + <field name="NUM">-42</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">divisible</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="true"></mutation> + <field name="PROPERTY">DIVISIBLE_BY</field> + <value name="NUMBER_TO_CHECK"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + <value name="DIVISOR"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="3738"> + <field name="NAME">test round</field> + <comment pinned="false" h="80" w="160">Tests the "round" block.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">round</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_round" inline="false"> + <field name="OP">ROUND</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">42.42</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">round up</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_round" inline="false"> + <field name="OP">ROUNDUP</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">-42.42</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">-42</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">round down</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_round" inline="false"> + <field name="OP">ROUNDDOWN</field> + <value name="NUM"> + <block type="math_number"> + <field name="NUM">42.42</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="4038"> + <field name="NAME">test change</field> + <comment pinned="false" h="80" w="160">Tests the "change" block.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">varToChange</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + <next> + <block type="math_change" inline="false"> + <field name="VAR">varToChange</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">change</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">varToChange</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">142</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="4238"> + <field name="NAME">test operations on list</field> + <comment pinned="false" h="80" w="160">Tests the "list operation" blocks.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">sum</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_on_list" inline="false"> + <mutation op="SUM"></mutation> + <field name="OP">SUM</field> + <value name="LIST"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">12</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">min</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_on_list" inline="false"> + <mutation op="MIN"></mutation> + <field name="OP">MIN</field> + <value name="LIST"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">max</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_on_list" inline="false"> + <mutation op="MAX"></mutation> + <field name="OP">MAX</field> + <value name="LIST"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">average</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_on_list" inline="false"> + <mutation op="AVERAGE"></mutation> + <field name="OP">AVERAGE</field> + <value name="LIST"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">median</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_on_list" inline="false"> + <mutation op="MEDIAN"></mutation> + <field name="OP">MEDIAN</field> + <value name="LIST"> + <block type="lists_create_with" inline="true"> + <mutation items="4"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <value name="ADD3"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3.5</field> + </block> + </value> + <next> + <block type="unittest_assertequals"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">modes</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_on_list" inline="false"> + <mutation op="MODE"></mutation> + <field name="OP">MODE</field> + <value name="LIST"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="1"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">modes multiple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_on_list" inline="false"> + <mutation op="MODE"></mutation> + <field name="OP">MODE</field> + <value name="LIST"> + <block type="lists_create_with" inline="true"> + <mutation items="5"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD3"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="ADD4"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="lists_create_with" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">standard dev</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_on_list" inline="false"> + <mutation op="STD_DEV"></mutation> + <field name="OP">STD_DEV</field> + <value name="LIST"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">random</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare" inline="false"> + <field name="OP">GT</field> + <value name="A"> + <block type="lists_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="lists_create_with" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <value name="FIND"> + <block type="math_on_list" inline="false"> + <mutation op="RANDOM"></mutation> + <field name="OP">RANDOM</field> + <value name="LIST"> + <block type="lists_create_with" inline="false"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="5213"> + <field name="NAME">test mod</field> + <comment pinned="false" h="80" w="160">Tests the "mod" block.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">mod</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_modulo"> + <value name="DIVIDEND"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + <value name="DIVISOR"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="5363"> + <field name="NAME">test constraint</field> + <comment pinned="false" h="80" w="160">Tests the "constrain" block.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">constraint</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_constrain"> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">100</field> + </block> + </value> + <value name="LOW"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="HIGH"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">42</field> + </block> + </value> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="5513"> + <field name="NAME">test random integer</field> + <comment pinned="false" h="80" w="160">Tests the "random integer" block.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">rand</field> + <value name="VALUE"> + <block type="math_random_int"> + <value name="FROM"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + <value name="TO"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">randRange</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">AND</field> + <value name="A"> + <block type="logic_compare"> + <field name="OP">GTE</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">rand</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">5</field> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="logic_compare"> + <field name="OP">LTE</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">rand</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">10</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">randInteger</field> + </block> + </value> + <value name="ACTUAL"> + <block type="math_number_property"> + <mutation divisor_input="false"></mutation> + <field name="PROPERTY">WHOLE</field> + <value name="NUMBER_TO_CHECK"> + <block type="variables_get"> + <field name="VAR">rand</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="5763"> + <field name="NAME">test random fraction</field> + <comment pinned="false" h="80" w="160">Tests the "random fraction" block.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">rand</field> + <value name="VALUE"> + <block type="math_random_float"></block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">randFloat</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_operation"> + <field name="OP">AND</field> + <value name="A"> + <block type="logic_compare"> + <field name="OP">GTE</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">rand</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="logic_compare"> + <field name="OP">LTE</field> + <value name="A"> + <block type="variables_get"> + <field name="VAR">rand</field> + </block> + </value> + <value name="B"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </statement> + </block> +</xml>
\ No newline at end of file diff --git a/blockly/tests/generators/text.xml b/blockly/tests/generators/text.xml new file mode 100644 index 0000000..baf62d8 --- /dev/null +++ b/blockly/tests/generators/text.xml @@ -0,0 +1,4094 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="13" y="13"> + <statement name="DO"> + <block type="procedures_callnoreturn"> + <mutation name="test length"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test empty"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test create"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test append"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test find simple"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test find complex"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test get simple"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test get complex"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test substring simple"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test substring complex"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test case"></mutation> + <next> + <block type="procedures_callnoreturn"> + <mutation name="test trim"></mutation> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="388"> + <mutation> + <arg name="test name"></arg> + </mutation> + <field name="NAME">check number of calls</field> + <comment pinned="false" h="69" w="256">Checks that the number of calls is one in order to confirm that a function was only called once.</comment> + <statement name="STACK"> + <block type="text_append"> + <field name="VAR">test name</field> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">number of calls</field> + </block> + </value> + <next> + <block type="unittest_assertequals"> + <value name="MESSAGE"> + <block type="variables_get"> + <field name="VAR">test name</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">number of calls</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="563"> + <field name="NAME">test create</field> + <comment pinned="false" h="80" w="160">Tests the "create text with" block with varying number of inputs.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">no text</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_join" inline="false"> + <mutation items="0"></mutation> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create single</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_join" inline="false"> + <mutation items="1"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">Hello</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Hello</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create single number</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_join" inline="false"> + <mutation items="1"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">-1</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create double text</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_join" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="text"> + <field name="TEXT">K</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">9</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">K9</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create double text numbers</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_join" inline="true"> + <mutation items="2"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">4</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">42</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create triple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_join" inline="true"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="ADD1"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + <value name="ADD2"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">123</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">create order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_join" inline="false"> + <mutation items="3"></mutation> + <value name="ADD0"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + <value name="ADD1"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="ADD2"> + <block type="text"> + <field name="TEXT">M</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">10M</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" x="13" y="1263"> + <mutation statements="false"></mutation> + <field name="NAME">get empty</field> + <comment pinned="false" h="80" w="160">Creates an empty string for use with the empty test.</comment> + <value name="RETURN"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + </block> + <block type="procedures_defnoreturn" x="13" y="1338"> + <field name="NAME">test empty</field> + <comment pinned="false" h="80" w="160">Tests the "is empty" block".</comment> + <statement name="STACK"> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">FALSE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">not empty</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_isEmpty" inline="true"> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Google</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">empty</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_isEmpty" inline="true"> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">empty complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_isEmpty" inline="true"> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get empty"></mutation> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">empty order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_isEmpty" inline="true"> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="1663"> + <field name="NAME">test length</field> + <comment pinned="false" h="80" w="160">Tests the "length" block.</comment> + <statement name="STACK"> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">zero length</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_length" inline="false"> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"></field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">non-zero length</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_length" inline="false"> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Google</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">length order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_length" inline="false"> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="text"> + <field name="TEXT">car</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="1963"> + <field name="NAME">test append</field> + <comment pinned="false" h="80" w="160">Tests the "append text" block with different types of parameters.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">item</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Miserable</field> + </block> + </value> + <next> + <block type="text_append" inline="false"> + <field name="VAR">item</field> + <value name="TEXT"> + <block type="text"> + <field name="TEXT">Failure</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">append text</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">item</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">MiserableFailure</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">item</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">12</field> + </block> + </value> + <next> + <block type="text_append" inline="false"> + <field name="VAR">item</field> + <value name="TEXT"> + <block type="math_number"> + <field name="NUM">34</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">append number</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">item</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">1234</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">item</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Something </field> + </block> + </value> + <next> + <block type="text_append" inline="false"> + <field name="VAR">item</field> + <value name="TEXT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="text"> + <field name="TEXT">Positive</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">append order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">item</field> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Something Positive</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="2438"> + <field name="NAME">test find simple</field> + <comment pinned="false" h="80" w="160">Tests the "find" block with a variable.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Banana</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find first simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">an</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">LAST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">an</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find none simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Peel</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" x="13" y="2838"> + <field name="NAME">get fruit</field> + <comment pinned="false" h="80" w="160">Creates a string for use with the find test.</comment> + <statement name="STACK"> + <block type="math_change"> + <field name="VAR">number of calls</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="text"> + <field name="TEXT">Banana</field> + </block> + </value> + </block> + <block type="procedures_defnoreturn" x="13" y="2938"> + <field name="NAME">test find complex</field> + <comment pinned="false" h="80" w="160">Tests the "find" block with a function call.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find first complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get fruit"></mutation> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">an</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find first complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find first order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get fruit"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">an</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find first order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find last complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">LAST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get fruit"></mutation> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">an</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find last complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find last order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">LAST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get fruit"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">an</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find last order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find none complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get fruit"></mutation> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Peel</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find none complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">find none order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_indexOf"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get fruit"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="FIND"> + <block type="text"> + <field name="TEXT">Peel</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">find none order complex</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="4013"> + <field name="NAME">test get simple</field> + <comment pinned="false" h="80" w="160">Tests the "get letter" block with a variable.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Blockly</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get first simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">B</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">y</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get random simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="text_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="FIND"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">o</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get # order simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">o</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_END</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">k</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get #-end order simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_END</field> + <comment pinned="false" h="84" w="274">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">k</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" x="13" y="4838"> + <field name="NAME">get Blockly</field> + <comment pinned="false" h="80" w="160">Creates a string for use with the get test.</comment> + <statement name="STACK"> + <block type="math_change"> + <field name="VAR">number of calls</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="text"> + <field name="TEXT">Blockly</field> + </block> + </value> + </block> + <block type="procedures_defnoreturn" x="13" y="4938"> + <field name="NAME">test get complex</field> + <comment pinned="false" h="80" w="160">Tests the "get letter" block with a function call.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Blockly</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get first complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">B</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get first complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get first order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">FIRST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">B</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get first order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get last complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">y</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get last complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get last order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">LAST</field> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">y</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get last order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get random complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="text_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="FIND"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get random complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertvalue" inline="false"> + <field name="EXPECTED">TRUE</field> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get random order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="logic_compare"> + <field name="OP">GT</field> + <value name="A"> + <block type="text_indexOf" inline="false"> + <field name="END">FIRST</field> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="FIND"> + <block type="text_charAt"> + <mutation at="false"></mutation> + <field name="WHERE">RANDOM</field> + <value name="VALUE"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">-1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get random order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">o</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get # order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="logic_ternary" inline="false"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">o</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get # order complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_END</field> + <value name="VALUE"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + <value name="AT"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">k</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">get #-end order complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_charAt"> + <mutation at="true"></mutation> + <field name="WHERE">FROM_END</field> + <comment pinned="false" h="83" w="258">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="VALUE"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get Blockly"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">k</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">get #-end order complex</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defreturn" x="13" y="6738"> + <field name="NAME">get numbers</field> + <comment pinned="false" h="80" w="160">Creates a string for use with the substring test.</comment> + <statement name="STACK"> + <block type="math_change"> + <field name="VAR">number of calls</field> + <value name="DELTA"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </statement> + <value name="RETURN"> + <block type="text"> + <field name="TEXT">123456789</field> + </block> + </value> + </block> + <block type="procedures_defnoreturn" x="13" y="6838"> + <field name="NAME">test substring simple</field> + <comment pinned="false" h="80" w="160">Tests the "get substring" block with a variable.</comment> + <statement name="STACK"> + <block type="variables_set" inline="false"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">123456789</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">23</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring # simple order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT2"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">23</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_END</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">78</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring #-end simple order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_END</field> + <comment pinned="false" h="81" w="266">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">78</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring first-last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="false" at2="false"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">LAST</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring # #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">2345678</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring #-end # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">34</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring first # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="false" at2="true"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">1234</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring first #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="false" at2="true"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">FROM_END</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">12345678</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring # last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="false"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">LAST</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">789</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring #-end last simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="false"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">LAST</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">789</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring all with # #-end simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">123456789</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring all with #-end # simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">123456789</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring all with # #-end math simple</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <comment pinned="false" h="94" w="320">Checks that the whole string is properly retrieved even if the value for start and end is not a simple number. This is especially important in generators where substring uses [x:length - y] for # #-end.</comment> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="AT1"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">123456789</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="8388"> + <field name="NAME">test substring complex</field> + <comment pinned="false" h="80" w="160">Tests the "get substring" block with a function call.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">23</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring # complex order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT1"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT2"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">23</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring # complex order</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_END</field> + <comment pinned="false" h="83" w="259">The order for index for #-end is addition because this will catch errors in generators where most perform the operation ... - index.</comment> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">78</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring #-end order order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_END</field> + <value name="STRING"> + <block type="logic_ternary"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + <value name="AT1"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">78</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring #-end order order</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring first-last</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="false" at2="false"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">LAST</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring first-last</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring # #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">2345678</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring # #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring #-end # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">34</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring #-end # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring first # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="false" at2="true"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">3</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">1234</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring first # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring first #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="false" at2="true"></mutation> + <field name="WHERE1">FIRST</field> + <field name="WHERE2">FROM_END</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">12345678</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring first #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring # last complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="false"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">LAST</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">6</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">789</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring # last complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring #-end last complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="false"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">LAST</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">789</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring #-end last complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring all with # #-end complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">123456789</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring all with # #-end complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring all with #-end # complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_END</field> + <field name="WHERE2">FROM_START</field> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">8</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">123456789</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring all with #-end # complex</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">number of calls</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">substring all with # #-end math complex</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_getSubstring"> + <mutation at1="true" at2="true"></mutation> + <field name="WHERE1">FROM_START</field> + <field name="WHERE2">FROM_END</field> + <comment pinned="false" h="92" w="323">Checks that the whole string is properly retrieved even if the value for start and end is not a simple number. This is especially important in generators where substring uses [x:length - y] for # #-end.</comment> + <value name="STRING"> + <block type="procedures_callreturn"> + <mutation name="get numbers"></mutation> + </block> + </value> + <value name="AT1"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="AT2"> + <block type="math_arithmetic"> + <field name="OP">ADD</field> + <value name="A"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + <value name="B"> + <block type="unittest_adjustindex"> + <value name="INDEX"> + <block type="math_number"> + <field name="NUM">0</field> + </block> + </value> + </block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">123456789</field> + </block> + </value> + <next> + <block type="procedures_callnoreturn" inline="true"> + <mutation name="check number of calls"> + <arg name="test name"></arg> + </mutation> + <value name="ARG0"> + <block type="text"> + <field name="TEXT">substring all with # #-end math complex</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="10838"> + <field name="NAME">test case</field> + <comment pinned="false" h="80" w="160">Tests the "change casing" block.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Hello World</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">uppercase</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_changeCase" inline="false"> + <field name="CASE">UPPERCASE</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">HELLO WORLD</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">uppercase order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_changeCase" inline="false"> + <field name="CASE">UPPERCASE</field> + <value name="TEXT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">HELLO WORLD</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">Hello World</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">lowercase</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_changeCase" inline="false"> + <field name="CASE">LOWERCASE</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">hello world</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">lowercase order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_changeCase" inline="false"> + <field name="CASE">LOWERCASE</field> + <value name="TEXT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">hello world</field> + </block> + </value> + <next> + <block type="variables_set"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT">heLLo WorlD</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">titlecase</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_changeCase" inline="false"> + <field name="CASE">TITLECASE</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Hello World</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">titlecase order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_changeCase" inline="false"> + <field name="CASE">TITLECASE</field> + <value name="TEXT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">Hello World</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" x="13" y="11488"> + <field name="NAME">test trim</field> + <comment pinned="false" h="80" w="160">Tests the "trim" block.</comment> + <statement name="STACK"> + <block type="variables_set"> + <field name="VAR">text</field> + <value name="VALUE"> + <block type="text"> + <field name="TEXT"> abc def </field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">trim both</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_trim" inline="false"> + <field name="MODE">BOTH</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">abc def</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">trim both order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_trim" inline="false"> + <field name="MODE">BOTH</field> + <value name="TEXT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">abc def</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">trim left</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_trim" inline="false"> + <field name="MODE">LEFT</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">abc def </field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">trim left order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_trim" inline="false"> + <field name="MODE">LEFT</field> + <value name="TEXT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT">abc def </field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">trim right</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_trim" inline="false"> + <field name="MODE">RIGHT</field> + <value name="TEXT"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT"> abc def</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">trim right order</field> + </block> + </value> + <value name="ACTUAL"> + <block type="text_trim" inline="false"> + <field name="MODE">RIGHT</field> + <value name="TEXT"> + <block type="logic_ternary" inline="true"> + <value name="IF"> + <block type="logic_boolean"> + <field name="BOOL">TRUE</field> + </block> + </value> + <value name="THEN"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="ELSE"> + <block type="logic_null"></block> + </value> + </block> + </value> + </block> + </value> + <value name="EXPECTED"> + <block type="text"> + <field name="TEXT"> abc def</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> +</xml>
\ No newline at end of file diff --git a/blockly/tests/generators/unittest.js b/blockly/tests/generators/unittest.js new file mode 100644 index 0000000..d2b94e6 --- /dev/null +++ b/blockly/tests/generators/unittest.js @@ -0,0 +1,117 @@ +/** + * @license + * Visual Blocks Language + * + * Copyright 2012 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Unit test blocks for Blockly. + * @author fraser@google.com (Neil Fraser) + */ +'use strict'; + +Blockly.Blocks['unittest_main'] = { + // Container for unit tests. + init: function() { + this.setColour(65); + this.appendDummyInput() + .appendField('run tests'); + this.appendStatementInput('DO'); + this.setTooltip('Executes the enclosed unit tests,\n' + + 'then prints a summary.'); + }, + getVars: function() { + return ['unittestResults']; + } +}; + +Blockly.Blocks['unittest_assertequals'] = { + // Asserts that a value equals another value. + init: function() { + this.setColour(65); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.appendValueInput('MESSAGE') + .appendField('name') + .setCheck('String'); + this.appendValueInput('ACTUAL') + .appendField('actual'); + this.appendValueInput('EXPECTED') + .appendField('expected'); + this.setTooltip('Tests that "actual == expected".'); + }, + getVars: function() { + return ['unittestResults']; + } +}; + +Blockly.Blocks['unittest_assertvalue'] = { + // Asserts that a value is true, false, or null. + init: function() { + this.setColour(65); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.appendValueInput('MESSAGE', 'test name') + .appendField('name') + .setCheck('String'); + this.appendValueInput('ACTUAL') + .appendField('assert') + .appendField(new Blockly.FieldDropdown( + [['true', 'TRUE'], ['false', 'FALSE'], ['null', 'NULL']]), 'EXPECTED'); + this.setTooltip('Tests that the value is true, false, or null.'); + }, + getVars: function() { + return ['unittestResults']; + } +}; + +Blockly.Blocks['unittest_fail'] = { + // Always assert an error. + init: function() { + this.setColour(65); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.appendDummyInput() + .appendField(new Blockly.FieldTextInput('test name'), 'MESSAGE') + .appendField('fail'); + this.setTooltip('Records an error.'); + }, + getVars: function() { + return ['unittestResults']; + } +}; + +Blockly.Blocks['unittest_adjustindex'] = { + // Adjusts the indexing based on current setting. + init: function() { + this.jsonInit({ + "message0": "adjusted %1", + "args0": [ + { + "type": "input_value", + "name": "INDEX", + "check": "Number" + } + ], + "inputsInline": true, + "output": "Number", + "colour": 65, + "tooltip": "Adjusts the value based on whether generated code is using " + + "zero or one based indexing" + }); + } +}; diff --git a/blockly/tests/generators/unittest_dart.js b/blockly/tests/generators/unittest_dart.js new file mode 100644 index 0000000..f1334c9 --- /dev/null +++ b/blockly/tests/generators/unittest_dart.js @@ -0,0 +1,177 @@ +/** + * @license + * Visual Blocks Language + * + * Copyright 2014 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Generating Dart for unit test blocks. + * @author fraser@google.com (Neil Fraser) + */ +'use strict'; + +Blockly.Dart['unittest_main'] = function(block) { + // Container for unit tests. + var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.Dart.provideFunction_( + 'unittest_report', + [ 'String ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + '() {', + ' // Create test report.', + ' List report = [];', + ' StringBuffer summary = new StringBuffer();', + ' int fails = 0;', + ' for (int x = 0; x < ' + resultsVar + '.length; x++) {', + ' if (' + resultsVar + '[x][0]) {', + ' summary.write(".");', + ' } else {', + ' summary.write("F");', + ' fails++;', + ' report.add("");', + ' report.add("FAIL: ${' + resultsVar + '[x][2]}");', + ' report.add(' + resultsVar + '[x][1]);', + ' }', + ' }', + ' report.insert(0, summary.toString());', + ' report.add("");', + ' report.add("Ran ${' + resultsVar + '.length} tests.");', + ' report.add("");', + ' if (fails != 0) {', + ' report.add("FAILED (failures=$fails)");', + ' } else {', + ' report.add("OK");', + ' }', + ' return report.join("\\n");', + '}']); + // Setup global to hold test results. + var code = resultsVar + ' = [];\n'; + // Run tests (unindented). + code += Blockly.Dart.statementToCode(block, 'DO') + .replace(/^ /, '').replace(/\n /g, '\n'); + var reportVar = Blockly.Dart.variableDB_.getDistinctName( + 'report', Blockly.Variables.NAME_TYPE); + code += 'String ' + reportVar + ' = ' + functionName + '();\n'; + // Destroy results. + code += resultsVar + ' = null;\n'; + // Print the report to the console (that's where errors will go anyway). + code += 'print(' + reportVar + ');\n'; + return code; +}; + +Blockly.Dart['unittest_main'].defineAssert_ = function() { + var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.Dart.provideFunction_( + 'unittest_assertequals', + [ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + + '(dynamic actual, dynamic expected, String message) {', + ' // Asserts that a value equals another value.', + ' if (' + resultsVar + ' == null) {', + ' throw "Orphaned assert: ${message}";', + ' }', + ' bool equals(a, b) {', + ' if (a == b) {', + ' return true;', + ' } else if (a is List && b is List) {', + ' if (a.length != b.length) {', + ' return false;', + ' }', + ' for (num i = 0; i < a.length; i++) {', + ' if (!equals(a[i], b[i])) {', + ' return false;', + ' }', + ' }', + ' return true;', + ' }', + ' return false;', + ' }', + ' if (equals(actual, expected)) {', + ' ' + resultsVar + '.add([true, "OK", message]);', + ' } else {', + ' ' + resultsVar + '.add([false, ' + + '"Expected: $expected\\nActual: $actual", message]);', + ' }', + '}']); + return functionName; +}; + +Blockly.Dart['unittest_assertequals'] = function(block) { + // Asserts that a value equals another value. + var message = Blockly.Dart.valueToCode(block, 'MESSAGE', + Blockly.Dart.ORDER_NONE) || ''; + var actual = Blockly.Dart.valueToCode(block, 'ACTUAL', + Blockly.Dart.ORDER_NONE) || 'null'; + var expected = Blockly.Dart.valueToCode(block, 'EXPECTED', + Blockly.Dart.ORDER_NONE) || 'null'; + return Blockly.Dart['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ');\n'; +}; + +Blockly.Dart['unittest_assertvalue'] = function(block) { + // Asserts that a value is true, false, or null. + var message = Blockly.Dart.valueToCode(block, 'MESSAGE', + Blockly.Dart.ORDER_NONE) || ''; + var actual = Blockly.Dart.valueToCode(block, 'ACTUAL', + Blockly.Dart.ORDER_NONE) || 'null'; + var expected = block.getFieldValue('EXPECTED'); + if (expected == 'TRUE') { + expected = 'true'; + } else if (expected == 'FALSE') { + expected = 'false'; + } else if (expected == 'NULL') { + expected = 'null'; + } + return Blockly.Dart['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ');\n'; +}; + +Blockly.Dart['unittest_fail'] = function(block) { + // Always assert an error. + var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var message = Blockly.Dart.valueToCode(block, 'MESSAGE', + Blockly.Dart.ORDER_NONE) || ''; + var functionName = Blockly.Dart.provideFunction_( + 'unittest_fail', + [ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + + '(String message) {', + ' // Always assert an error.', + ' if (' + resultsVar + ' == null) {', + ' throw "Orphaned assert fail: ${message}";', + ' }', + ' ' + resultsVar + '.add([false, "Fail.", message]);', + '}']); + return functionName + '(' + message + ');\n'; +}; + +Blockly.Dart['unittest_adjustindex'] = function(block) { + var index = Blockly.Dart.valueToCode(block, 'INDEX', + Blockly.Dart.ORDER_ADDITIVE) || '0'; + // Adjust index if using one-based indexing. + if (Blockly.Dart.ONE_BASED_INDEXING) { + if (Blockly.isNumber(index)) { + // If the index is a naked number, adjust it right now. + return [parseFloat(index) + 1, Blockly.Dart.ORDER_ATOMIC]; + } else { + // If the index is dynamic, adjust it in code. + index = index + ' + 1'; + } + } else if (Blockly.isNumber(index)) { + return [index, Blockly.Dart.ORDER_ATOMIC]; + } + return [index, Blockly.Dart.ORDER_ADDITIVE]; +}; diff --git a/blockly/tests/generators/unittest_javascript.js b/blockly/tests/generators/unittest_javascript.js new file mode 100644 index 0000000..9915686 --- /dev/null +++ b/blockly/tests/generators/unittest_javascript.js @@ -0,0 +1,181 @@ +/** + * @license + * Visual Blocks Language + * + * Copyright 2012 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Generating JavaScript for unit test blocks. + * @author fraser@google.com (Neil Fraser) + */ +'use strict'; + +Blockly.JavaScript['unittest_main'] = function(block) { + // Container for unit tests. + var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.JavaScript.provideFunction_( + 'unittest_report', + [ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '() {', + ' // Create test report.', + ' var report = [];', + ' var summary = [];', + ' var fails = 0;', + ' for (var i = 0; i < ' + resultsVar + '.length; i++) {', + ' if (' + resultsVar + '[i][0]) {', + ' summary.push(".");', + ' } else {', + ' summary.push("F");', + ' fails++;', + ' report.push("");', + ' report.push("FAIL: " + ' + resultsVar + '[i][2]);', + ' report.push(' + resultsVar + '[i][1]);', + ' }', + ' }', + ' report.unshift(summary.join(""));', + ' report.push("");', + ' report.push("Number of tests run: " + ' + resultsVar + + '.length);', + ' report.push("");', + ' if (fails) {', + ' report.push("FAILED (failures=" + fails + ")");', + ' } else {', + ' report.push("OK");', + ' }', + ' return report.join("\\n");', + '}']); + // Setup global to hold test results. + var code = resultsVar + ' = [];\n'; + // Run tests (unindented). + code += Blockly.JavaScript.statementToCode(block, 'DO') + .replace(/^ /, '').replace(/\n /g, '\n'); + var reportVar = Blockly.JavaScript.variableDB_.getDistinctName( + 'report', Blockly.Variables.NAME_TYPE); + code += 'var ' + reportVar + ' = ' + functionName + '();\n'; + // Destroy results. + code += resultsVar + ' = null;\n'; + // Send the report to the console (that's where errors will go anyway). + code += 'console.log(' + reportVar + ');\n'; + return code; +}; + +Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) { + var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.JavaScript.provideFunction_( + 'assertEquals', + [ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + + '(actual, expected, message) {', + ' // Asserts that a value equals another value.', + ' if (!' + resultsVar + ') {', + ' throw "Orphaned assert: " + message;', + ' }', + ' function equals(a, b) {', + ' if (a === b) {', + ' return true;', + ' } else if ((typeof a == "number") && (typeof b == "number") &&', + ' (a.toPrecision(15) == b.toPrecision(15))) {', + ' return true;', + ' } else if (a instanceof Array && b instanceof Array) {', + ' if (a.length != b.length) {', + ' return false;', + ' }', + ' for (var i = 0; i < a.length; i++) {', + ' if (!equals(a[i], b[i])) {', + ' return false;', + ' }', + ' }', + ' return true;', + ' }', + ' return false;', + ' }', + ' if (equals(actual, expected)) {', + ' ' + resultsVar + '.push([true, "OK", message]);', + ' } else {', + ' ' + resultsVar + '.push([false, ' + + '"Expected: " + expected + "\\nActual: " + actual, message]);', + ' }', + '}']); + return functionName; +}; + +Blockly.JavaScript['unittest_assertequals'] = function(block) { + // Asserts that a value equals another value. + var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', + Blockly.JavaScript.ORDER_NONE) || ''; + var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL', + Blockly.JavaScript.ORDER_COMMA) || 'null'; + var expected = Blockly.JavaScript.valueToCode(block, 'EXPECTED', + Blockly.JavaScript.ORDER_COMMA) || 'null'; + return Blockly.JavaScript['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ');\n'; +}; + +Blockly.JavaScript['unittest_assertvalue'] = function(block) { + // Asserts that a value is true, false, or null. + var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', + Blockly.JavaScript.ORDER_NONE) || ''; + var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL', + Blockly.JavaScript.ORDER_COMMA) || 'null'; + var expected = block.getFieldValue('EXPECTED'); + if (expected == 'TRUE') { + expected = 'true'; + } else if (expected == 'FALSE') { + expected = 'false'; + } else if (expected == 'NULL') { + expected = 'null'; + } + return Blockly.JavaScript['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ');\n'; +}; + +Blockly.JavaScript['unittest_fail'] = function(block) { + // Always assert an error. + var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE', + Blockly.JavaScript.ORDER_NONE) || ''; + var functionName = Blockly.JavaScript.provideFunction_( + 'unittest_fail', + [ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + + '(message) {', + ' // Always assert an error.', + ' if (!' + resultsVar + ') {', + ' throw "Orphaned assert fail: " + message;', + ' }', + ' ' + resultsVar + '.push([false, "Fail.", message]);', + '}']); + return functionName + '(' + message + ');\n'; +}; + +Blockly.JavaScript['unittest_adjustindex'] = function(block) { + var index = Blockly.JavaScript.valueToCode(block, 'INDEX', + Blockly.JavaScript.ORDER_ADDITION) || '0'; + // Adjust index if using one-based indexing. + if (Blockly.JavaScript.ONE_BASED_INDEXING) { + if (Blockly.isNumber(index)) { + // If the index is a naked number, adjust it right now. + return [parseFloat(index) + 1, Blockly.JavaScript.ORDER_ATOMIC]; + } else { + // If the index is dynamic, adjust it in code. + index = index + ' + 1'; + } + } else if (Blockly.isNumber(index)) { + return [index, Blockly.JavaScript.ORDER_ATOMIC]; + } + return [index, Blockly.JavaScript.ORDER_ADDITION]; +}; diff --git a/blockly/tests/generators/unittest_lua.js b/blockly/tests/generators/unittest_lua.js new file mode 100644 index 0000000..d687b09 --- /dev/null +++ b/blockly/tests/generators/unittest_lua.js @@ -0,0 +1,179 @@ +/** + * @license + * Visual Blocks Language + * + * Copyright 2016 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Generating Lua for unit test blocks. + * @author rodrigoq@google.com (Rodrigo Queiro) + */ +'use strict'; + +Blockly.Lua['unittest_main'] = function(block) { + // Container for unit tests. + var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.Lua.provideFunction_( + 'unittest_report', + ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '()', + ' -- Create test report.', + ' local report = {}', + ' local summary = {}', + ' local fails = 0', + ' for _, v in pairs(' + resultsVar + ') do', + ' if v["success"] then', + ' table.insert(summary, ".")', + ' else', + ' table.insert(summary, "F")', + ' fails = fails + 1', + ' table.insert(report, "FAIL: " .. v["title"])', + ' table.insert(report, v["log"])', + ' end', + ' end', + ' table.insert(report, 1, table.concat(summary))', + ' table.insert(report, "")', + ' table.insert(report, "Number of tests run: " .. #' + resultsVar + ')', + ' table.insert(report, "")', + ' if fails > 0 then', + ' table.insert(report, "FAILED (failures=" .. fails .. ")")', + ' else', + ' table.insert(report, "OK")', + ' end', + ' return table.concat(report, "\\n")', + 'end']); + // Setup global to hold test results. + var code = resultsVar + ' = {}\n'; + // Run tests (unindented). + code += Blockly.Lua.statementToCode(block, 'DO') + .replace(/^ /, '').replace(/\n /g, '\n'); + var reportVar = Blockly.Lua.variableDB_.getDistinctName( + 'report', Blockly.Variables.NAME_TYPE); + code += reportVar + ' = ' + functionName + '()\n'; + // Destroy results. + code += resultsVar + ' = nil\n'; + // Print the report. + code += 'print(' + reportVar + ')\n'; + return code; +}; + +Blockly.Lua['unittest_main'].defineAssert_ = function(block) { + var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.Lua.provideFunction_( + 'assertEquals', + ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + + '(actual, expected, message)', + ' -- Asserts that a value equals another value.', + ' assert(' + resultsVar + ' ~= nil, ' + + '"Orphaned assert equals: " .. message)', + ' if type(actual) == "table" and type(expected) == "table" then', + ' local lists_match = #actual == #expected', + ' if lists_match then', + ' for i, v1 in ipairs(actual) do', + ' local v2 = expected[i]', + ' if type(v1) == "number" and type(v2) == "number" then', + ' if math.abs(v1 - v2) > 1e-9 then', + ' lists_match = false', + ' end', + ' elseif v1 ~= v2 then', + ' lists_match = false', + ' end', + ' end', + ' end', + ' if lists_match then', + ' table.insert(' + resultsVar + + ', {success=true, log="OK", title=message})', + ' return', + ' else', + ' -- produce the non-matching strings for a human-readable error', + ' expected = "{" .. table.concat(expected, ", ") .. "}"', + ' actual = "{" .. table.concat(actual, ", ") .. "}"', + ' end', + ' end', + ' if actual == expected or (type(actual) == "number" and ' + + 'type(expected) == "number" and math.abs(actual - expected) < ' + + '1e-9) then ', + ' table.insert(' + resultsVar + + ', {success=true, log="OK", title=message})', + ' else', + ' table.insert(' + resultsVar + ', {success=false, ' + + 'log=string.format("Expected: %s\\nActual: %s"' + + ', tostring(expected), tostring(actual)), title=message})', + ' end', + 'end']); + return functionName; +}; + +Blockly.Lua['unittest_assertequals'] = function(block) { + // Asserts that a value equals another value. + var message = Blockly.Lua.valueToCode(block, 'MESSAGE', + Blockly.Lua.ORDER_NONE) || ''; + var actual = Blockly.Lua.valueToCode(block, 'ACTUAL', + Blockly.Lua.ORDER_NONE) || 'nil'; + var expected = Blockly.Lua.valueToCode(block, 'EXPECTED', + Blockly.Lua.ORDER_NONE) || 'nil'; + return Blockly.Lua['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ')\n'; +}; + +Blockly.Lua['unittest_assertvalue'] = function(block) { + // Asserts that a value is true, false, or null. + var message = Blockly.Lua.valueToCode(block, 'MESSAGE', + Blockly.Lua.ORDER_NONE) || ''; + var actual = Blockly.Lua.valueToCode(block, 'ACTUAL', + Blockly.Lua.ORDER_NONE) || 'nil'; + var expected = block.getFieldValue('EXPECTED'); + if (expected == 'TRUE') { + expected = 'true'; + } else if (expected == 'FALSE') { + expected = 'false'; + } else if (expected == 'NULL') { + expected = 'nil'; + } + return Blockly.Lua.unittest_main.defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ')\n'; +}; + +Blockly.Lua['unittest_fail'] = function(block) { + // Always assert an error. + var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var message = Blockly.Lua.valueToCode(block, 'MESSAGE', + Blockly.Lua.ORDER_NONE) || ''; + var functionName = Blockly.Lua.provideFunction_( + 'unittest_fail', + ['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '(message)', + ' -- Always assert an error.', + ' assert(' + resultsVar + + ' ~= nil, "Orphaned assert fail: " .. message)', + ' table.insert(' + resultsVar + + ', {success=false, log="Fail.", title=message})', + 'end']); + return functionName + '(' + message + ')\n'; +}; + +Blockly.Lua['unittest_adjustindex'] = function(block) { + var index = Blockly.Lua.valueToCode(block, 'INDEX', + Blockly.Lua.ORDER_ADDITIVE) || '0'; + if (Blockly.isNumber(index)) { + // If the index is a naked number, adjust it right now. + return [parseFloat(index) + 1, Blockly.Lua.ORDER_ATOMIC]; + } + // If the index is dynamic, adjust it in code. + return [index + ' + 1', Blockly.Lua.ORDER_ATOMIC]; +}; diff --git a/blockly/tests/generators/unittest_php.js b/blockly/tests/generators/unittest_php.js new file mode 100644 index 0000000..3a80502 --- /dev/null +++ b/blockly/tests/generators/unittest_php.js @@ -0,0 +1,187 @@ +/** + * @license + * Visual Blocks Language + * + * Copyright 2015 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Generating PHP for unit test blocks. + * @author daarond@gmail.com (Daaron Dwyer) + */ +'use strict'; + +Blockly.PHP['unittest_main'] = function(block) { + // Container for unit tests. + var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.PHP.provideFunction_( + 'unittest_report', + [ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + '() {', + 'global ' + resultsVar + ';', + ' // Create test report.', + ' $report = array();', + ' $summary = array();', + ' $fails = 0;', + ' for ($x = 0; $x < count(' + resultsVar + '); $x++) {', + ' if (' + resultsVar + '[$x][0]) {', + ' array_push($summary, ".");', + ' } else {', + ' array_push($summary, "F");', + ' $fails++;', + ' array_push($report,"");', + ' array_push($report, "FAIL: " . ' + resultsVar + '[$x][2]);', + ' array_push($report, ' + resultsVar + '[$x][1]);', + ' }', + ' }', + ' array_unshift($report, implode("",$summary));', + ' array_push($report, "");', + ' array_push($report, "Number of tests run: " . count(' + resultsVar + '));', + ' array_push($report, "");', + ' if ($fails) {', + ' array_push($report, "FAILED (failures=" . $fails + ")");', + ' } else {', + ' array_push($report, "OK");', + ' }', + ' return implode("\\n", $report);', + '}']); + // Setup global to hold test results. + var code = resultsVar + ' = array();\n'; + // Run tests (unindented). + code += Blockly.PHP.statementToCode(block, 'DO') + .replace(/^ /, '').replace(/\n /g, '\n'); + var reportVar = Blockly.PHP.variableDB_.getDistinctName( + 'report', Blockly.Variables.NAME_TYPE); + code += reportVar + ' = ' + functionName + '();\n'; + // Destroy results. + code += resultsVar + ' = null;\n'; + // Send the report to the console (that's where errors will go anyway). + code += 'print(' + reportVar + ');\n'; + return code; +}; + +Blockly.PHP['unittest_main'].defineAssert_ = function(block) { + var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.PHP.provideFunction_( + 'assertEquals', + [' function equals($a, $b) {', + ' if ($a === $b) {', + ' return true;', + ' } else if ((is_numeric($a)) && (is_numeric($b)) &&', + ' (round($a,15) == round($b,15))) {', + ' return true;', + ' } else if (is_array($a) && is_array($b)) {', + ' if (count($a) != count($b)) {', + ' return false;', + ' }', + ' for ($i = 0; $i < count($a); $i++) {', + ' if (!equals($a[$i], $b[$i])) {', + ' return false;', + ' }', + ' }', + ' return true;', + ' }', + ' return false;', + ' }', + 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + + '($actual, $expected, $message) {', + 'global ' + resultsVar + ';', + ' // Asserts that a value equals another value.', + ' if (!is_array(' + resultsVar + ')) {', + ' throw new Exception("Orphaned assert: " . $message);', + ' }', + ' if (equals($actual, $expected)) {', + ' array_push(' + resultsVar + ', [true, "OK", $message]);', + ' } else {', + ' $expected = is_array($expected) ? implode(" ", $expected) : ' + + '$expected;', + ' $actual = is_array($actual) ? implode(" ", $actual) : ' + + '$actual;', + ' array_push(' + resultsVar + ', [false, ' + + '"Expected: " . $expected . "\\nActual: " . $actual, $message]);', + ' }', + '}']); + return functionName; +}; + +Blockly.PHP['unittest_assertequals'] = function(block) { + // Asserts that a value equals another value. + var message = Blockly.PHP.valueToCode(block, 'MESSAGE', + Blockly.PHP.ORDER_NONE) || ''; + var actual = Blockly.PHP.valueToCode(block, 'ACTUAL', + Blockly.PHP.ORDER_COMMA) || 'null'; + var expected = Blockly.PHP.valueToCode(block, 'EXPECTED', + Blockly.PHP.ORDER_COMMA) || 'null'; + return Blockly.PHP['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ');\n'; +}; + +Blockly.PHP['unittest_assertvalue'] = function(block) { + // Asserts that a value is true, false, or null. + var message = Blockly.PHP.valueToCode(block, 'MESSAGE', + Blockly.PHP.ORDER_NONE) || ''; + var actual = Blockly.PHP.valueToCode(block, 'ACTUAL', + Blockly.PHP.ORDER_COMMA) || 'null'; + var expected = block.getFieldValue('EXPECTED'); + if (expected == 'TRUE') { + expected = 'true'; + } else if (expected == 'FALSE') { + expected = 'false'; + } else if (expected == 'NULL') { + expected = 'null'; + } + return Blockly.PHP['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ');\n'; +}; + +Blockly.PHP['unittest_fail'] = function(block) { + // Always assert an error. + var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var message = Blockly.PHP.valueToCode(block, 'MESSAGE', + Blockly.PHP.ORDER_NONE) || ''; + var functionName = Blockly.PHP.provideFunction_( + 'unittest_fail', + [ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + + '($message) {', + 'global ' + resultsVar + ';', + ' // Always assert an error.', + ' if (!' + resultsVar + ') {', + ' throw new Exception("Orphaned assert fail: " . $message);', + ' }', + ' array_push(' + resultsVar + ', [false, "Fail.", $message]);', + '}']); + return functionName + '(' + message + ');\n'; +}; + +Blockly.PHP['unittest_adjustindex'] = function(block) { + var index = Blockly.PHP.valueToCode(block, 'INDEX', + Blockly.PHP.ORDER_ADDITION) || '0'; + // Adjust index if using one-based indexing. + if (Blockly.PHP.ONE_BASED_INDEXING) { + if (Blockly.isNumber(index)) { + // If the index is a naked number, adjust it right now. + return [parseFloat(index) + 1, Blockly.PHP.ORDER_ATOMIC]; + } else { + // If the index is dynamic, adjust it in code. + index = index + ' + 1'; + } + } else if (Blockly.isNumber(index)) { + return [index, Blockly.PHP.ORDER_ATOMIC]; + } + return [index, Blockly.PHP.ORDER_ADDITION]; +}; diff --git a/blockly/tests/generators/unittest_python.js b/blockly/tests/generators/unittest_python.js new file mode 100644 index 0000000..2b459aa --- /dev/null +++ b/blockly/tests/generators/unittest_python.js @@ -0,0 +1,152 @@ +/** + * @license + * Visual Blocks Language + * + * Copyright 2012 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Generating Python for unit test blocks. + * @author fraser@google.com (Neil Fraser) + */ +'use strict'; + +Blockly.Python['unittest_main'] = function(block) { + // Container for unit tests. + var resultsVar = Blockly.Python.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.Python.provideFunction_( + 'unittest_report', + ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '():', + ' # Create test report.', + ' report = []', + ' summary = []', + ' fails = 0', + ' for (success, log, message) in ' + resultsVar + ':', + ' if success:', + ' summary.append(".")', + ' else:', + ' summary.append("F")', + ' fails += 1', + ' report.append("")', + ' report.append("FAIL: " + message)', + ' report.append(log)', + ' report.insert(0, "".join(summary))', + ' report.append("")', + ' report.append("Number of tests run: %d" % len(' + resultsVar + '))', + ' report.append("")', + ' if fails:', + ' report.append("FAILED (failures=%d)" % fails)', + ' else:', + ' report.append("OK")', + ' return "\\n".join(report)']); + + // Setup global to hold test results. + var code = resultsVar + ' = []\n'; + // Run tests (unindented). + code += Blockly.Python.statementToCode(block, 'DO') + .replace(/^ /, '').replace(/\n /g, '\n'); + var reportVar = Blockly.Python.variableDB_.getDistinctName( + 'report', Blockly.Variables.NAME_TYPE); + code += reportVar + ' = ' + functionName + '()\n'; + // Destroy results. + code += resultsVar + ' = None\n'; + // Print the report. + code += 'print(' + reportVar + ')\n'; + return code; +}; + +Blockly.Python['unittest_main'].defineAssert_ = function() { + var resultsVar = Blockly.Python.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var functionName = Blockly.Python.provideFunction_( + 'assertEquals', + ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + + '(actual, expected, message):', + ' # Asserts that a value equals another value.', + ' if ' + resultsVar + ' == None:', + ' raise Exception("Orphaned assert equals: " + message)', + ' if actual == expected:', + ' ' + resultsVar + '.append((True, "OK", message))', + ' else:', + ' ' + resultsVar + '.append((False, ' + + '"Expected: %s\\nActual: %s" % (expected, actual), message))']); + return functionName; +}; + +Blockly.Python['unittest_assertequals'] = function(block) { + // Asserts that a value equals another value. + var message = Blockly.Python.valueToCode(block, 'MESSAGE', + Blockly.Python.ORDER_NONE) || ''; + var actual = Blockly.Python.valueToCode(block, 'ACTUAL', + Blockly.Python.ORDER_NONE) || 'None'; + var expected = Blockly.Python.valueToCode(block, 'EXPECTED', + Blockly.Python.ORDER_NONE) || 'None'; + return Blockly.Python['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ')\n'; +}; + +Blockly.Python['unittest_assertvalue'] = function(block) { + // Asserts that a value is true, false, or null. + var message = Blockly.Python.valueToCode(block, 'MESSAGE', + Blockly.Python.ORDER_NONE) || ''; + var actual = Blockly.Python.valueToCode(block, 'ACTUAL', + Blockly.Python.ORDER_NONE) || 'None'; + var expected = block.getFieldValue('EXPECTED'); + if (expected == 'TRUE') { + expected = 'True'; + } else if (expected == 'FALSE') { + expected = 'False'; + } else if (expected == 'NULL') { + expected = 'None'; + } + return Blockly.Python['unittest_main'].defineAssert_() + + '(' + actual + ', ' + expected + ', ' + message + ')\n'; +}; + +Blockly.Python['unittest_fail'] = function(block) { + // Always assert an error. + var resultsVar = Blockly.Python.variableDB_.getName('unittestResults', + Blockly.Variables.NAME_TYPE); + var message = Blockly.Python.valueToCode(block, 'MESSAGE', + Blockly.Python.ORDER_NONE) || ''; + var functionName = Blockly.Python.provideFunction_( + 'fail', + ['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '(message):', + ' # Always assert an error.', + ' if ' + resultsVar + ' == None:', + ' raise Exception("Orphaned assert equals: " + message)', + ' ' + resultsVar + '.append((False, "Fail.", message))']); + return functionName + '(' + message + ')\n'; +}; + +Blockly.Python['unittest_adjustindex'] = function(block) { + var index = Blockly.Python.valueToCode(block, 'INDEX', + Blockly.Python.ORDER_ADDITIVE) || '0'; + // Adjust index if using one-based indexing. + if (Blockly.Python.ONE_BASED_INDEXING) { + if (Blockly.isNumber(index)) { + // If the index is a naked number, adjust it right now. + return [parseFloat(index) + 1, Blockly.Python.ORDER_ATOMIC]; + } else { + // If the index is dynamic, adjust it in code. + index = index + ' + 1'; + } + } else if (Blockly.isNumber(index)) { + return [index, Blockly.Python.ORDER_ATOMIC]; + } + return [index, Blockly.Python.ORDER_ADDITIVE]; +}; diff --git a/blockly/tests/generators/variables.xml b/blockly/tests/generators/variables.xml new file mode 100644 index 0000000..a11d0a0 --- /dev/null +++ b/blockly/tests/generators/variables.xml @@ -0,0 +1,66 @@ +<xml xmlns="http://www.w3.org/1999/xhtml"> + <block type="unittest_main" x="0" y="0"> + <statement name="DO"> + <block type="variables_set" inline="false"> + <field name="VAR">item</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">123</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">variable</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">item</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">123</field> + </block> + </value> + <next> + <block type="variables_set" inline="false"> + <field name="VAR">if</field> + <value name="VALUE"> + <block type="math_number"> + <field name="NUM">123</field> + </block> + </value> + <next> + <block type="unittest_assertequals" inline="false"> + <value name="MESSAGE"> + <block type="text"> + <field name="TEXT">reserved variable</field> + </block> + </value> + <value name="ACTUAL"> + <block type="variables_get"> + <field name="VAR">if</field> + </block> + </value> + <value name="EXPECTED"> + <block type="math_number"> + <field name="NUM">123</field> + </block> + </value> + </block> + </next> + </block> + </next> + </block> + </next> + </block> + </statement> + </block> + <block type="variables_get" x="300" y="100"> + <field name="VAR">naked</field> + <comment pinned="true" h="80" w="160">Intentionally non-connected variable.</comment> + </block> +</xml> diff --git a/blockly/tests/jsunit/blockly_test.js b/blockly/tests/jsunit/blockly_test.js new file mode 100644 index 0000000..0278b84 --- /dev/null +++ b/blockly/tests/jsunit/blockly_test.js @@ -0,0 +1,140 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2011 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function test_genUid() { + var uuids = {}; + for (var i = 0; i < 1000; i++) { + var uuid = Blockly.genUid(); + assertFalse('UUID different: ' + uuid, uuid in uuids); + uuids[uuid] = true; + } +} + +function test_addClass() { + var p = document.createElement('p'); + Blockly.addClass_(p, 'one'); + assertEquals('Adding "one"', 'one', p.className); + Blockly.addClass_(p, 'one'); + assertEquals('Adding duplicate "one"', 'one', p.className); + Blockly.addClass_(p, 'two'); + assertEquals('Adding "two"', 'one two', p.className); + Blockly.addClass_(p, 'two'); + assertEquals('Adding duplicate "two"', 'one two', p.className); + Blockly.addClass_(p, 'three'); + assertEquals('Adding "three"', 'one two three', p.className); +} + +function test_removeClass() { + var p = document.createElement('p'); + p.className = ' one three two three '; + Blockly.removeClass_(p, 'two'); + assertEquals('Removing "two"', 'one three three', p.className); + Blockly.removeClass_(p, 'four'); + assertEquals('Removing "four"', 'one three three', p.className); + Blockly.removeClass_(p, 'three'); + assertEquals('Removing "three"', 'one', p.className); + Blockly.removeClass_(p, 'ne'); + assertEquals('Removing "ne"', 'one', p.className); + Blockly.removeClass_(p, 'one'); + assertEquals('Removing "one"', '', p.className); + Blockly.removeClass_(p, 'zero'); + assertEquals('Removing "zero"', '', p.className); +} + +function test_hasClass() { + var p = document.createElement('p'); + p.className = ' one three two three '; + assertTrue('Has "one"', Blockly.hasClass_(p, 'one')); + assertTrue('Has "two"', Blockly.hasClass_(p, 'two')); + assertTrue('Has "three"', Blockly.hasClass_(p, 'three')); + assertFalse('Has no "four"', Blockly.hasClass_(p, 'four')); + assertFalse('Has no "t"', Blockly.hasClass_(p, 't')); +} + +function test_shortestStringLength() { + var len = Blockly.shortestStringLength('one,two,three,four,five'.split(',')); + assertEquals('Length of "one"', 3, len); + len = Blockly.shortestStringLength('one,two,three,four,five,'.split(',')); + assertEquals('Length of ""', 0, len); + len = Blockly.shortestStringLength(['Hello World']); + assertEquals('List of one', 11, len); + len = Blockly.shortestStringLength([]); + assertEquals('Empty list', 0, len); +} + +function test_commonWordPrefix() { + var len = Blockly.commonWordPrefix('one,two,three,four,five'.split(',')); + assertEquals('No prefix', 0, len); + len = Blockly.commonWordPrefix('Xone,Xtwo,Xthree,Xfour,Xfive'.split(',')); + assertEquals('No word prefix', 0, len); + len = Blockly.commonWordPrefix('abc de,abc de,abc de,abc de'.split(',')); + assertEquals('Full equality', 6, len); + len = Blockly.commonWordPrefix('abc deX,abc deY'.split(',')); + assertEquals('One word prefix', 4, len); + len = Blockly.commonWordPrefix('abc de,abc deY'.split(',')); + assertEquals('Overflow no', 4, len); + len = Blockly.commonWordPrefix('abc de,abc de Y'.split(',')); + assertEquals('Overflow yes', 6, len); + len = Blockly.commonWordPrefix(['Hello World']); + assertEquals('List of one', 11, len); + len = Blockly.commonWordPrefix([]); + assertEquals('Empty list', 0, len); + len = Blockly.commonWordPrefix('turn left,turn right'.split(',')); + assertEquals('No prefix due to &nbsp;', 0, len); + len = Blockly.commonWordPrefix('turn\u00A0left,turn\u00A0right'.split(',')); + assertEquals('No prefix due to \\u00A0', 0, len); +} + +function test_commonWordSuffix() { + var len = Blockly.commonWordSuffix('one,two,three,four,five'.split(',')); + assertEquals('No prefix', 0, len); + len = Blockly.commonWordSuffix('oneX,twoX,threeX,fourX,fiveX'.split(',')); + assertEquals('No word prefix', 0, len); + len = Blockly.commonWordSuffix('abc de,abc de,abc de,abc de'.split(',')); + assertEquals('Full equality', 6, len); + len = Blockly.commonWordSuffix('Xabc de,Yabc de'.split(',')); + assertEquals('One word prefix', 3, len); + len = Blockly.commonWordSuffix('abc de,Yabc de'.split(',')); + assertEquals('Overflow no', 3, len); + len = Blockly.commonWordSuffix('abc de,Y abc de'.split(',')); + assertEquals('Overflow yes', 6, len); + len = Blockly.commonWordSuffix(['Hello World']); + assertEquals('List of one', 11, len); + len = Blockly.commonWordSuffix([]); + assertEquals('Empty list', 0, len); +} + +function test_tokenizeInterpolation() { + var tokens = Blockly.utils.tokenizeInterpolation(''); + assertArrayEquals('Null interpolation', [], tokens); + tokens = Blockly.utils.tokenizeInterpolation('Hello'); + assertArrayEquals('No interpolation', ['Hello'], tokens); + tokens = Blockly.utils.tokenizeInterpolation('Hello%World'); + assertArrayEquals('Unescaped %.', ['Hello%World'], tokens); + tokens = Blockly.utils.tokenizeInterpolation('Hello%%World'); + assertArrayEquals('Escaped %.', ['Hello%World'], tokens); + tokens = Blockly.utils.tokenizeInterpolation('Hello %1 World'); + assertArrayEquals('Interpolation.', ['Hello ', 1, ' World'], tokens); + tokens = Blockly.utils.tokenizeInterpolation('%123Hello%456World%789'); + assertArrayEquals('Interpolations.', [123, 'Hello', 456, 'World', 789], tokens); + tokens = Blockly.utils.tokenizeInterpolation('%%%x%%0%00%01%'); + assertArrayEquals('Torture interpolations.', ['%%x%0', 0, 1, '%'], tokens); +} diff --git a/blockly/tests/jsunit/connection_db_test.js b/blockly/tests/jsunit/connection_db_test.js new file mode 100644 index 0000000..558edf1 --- /dev/null +++ b/blockly/tests/jsunit/connection_db_test.js @@ -0,0 +1,307 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2015 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function verify_DB_(msg, expected, db) { + var equal = (expected.length == db.length); + if (equal) { + for (var i = 0; i < expected.length; i++) { + if (expected[i] != db[i]) { + equal = false; + break; + } + } + } + if (equal) { + assertTrue(msg, true); + } else { + assertEquals(msg, expected, db); + } +} + +function test_DB_addConnection() { + var db = new Blockly.ConnectionDB(); + var o2 = {y_: 2, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + db.addConnection(o2); + verify_DB_('Adding connection #2', [o2], db); + + var o4 = {y_: 4, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + db.addConnection(o4); + verify_DB_('Adding connection #4', [o2, o4], db); + + var o1 = {y_: 1, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + db.addConnection(o1); + verify_DB_('Adding connection #1', [o1, o2, o4], db); + + var o3a = {y_: 3, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + db.addConnection(o3a); + verify_DB_('Adding connection #3a', [o1, o2, o3a, o4], db); + + var o3b = {y_: 3, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + db.addConnection(o3b); + verify_DB_('Adding connection #3b', [o1, o2, o3b, o3a, o4], db); +} + +function test_DB_removeConnection() { + var db = new Blockly.ConnectionDB(); + var o1 = {y_: 1, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + var o2 = {y_: 2, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + var o3a = {y_: 3, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + var o3b = {y_: 3, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + var o3c = {y_: 3, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + var o4 = {y_: 4, sourceBlock_: {}, + getSourceBlock: Blockly.Connection.prototype.getSourceBlock}; + db.addConnection(o1); + db.addConnection(o2); + db.addConnection(o3c); + db.addConnection(o3b); + db.addConnection(o3a); + db.addConnection(o4); + verify_DB_('Adding connections 1-4', [o1, o2, o3a, o3b, o3c, o4], db); + + db.removeConnection_(o2); + verify_DB_('Removing connection #2', [o1, o3a, o3b, o3c, o4], db); + + db.removeConnection_(o4); + verify_DB_('Removing connection #4', [o1, o3a, o3b, o3c], db); + + db.removeConnection_(o1); + verify_DB_('Removing connection #1', [o3a, o3b, o3c], db); + + db.removeConnection_(o3a); + verify_DB_('Removing connection #3a', [o3b, o3c], db); + + db.removeConnection_(o3c); + verify_DB_('Removing connection #3c', [o3b], db); + + db.removeConnection_(o3b); + verify_DB_('Removing connection #3b', [], db); +} + +function test_DB_getNeighbours() { + var db = new Blockly.ConnectionDB(); + + // Search an empty list. + assertEquals(helper_getNeighbours(db, + 10 /* x */, 10 /* y */, 100 /* radius */).length, 0); + + // Set up some connections. + for (var i = 0; i < 10; i++) { + db.addConnection(helper_createConnection(0, i, + Blockly.PREVIOUS_STATEMENT, null, true)); + } + + // Test block belongs at beginning. + var result = helper_getNeighbours(db, 0, 0, 4); + assertEquals(5, result.length); + for (i = 0; i < result.length; i++) { + assertNotEquals(result.indexOf(db[i]), -1); // contains + } + + // Test block belongs at middle. + result = helper_getNeighbours(db, 0, 4, 2); + assertEquals(5, result.length); + for (i = 0; i < result.length; i++) { + assertNotEquals(result.indexOf(db[i + 2]), -1); // contains + } + + // Test block belongs at end. + result = helper_getNeighbours(db, 0, 9, 4); + assertEquals(5, result.length); + for (i = 0; i < result.length; i++) { + assertNotEquals(result.indexOf(db[i + 5]), -1); // contains + } + + // Test block has no neighbours due to being out of range in the x direction. + result = helper_getNeighbours(db, 10, 9, 4); + assertEquals(result.length, 0); + + // Test block has no neighbours due to being out of range in the y direction. + result = helper_getNeighbours(db, 0, 19, 4); + assertEquals(result.length, 0); + + // Test block has no neighbours due to being out of range diagonally. + result = helper_getNeighbours(db, -2, -2, 2); + assertEquals(result.length, 0); +} + +function test_DB_findPositionForConnection() { + var db = new Blockly.ConnectionDB(); + db.addConnection(helper_createConnection(0, 0, Blockly.PREVIOUS_STATEMENT, + null, true)); + db.addConnection(helper_createConnection(0, 1, Blockly.PREVIOUS_STATEMENT, + null, true)); + db.addConnection(helper_createConnection(0, 2, Blockly.PREVIOUS_STATEMENT, + null, true)); + db.addConnection(helper_createConnection(0, 4, Blockly.PREVIOUS_STATEMENT, + null, true)); + db.addConnection(helper_createConnection(0, 5, Blockly.PREVIOUS_STATEMENT, + null, true)); + + assertEquals(5, db.length); + var conn = helper_createConnection(0, 3, Blockly.PREVIOUS_STATEMENT, null, + true); + assertEquals(3, db.findPositionForConnection_(conn)); +} + +function test_DB_findConnection() { + var db = new Blockly.ConnectionDB(); + for (var i = 0; i < 10; i++) { + db.addConnection(helper_createConnection(i, 0, + Blockly.PREVIOUS_STATEMENT, null, true)); + db.addConnection(helper_createConnection(0, i, + Blockly.PREVIOUS_STATEMENT, null, true)); + } + + var conn = helper_createConnection(3, 3, Blockly.PREVIOUS_STATEMENT, null, + true); + db.addConnection(conn); + assertEquals(conn, db[db.findConnection(conn)]); + + conn = helper_createConnection(3, 3, Blockly.PREVIOUS_STATEMENT, null, true); + assertEquals(-1, db.findConnection(conn)); +} + +function test_DB_ordering() { + var db = new Blockly.ConnectionDB(); + for (var i = 0; i < 10; i++) { + db.addConnection(helper_createConnection(0, 9 - i, + Blockly.PREVIOUS_STATEMENT), null, true); + } + + for (i = 0; i < 10; i++) { + assertEquals(i, db[i].y_); + } + + // quasi-random + var xCoords = [-29, -47, -77, 2, 43, 34, -59, -52, -90, -36, -91, 38, 87, -20, + 60, 4, -57, 65, -37, -81, 57, 58, -96, 1, 67, -79, 34, 93, -90, -99, -62, + 4, 11, -36, -51, -72, 3, -50, -24, -45, -92, -38, 37, 24, -47, -73, 79, + -20, 99, 43, -10, -87, 19, 35, -62, -36, 49, 86, -24, -47, -89, 33, -44, + 25, -73, -91, 85, 6, 0, 89, -94, 36, -35, 84, -9, 96, -21, 52, 10, -95, 7, + -67, -70, 62, 9, -40, -95, -9, -94, 55, 57, -96, 55, 8, -48, -57, -87, 81, + 23, 65]; + var yCoords = [-81, 82, 5, 47, 30, 57, -12, 28, 38, 92, -25, -20, 23, -51, 73, + -90, 8, 28, -51, -15, 81, -60, -6, -16, 77, -62, -42, -24, 35, 95, -46, + -7, 61, -16, 14, 91, 57, -38, 27, -39, 92, 47, -98, 11, -33, -72, 64, 38, + -64, -88, -35, -59, -76, -94, 45, -25, -100, -95, 63, -97, 45, 98, 99, 34, + 27, 52, -18, -45, 66, -32, -38, 70, -73, -23, 5, -2, -13, -9, 48, 74, -97, + -11, 35, -79, -16, -77, 83, -57, -53, 35, -44, 100, -27, -15, 5, 39, 33, + -19, -20, -95]; + for (i = 0; i < xCoords.length; i++) { + db.addConnection(helper_createConnection(xCoords[i], yCoords[i], + Blockly.PREVIOUS_STATEMENT), null, true); + } + + for (i = 1; i < xCoords.length; i++) { + assertTrue(db[i].y_ >= db[i - 1].y_); + } +} + +function test_SearchForClosest() { + var db = new Blockly.ConnectionDB(); + var sharedWorkspace = {id: "Shared workspace"}; + + // Search an empty list. + assertEquals(null, helper_searchDB(db, 10 /* x */, 10 /* y */, + 100 /* radius */)); + + db.addConnection(helper_createConnection(100, 0, Blockly.PREVIOUS_STATEMENT, + sharedWorkspace, true)); + assertEquals(null, helper_searchDB(db, 0, 0, 5, sharedWorkspace)); + + db = new Blockly.ConnectionDB(); + for (var i = 0; i < 10; i++) { + var tempConn = helper_createConnection(0, i, Blockly.PREVIOUS_STATEMENT, + sharedWorkspace, true); + tempConn.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + db.addConnection(tempConn); + } + + // Should be at 0, 9. + var last = db[db.length - 1]; + // Correct connection is last in db; many connections in radius. + assertEquals(last, helper_searchDB(db, 0, 10, 15, sharedWorkspace)); + // Nothing nearby. + assertEquals(null, helper_searchDB(db, 100, 100, 3, sharedWorkspace)); + // First in db, exact match. + assertEquals(db[0], helper_searchDB(db, 0, 0, 0, sharedWorkspace)); + + tempConn = helper_createConnection(6, 6, Blockly.PREVIOUS_STATEMENT, + sharedWorkspace, true); + tempConn.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + db.addConnection(tempConn); + tempConn = helper_createConnection(5, 5, Blockly.PREVIOUS_STATEMENT, + sharedWorkspace, true); + tempConn.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + db.addConnection(tempConn); + + var result = helper_searchDB(db, 4, 6, 3, sharedWorkspace); + assertEquals(5, result.x_); + assertEquals(5, result.y_); +} + + +function helper_getNeighbours(db, x, y, radius) { + return db.getNeighbours(helper_createConnection(x, y, Blockly.NEXT_STATEMENT, + null, true), + radius); +} + +function helper_searchDB(db, x, y, radius, shared_workspace) { + var tempConn = helper_createConnection(x, y, + Blockly.NEXT_STATEMENT, shared_workspace, true); + tempConn.sourceBlock_ = helper_makeSourceBlock(shared_workspace); + var closest = db.searchForClosest(tempConn, radius, {x: 0, y: 0}); + return closest.connection; +} + +function helper_makeSourceBlock(sharedWorkspace) { + return {workspace: sharedWorkspace, + parentBlock_: null, + getParent: function() { return null; }, + movable_: true, + isMovable: function() { return true; }, + isShadow: function() { return false; } + }; +} + +function helper_createConnection(x, y, type, opt_shared_workspace, + opt_rendered) { + var workspace = opt_shared_workspace ? opt_shared_workspace : {}; + if (opt_rendered) { + var conn = new Blockly.RenderedConnection({workspace: workspace}, type); + } else { + var conn = new Blockly.Connection({workspace: workspace}, type); + } + conn.x_ = x; + conn.y_ = y; + return conn; +}
\ No newline at end of file diff --git a/blockly/tests/jsunit/connection_test.js b/blockly/tests/jsunit/connection_test.js new file mode 100644 index 0000000..0d10e63 --- /dev/null +++ b/blockly/tests/jsunit/connection_test.js @@ -0,0 +1,324 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2016 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Tests for connection logic. + * @author fenichel@google.com (Rachel Fenichel) + */ +'use strict'; + +var input; +var output; +var previous; +var next; + +var dummyWorkspace; + +function connectionTest_setUp() { + dummyWorkspace = {}; + function createDummyBlock() { + return { + workspace: dummyWorkspace, + isShadow: function() {return false;} + }; + } + input = new Blockly.Connection(createDummyBlock(), + Blockly.INPUT_VALUE); + output = new Blockly.Connection(createDummyBlock(), + Blockly.OUTPUT_VALUE); + previous = new Blockly.Connection(createDummyBlock(), + Blockly.PREVIOUS_STATEMENT); + next = new Blockly.Connection(createDummyBlock(), + Blockly.NEXT_STATEMENT); +} + +function connectionTest_tearDown() { + input = null; + output = null; + previous = null; + next = null; + dummyWorkspace = null; +} + +var isMovableFn = function() { return true; }; +/** + * These tests check that the reasons for failures to connect are consistent + * (internal view of error states). + */ +function testCanConnectWithReason_TargetNull() { + connectionTest_setUp(); + + assertEquals(Blockly.Connection.REASON_TARGET_NULL, + input.canConnectWithReason_(null)); + + connectionTest_tearDown(); +} + +function testCanConnectWithReason_Disconnect() { + connectionTest_setUp(); + + var tempConnection = new Blockly.Connection({workspace: dummyWorkspace, isMovable: isMovableFn}, + Blockly.OUTPUT_VALUE); + Blockly.Connection.connectReciprocally_(input, tempConnection); + assertEquals(Blockly.Connection.CAN_CONNECT, + input.canConnectWithReason_(output)); + + connectionTest_tearDown(); +} + +function testCanConnectWithReason_DifferentWorkspaces() { + connectionTest_setUp(); + + input = new Blockly.Connection({workspace: {}}, Blockly.INPUT_VALUE); + output = new Blockly.Connection({workspace: dummyWorkspace}, + Blockly.OUTPUT_VALUE); + + assertEquals(Blockly.Connection.REASON_DIFFERENT_WORKSPACES, + input.canConnectWithReason_(output)); + + connectionTest_tearDown(); +} + + +function testCanConnectWithReason_Self() { + connectionTest_setUp(); + + var block = {type_: "test block"}; + input.sourceBlock_ = block; + assertEquals(Blockly.Connection.REASON_SELF_CONNECTION, + input.canConnectWithReason_(input)); + + connectionTest_tearDown(); +} + +function testCanConnectWithReason_Type() { + connectionTest_setUp(); + + assertEquals(Blockly.Connection.REASON_WRONG_TYPE, + input.canConnectWithReason_(previous)); + assertEquals(Blockly.Connection.REASON_WRONG_TYPE, + input.canConnectWithReason_(next)); + + assertEquals(Blockly.Connection.REASON_WRONG_TYPE, + output.canConnectWithReason_(previous)); + assertEquals(Blockly.Connection.REASON_WRONG_TYPE, + output.canConnectWithReason_(next)); + + assertEquals(Blockly.Connection.REASON_WRONG_TYPE, + previous.canConnectWithReason_(input)); + assertEquals(Blockly.Connection.REASON_WRONG_TYPE, + previous.canConnectWithReason_(output)); + + assertEquals(Blockly.Connection.REASON_WRONG_TYPE, + next.canConnectWithReason_(input)); + assertEquals(Blockly.Connection.REASON_WRONG_TYPE, + next.canConnectWithReason_(output)); + + connectionTest_tearDown(); +} + +function testCanConnectWithReason_CanConnect() { + connectionTest_setUp(); + + assertEquals(Blockly.Connection.CAN_CONNECT, + previous.canConnectWithReason_(next)); + assertEquals(Blockly.Connection.CAN_CONNECT, + next.canConnectWithReason_(previous)); + assertEquals(Blockly.Connection.CAN_CONNECT, + input.canConnectWithReason_(output)); + assertEquals(Blockly.Connection.CAN_CONNECT, + output.canConnectWithReason_(input)); + + connectionTest_tearDown(); +} + +/** + * The next set of tests checks that exceptions are being thrown at the correct + * times (external view of errors). + */ +function testCheckConnection_Self() { + connectionTest_setUp(); + var block = {type_: "test block"}; + input.sourceBlock_ = block; + try { + input.checkConnection_(input); + fail(); + } catch (e) { + // expected + } + + connectionTest_tearDown(); +} + +function testCheckConnection_TypeInputPrev() { + connectionTest_setUp(); + try { + input.checkConnection_(previous); + fail(); + } catch (e) { + // expected + } + + connectionTest_tearDown(); +} + +function testCheckConnection_TypeInputNext() { + connectionTest_setUp(); + try { + input.checkConnection_(next); + fail(); + } catch (e) { + // expected + } + + connectionTest_tearDown(); +} + +function testCheckConnection_TypeOutputPrev() { + connectionTest_setUp(); + try { + output.checkConnection_(previous); + fail(); + } catch (e) { + // expected + } + + connectionTest_tearDown(); +} + +function testCheckConnection_TypePrevInput() { + connectionTest_setUp(); + try { + previous.checkConnection_(input); + fail(); + } catch (e) { + // expected + } + + connectionTest_tearDown(); +} + +function testCheckConnection_TypePrevOutput() { + connectionTest_setUp(); + try { + previous.checkConnection_(output); + fail(); + } catch (e) { + // expected + } + + connectionTest_tearDown(); +} + +function testCheckConnection_TypeNextInput() { + connectionTest_setUp(); + try { + next.checkConnection_(input); + fail(); + } catch (e) { + // expected + } + + connectionTest_tearDown(); +} + +function testCheckConnection_TypeNextOutput() { + connectionTest_setUp(); + try { + next.checkConnection_(output); + fail(); + } catch (e) { + // expected + } + + connectionTest_tearDown(); +} + +function test_isConnectionAllowed_Distance() { + var sharedWorkspace = {}; + // Two connections of opposite types near each other. + var one = helper_createConnection(5 /* x */, 10 /* y */, + Blockly.INPUT_VALUE, null, true); + one.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + + var two = helper_createConnection(10 /* x */, 15 /* y */, + Blockly.OUTPUT_VALUE, null, true); + two.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + + assertTrue(one.isConnectionAllowed(two, 20.0)); + // Move connections farther apart. + two.x_ = 100; + two.y_ = 100; + assertFalse(one.isConnectionAllowed(two, 20.0)); +} + +function test_isConnectionAllowed_Unrendered() { + var sharedWorkspace = {}; + + var one = helper_createConnection(5 /* x */, 10 /* y */, + Blockly.INPUT_VALUE); + one.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + + // Don't offer to connect an already connected left (male) value plug to + // an available right (female) value plug. + var two = helper_createConnection(0, 0, Blockly.OUTPUT_VALUE); + two.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + + assertTrue(one.isConnectionAllowed(two)); + var three = helper_createConnection(0, 0, Blockly.INPUT_VALUE); + three.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + + Blockly.Connection.connectReciprocally_(two, three); + assertFalse(one.isConnectionAllowed(two)); + + // Don't connect two connections on the same block. + two.sourceBlock_ = one.sourceBlock_; + assertFalse(one.isConnectionAllowed(two)); +} + +function test_isConnectionAllowed_NoNext() { + var sharedWorkspace = {}; + var one = helper_createConnection(0, 0, Blockly.NEXT_STATEMENT); + one.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + one.sourceBlock_.nextConnection = one; + + var two = helper_createConnection(0, 0, Blockly.PREVIOUS_STATEMENT); + two.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + + assertTrue(two.isConnectionAllowed(one)); + + var three = helper_createConnection(0, 0, Blockly.PREVIOUS_STATEMENT); + three.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace); + three.sourceBlock_.previousConnection = three; + Blockly.Connection.connectReciprocally_(one, three); + + // A terminal block is allowed to replace another terminal block. + assertTrue(two.isConnectionAllowed(one)); +} + +function testCheckConnection_Okay() { + connectionTest_setUp(); + previous.checkConnection_(next); + next.checkConnection_(previous); + input.checkConnection_(output); + output.checkConnection_(input); + + connectionTest_tearDown(); +} diff --git a/blockly/tests/jsunit/db_test.js b/blockly/tests/jsunit/db_test.js new file mode 100644 index 0000000..45fc62a --- /dev/null +++ b/blockly/tests/jsunit/db_test.js @@ -0,0 +1,76 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2016 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function test_DB_getNeighbours() { + var db = new Blockly.ConnectionDB(); + + // Search an empty list. + assertEquals(helper_getNeighbours(db, 10 /* x */, 10 /* y */, 100 /* radius */).length, 0); + + // Set up some connections. + for (var i = 0; i < 10; i++) { + db.addConnection_(helper_createConnection(0, i, Blockly.PREVIOUS_STATEMENT)); + } + + // Test block belongs at beginning + var result = helper_getNeighbours(db, 0, 0, 4); + assertEquals(5, result.length); + for (i = 0; i < result.length; i++) { + assertNotEquals(result.indexOf(db[i]), -1); // contains + } + + // Test block belongs at middle + result = helper_getNeighbours(db, 0, 4, 2); + assertEquals(5, result.length); + for (i = 0; i < result.length; i++) { + assertNotEquals(result.indexOf(db[i + 2]), -1); // contains + } + + // Test block belongs at end + result = helper_getNeighbours(db, 0, 9, 4); + assertEquals(5, result.length); + for (i = 0; i < result.length; i++) { + assertNotEquals(result.indexOf(db[i + 5]), -1); // contains + } + + // Test block has no neighbours due to being out of range in the x direction + result = helper_getNeighbours(db, 10, 9, 4); + assertEquals(result.length, 0); + + // Test block has no neighbours due to being out of range in the y direction + result = helper_getNeighbours(db, 0, 19, 4); + assertEquals(result.length, 0); + + // Test block has no neighbours due to being out of range diagonally + result = helper_getNeighbours(db, -2, -2, 2); + assertEquals(result.length, 0); +} + +function helper_getNeighbours(db, x, y, radius) { + return db.getNeighbours(helper_createConnection(x, y, Blockly.NEXT_STATEMENT), radius); +} + +function helper_createConnection(x, y, type) { + var conn = new Blockly.Connection({workspace: {}}, type); + conn.x_ = x; + conn.y_ = y; + return conn; +}
\ No newline at end of file diff --git a/blockly/tests/jsunit/generator_test.js b/blockly/tests/jsunit/generator_test.js new file mode 100644 index 0000000..069f1c5 --- /dev/null +++ b/blockly/tests/jsunit/generator_test.js @@ -0,0 +1,28 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2012 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function test_prefix() { + var generator = new Blockly.Generator('INTERCAL'); + assertEquals('Prefix nothing.', '', generator.prefixLines('', '')); + assertEquals('Prefix a word.', '@Hello', generator.prefixLines('Hello', '@')); + assertEquals('Prefix one line.', '12Hello\n', generator.prefixLines('Hello\n', '12')); + assertEquals('Prefix two lines.', '***Hello\n***World\n', generator.prefixLines('Hello\nWorld\n', '***')); +} diff --git a/blockly/tests/jsunit/index.html b/blockly/tests/jsunit/index.html new file mode 100644 index 0000000..a604591 --- /dev/null +++ b/blockly/tests/jsunit/index.html @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <title>Unit Tests for Blockly</title> + <script src="../../blockly_uncompressed.js"></script> + <script>goog.require('goog.testing.jsunit');</script> + </head> + <body> + <script src="blockly_test.js"></script> + <script src="connection_test.js"></script> + <script src="connection_db_test.js"></script> + <script src="generator_test.js"></script> + <script src="names_test.js"></script> + <script src="workspace_test.js"></script> + <script src="xml_test.js"></script> + </body> +</html> diff --git a/blockly/tests/jsunit/names_test.js b/blockly/tests/jsunit/names_test.js new file mode 100644 index 0000000..8a4b008 --- /dev/null +++ b/blockly/tests/jsunit/names_test.js @@ -0,0 +1,62 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2012 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function test_safeName() { + var varDB = new Blockly.Names('window,door'); + assertEquals('SafeName empty.', 'unnamed', varDB.safeName_('')); + assertEquals('SafeName ok.', 'foobar', varDB.safeName_('foobar')); + assertEquals('SafeName number start.', 'my_9lives', + varDB.safeName_('9lives')); + assertEquals('SafeName number end.', 'lives9', varDB.safeName_('lives9')); + assertEquals('SafeName special chars.', '____', varDB.safeName_('!@#$')); + assertEquals('SafeName reserved.', 'door', varDB.safeName_('door')); +} + +function test_getName() { + var varDB = new Blockly.Names('window,door'); + assertEquals('Name add #1.', 'Foo_bar', varDB.getName('Foo.bar', 'var')); + assertEquals('Name get #1.', 'Foo_bar', varDB.getName('Foo.bar', 'var')); + assertEquals('Name add #2.', 'Foo_bar2', varDB.getName('Foo bar', 'var')); + assertEquals('Name get #2.', 'Foo_bar2', varDB.getName('foo BAR', 'var')); + assertEquals('Name add #3.', 'door2', varDB.getName('door', 'var')); + assertEquals('Name add #4.', 'Foo_bar3', varDB.getName('Foo.bar', 'proc')); + assertEquals('Name get #1b.', 'Foo_bar', varDB.getName('Foo.bar', 'var')); + assertEquals('Name get #4.', 'Foo_bar3', varDB.getName('Foo.bar', 'proc')); +} + +function test_getDistinctName() { + var varDB = new Blockly.Names('window,door'); + assertEquals('Name distinct #1.', 'Foo_bar', + varDB.getDistinctName('Foo.bar', 'var')); + assertEquals('Name distinct #2.', 'Foo_bar2', + varDB.getDistinctName('Foo.bar', 'var')); + assertEquals('Name distinct #3.', 'Foo_bar3', + varDB.getDistinctName('Foo.bar', 'proc')); + varDB.reset(); + assertEquals('Name distinct #4.', 'Foo_bar', + varDB.getDistinctName('Foo.bar', 'var')); +} + +function test_nameEquals() { + assertTrue('Name equals #1.', Blockly.Names.equals('Foo.bar', 'Foo.bar')); + assertFalse('Name equals #2.', Blockly.Names.equals('Foo.bar', 'Foo_bar')); + assertTrue('Name equals #3.', Blockly.Names.equals('Foo.bar', 'FOO.BAR')); +} diff --git a/blockly/tests/jsunit/workspace_test.js b/blockly/tests/jsunit/workspace_test.js new file mode 100644 index 0000000..87ff3bb --- /dev/null +++ b/blockly/tests/jsunit/workspace_test.js @@ -0,0 +1,99 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2012 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +function test_emptyWorkspace() { + var workspace = new Blockly.Workspace(); + assertEquals('Empty workspace (1).', 0, workspace.getTopBlocks(true).length); + assertEquals('Empty workspace (2).', 0, workspace.getTopBlocks(false).length); + assertEquals('Empty workspace (3).', 0, workspace.getAllBlocks().length); + workspace.clear(); + assertEquals('Empty workspace (4).', 0, workspace.getTopBlocks(true).length); + assertEquals('Empty workspace (5).', 0, workspace.getTopBlocks(false).length); + assertEquals('Empty workspace (6).', 0, workspace.getAllBlocks().length); +} + +function test_flatWorkspace() { + var workspace = new Blockly.Workspace(); + var blockA = workspace.newBlock(''); + assertEquals('One block workspace (1).', 1, workspace.getTopBlocks(true).length); + assertEquals('One block workspace (2).', 1, workspace.getTopBlocks(false).length); + assertEquals('One block workspace (3).', 1, workspace.getAllBlocks().length); + var blockB = workspace.newBlock(''); + assertEquals('Two block workspace (1).', 2, workspace.getTopBlocks(true).length); + assertEquals('Two block workspace (2).', 2, workspace.getTopBlocks(false).length); + assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks().length); + blockA.dispose(); + assertEquals('One block workspace (4).', 1, workspace.getTopBlocks(true).length); + assertEquals('One block workspace (5).', 1, workspace.getTopBlocks(false).length); + assertEquals('One block workspace (6).', 1, workspace.getAllBlocks().length); + workspace.clear(); + assertEquals('Cleared workspace (1).', 0, workspace.getTopBlocks(true).length); + assertEquals('Cleared workspace (2).', 0, workspace.getTopBlocks(false).length); + assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks().length); +} + +function test_maxBlocksWorkspace() { + var workspace = new Blockly.Workspace(); + var blockA = workspace.newBlock(''); + var blockB = workspace.newBlock(''); + assertEquals('Infinite capacity.', Infinity, workspace.remainingCapacity()); + workspace.options.maxBlocks = 3; + assertEquals('Three capacity.', 1, workspace.remainingCapacity()); + workspace.options.maxBlocks = 2; + assertEquals('Two capacity.', 0, workspace.remainingCapacity()); + workspace.options.maxBlocks = 1; + assertEquals('One capacity.', -1, workspace.remainingCapacity()); + workspace.options.maxBlocks = 0; + assertEquals('Zero capacity.', -2, workspace.remainingCapacity()); + workspace.clear(); + assertEquals('Cleared capacity.', 0, workspace.remainingCapacity()); +} + +function test_getWorkspaceById() { + var workspaceA = new Blockly.Workspace(); + var workspaceB = new Blockly.Workspace(); + assertEquals('Find workspaceA.', workspaceA, + Blockly.Workspace.getById(workspaceA.id)); + assertEquals('Find workspaceB.', workspaceB, + Blockly.Workspace.getById(workspaceB.id)); + assertEquals('No workspace found.', null, + Blockly.Workspace.getById('I do not exist.')); + workspaceA.dispose(); + assertEquals('Can\'t find workspaceA.', null, + Blockly.Workspace.getById(workspaceA.id)); + assertEquals('WorkspaceB exists.', workspaceB, + Blockly.Workspace.getById(workspaceB.id)); +} + +function test_getBlockById() { + var workspace = new Blockly.Workspace(); + var blockA = workspace.newBlock(''); + var blockB = workspace.newBlock(''); + assertEquals('Find blockA.', blockA, workspace.getBlockById(blockA.id)); + assertEquals('Find blockB.', blockB, workspace.getBlockById(blockB.id)); + assertEquals('No block found.', null, + workspace.getBlockById('I do not exist.')); + blockA.dispose(); + assertEquals('Can\'t find blockA.', null, workspace.getBlockById(blockA.id)); + assertEquals('BlockB exists.', blockB, workspace.getBlockById(blockB.id)); + workspace.clear(); + assertEquals('Can\'t find blockB.', null, workspace.getBlockById(blockB.id)); +} diff --git a/blockly/tests/jsunit/xml_test.js b/blockly/tests/jsunit/xml_test.js new file mode 100644 index 0000000..25e2655 --- /dev/null +++ b/blockly/tests/jsunit/xml_test.js @@ -0,0 +1,90 @@ +/** + * @license + * Blockly Tests + * + * Copyright 2014 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +var XML_TEXT = ['<xml xmlns="http://www.w3.org/1999/xhtml">', + ' <block type="controls_repeat_ext" inline="true" x="21" y="23">', + ' <value name="TIMES">', + ' <block type="math_number">', + ' <field name="NUM">10</field>', + ' </block>', + ' </value>', + ' <statement name="DO">', + ' <block type="variables_set" inline="true">', + ' <field name="VAR">item</field>', + ' <value name="VALUE">', + ' <block type="lists_create_empty"></block>', + ' </value>', + ' <next>', + ' <block type="text_print" inline="false">', + ' <value name="TEXT">', + ' <block type="text">', + ' <field name="TEXT">Hello</field>', + ' </block>', + ' </value>', + ' </block>', + ' </next>', + ' </block>', + ' </statement>', + ' </block>', + '</xml>'].join('\n'); + +function test_textToDom() { + var dom = Blockly.Xml.textToDom(XML_TEXT); + assertEquals('XML tag', 'xml', dom.nodeName); + assertEquals('Block tags', 6, dom.getElementsByTagName('block').length); +} + +function test_domToText() { + var dom = Blockly.Xml.textToDom(XML_TEXT); + var text = Blockly.Xml.domToText(dom); + assertEquals('Round trip', XML_TEXT.replace(/\s+/g, ''), + text.replace(/\s+/g, '')); +} + +function test_domToWorkspace() { + Blockly.Blocks.test_block = { + init: function() { + this.jsonInit({ + message0: 'test', + }); + } + }; + + try { + var dom = Blockly.Xml.textToDom( + '<xml xmlns="http://www.w3.org/1999/xhtml">' + + ' <block type="test_block" inline="true" x="21" y="23">' + + ' </block>' + + '</xml>'); + var workspace = new Blockly.Workspace(); + Blockly.Xml.domToWorkspace(dom, workspace); + assertEquals('Block count', 1, workspace.getAllBlocks().length); + } finally { + delete Blockly.Blocks.test_block; + } +} + +function test_domToPrettyText() { + var dom = Blockly.Xml.textToDom(XML_TEXT); + var text = Blockly.Xml.domToPrettyText(dom); + assertEquals('Round trip', XML_TEXT.replace(/\s+/g, ''), + text.replace(/\s+/g, '')); +} diff --git a/blockly/tests/multi_playground.html b/blockly/tests/multi_playground.html new file mode 100644 index 0000000..9c21323 --- /dev/null +++ b/blockly/tests/multi_playground.html @@ -0,0 +1,461 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>Multi-toolbox Playground</title> +<script src="../blockly_uncompressed.js"></script> +<script src="../msg/messages.js"></script> +<script src="../blocks/logic.js"></script> +<script src="../blocks/loops.js"></script> +<script src="../blocks/math.js"></script> +<script src="../blocks/text.js"></script> +<script src="../blocks/lists.js"></script> +<script src="../blocks/colour.js"></script> +<script src="../blocks/variables.js"></script> +<script src="../blocks/procedures.js"></script> +<script> +'use strict'; +var options = { + comments: true, + disable: true, + collapse: true, + maxBlocks: Infinity, + media: '../media/', + readOnly: false, + //rtl: false, + scrollbars: true, + trashcan: true, + //toolbox: null, + //horizontalLayout: false, + //toolboxPosition: 'start', + zoom: { + controls: true, + wheel: false, + startScale: 1.0, + maxScale: 4, + minScale: 0.25, + scaleSpeed: 1.1 + }, +}; + +function start() { + var match = location.search.match(/toolbox=([^&]+)/); + var toolbox = + document.getElementById('toolbox-' + (match ? match[1] : 'categories')); + document.forms.options.elements.toolbox.selectedIndex = + Number(toolbox.getElementsByTagName('category').length == 0); + startBlocklyInstance('VertStartLTR', false, false, 'start', toolbox); + startBlocklyInstance('VertStartRTL', true, false, 'start', toolbox); + + startBlocklyInstance('VertEndLTR', false, false, 'end', toolbox); + startBlocklyInstance('VertEndRTL', true, false, 'end', toolbox); + + startBlocklyInstance('HorizontalStartLTR', false, true, 'start', toolbox); + startBlocklyInstance('HorizontalStartRTL', true, true, 'start', toolbox); + + startBlocklyInstance('HorizontalEndLTR', false, true, 'end', toolbox); + startBlocklyInstance('HorizontalEndRTL', true, true, 'end', toolbox); +} + +function startBlocklyInstance(suffix, rtl, horizontalLayout, position, + toolbox) { + options.rtl = rtl; + options.toolbox = toolbox; + options.horizontalLayout = horizontalLayout; + options.toolboxPosition = position; + Blockly.inject('blocklyDiv' + suffix, options); +} +</script> + +<style> +html, body { + height: 100%; +} +body { + background-color: #fff; + font-family: sans-serif; +} +h1 { + font-weight: normal; + font-size: 140%; +} + +#octaweb { + width: 100%; +} +#octaweb th { + padding-top: 1em; + width: 50%; +} +#octaweb td { + width: 50%; +} +#octaweb td >div { + height: 480px; + width: 100%; +} +</style> +</head> +<body onload="start()"> + <h1>Blockly Multi Playground</h1> + + <form id="options"> + <select name="toolbox" onchange="document.forms.options.submit()"> + <option value="categories">Categories</option> + <option value="simple">Simple</option> + </select> + </form> + + <table id="octaweb"> + <tr> + <th>LTR, Vertical, Start</th> + <th>RTL, Vertical, Start</th> + </tr> + <tr> + <td><div id="blocklyDivVertStartLTR"></div></td> + <td><div id="blocklyDivVertStartRTL"></div></td> + </tr> + <tr> + <th>LTR, Vertical, End</th> + <th>RTL, Vertical, End</th> + </tr> + <tr> + <td><div id="blocklyDivVertEndLTR"></div></td> + <td><div id="blocklyDivVertEndRTL"></div></td> + </tr> + <tr> + <th>LTR, Horizontal, Start</th> + <th>RTL, Horizontal, Start</th> + </tr> + <tr> + <td><div id="blocklyDivHorizontalStartLTR"></div></td> + <td><div id="blocklyDivHorizontalStartRTL"></div></td> + </tr> + <tr> + <th>LTR, Horizontal, End</th> + <th>RTL, Horizontal, End</th> + </tr> + <tr> + <td><div id="blocklyDivHorizontalEndLTR"></div></td> + <td><div id="blocklyDivHorizontalEndRTL"></div></td> + </tr> + </table> + + <xml id="toolbox-simple" style="display: none"> + <block type="controls_if"></block> + <block type="logic_compare"></block> + <!-- <block type="control_repeat"></block> --> + <block type="logic_operation"></block> + <block type="controls_repeat_ext"> + <value name="TIMES"> + <shadow type="math_number"> + <field name="NUM">10</field> + </shadow> + </value> + </block> + <block type="logic_operation"></block> + <block type="logic_negate"></block> + <block type="logic_boolean"></block> + <block type="logic_null" disabled="true"></block> + <block type="logic_ternary"></block> + </xml> + + <xml id="toolbox-categories" style="display: none"> + <category name="Logic" colour="210"> + <block type="controls_if"></block> + <block type="logic_compare"></block> + <block type="logic_operation"></block> + <block type="logic_negate"></block> + <block type="logic_boolean"></block> + <block type="logic_null" disabled="true"></block> + <block type="logic_ternary"></block> + </category> + <category name="Loops" colour="120"> + <block type="controls_repeat_ext"> + <value name="TIMES"> + <shadow type="math_number"> + <field name="NUM">10</field> + </shadow> + </value> + </block> + <block type="controls_repeat" disabled="true"></block> + <block type="controls_whileUntil"></block> + <block type="controls_for"> + <value name="FROM"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + <value name="TO"> + <shadow type="math_number"> + <field name="NUM">10</field> + </shadow> + </value> + <value name="BY"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + </block> + <block type="controls_forEach"></block> + <block type="controls_flow_statements"></block> + </category> + <category name="Math" colour="230"> + <block type="math_number" gap="32"></block> + <block type="math_arithmetic"> + <value name="A"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + <value name="B"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + </block> + <block type="math_single"> + <value name="NUM"> + <shadow type="math_number"> + <field name="NUM">9</field> + </shadow> + </value> + </block> + <block type="math_trig"> + <value name="NUM"> + <shadow type="math_number"> + <field name="NUM">45</field> + </shadow> + </value> + </block> + <block type="math_constant"></block> + <block type="math_number_property"> + <value name="NUMBER_TO_CHECK"> + <shadow type="math_number"> + <field name="NUM">0</field> + </shadow> + </value> + </block> + <block type="math_round"> + <value name="NUM"> + <shadow type="math_number"> + <field name="NUM">3.1</field> + </shadow> + </value> + </block> + <block type="math_on_list"></block> + <block type="math_modulo"> + <value name="DIVIDEND"> + <shadow type="math_number"> + <field name="NUM">64</field> + </shadow> + </value> + <value name="DIVISOR"> + <shadow type="math_number"> + <field name="NUM">10</field> + </shadow> + </value> + </block> + <block type="math_constrain"> + <value name="VALUE"> + <shadow type="math_number"> + <field name="NUM">50</field> + </shadow> + </value> + <value name="LOW"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + <value name="HIGH"> + <shadow type="math_number"> + <field name="NUM">100</field> + </shadow> + </value> + </block> + <block type="math_random_int"> + <value name="FROM"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + <value name="TO"> + <shadow type="math_number"> + <field name="NUM">100</field> + </shadow> + </value> + </block> + <block type="math_random_float"></block> + </category> + <category name="Text" colour="160"> + <block type="text"></block> + <block type="text_join"></block> + <block type="text_append"> + <value name="TEXT"> + <shadow type="text"></shadow> + </value> + </block> + <block type="text_length"> + <value name="VALUE"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_isEmpty"> + <value name="VALUE"> + <shadow type="text"> + <field name="TEXT"></field> + </shadow> + </value> + </block> + <block type="text_indexOf"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="FIND"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_charAt"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + <block type="text_getSubstring"> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + <block type="text_changeCase"> + <value name="TEXT"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_trim"> + <value name="TEXT"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_print"> + <value name="TEXT"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_prompt_ext"> + <value name="TEXT"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + </category> + <category name="Lists" colour="260"> + <block type="lists_create_with"> + <mutation items="0"></mutation> + </block> + <block type="lists_create_with"></block> + <block type="lists_repeat"> + <value name="NUM"> + <shadow type="math_number"> + <field name="NUM">5</field> + </shadow> + </value> + </block> + <block type="lists_length"></block> + <block type="lists_isEmpty"></block> + <block type="lists_indexOf"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + <block type="lists_getIndex"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + <block type="lists_setIndex"> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + <block type="lists_getSublist"> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + <block type="lists_split"> + <value name="DELIM"> + <shadow type="text"> + <field name="TEXT">,</field> + </shadow> + </value> + </block> + <block type="lists_sort"></block> + </category> + <category name="Colour" colour="20"> + <block type="colour_picker"></block> + <block type="colour_random"></block> + <block type="colour_rgb"> + <value name="RED"> + <shadow type="math_number"> + <field name="NUM">100</field> + </shadow> + </value> + <value name="GREEN"> + <shadow type="math_number"> + <field name="NUM">50</field> + </shadow> + </value> + <value name="BLUE"> + <shadow type="math_number"> + <field name="NUM">0</field> + </shadow> + </value> + </block> + <block type="colour_blend"> + <value name="COLOUR1"> + <shadow type="colour_picker"> + <field name="COLOUR">#ff0000</field> + </shadow> + </value> + <value name="COLOUR2"> + <shadow type="colour_picker"> + <field name="COLOUR">#3333ff</field> + </shadow> + </value> + <value name="RATIO"> + <shadow type="math_number"> + <field name="NUM">0.5</field> + </shadow> + </value> + </block> + </category> + <sep></sep> + <category name="Variables" colour="330" custom="VARIABLE"></category> + <category name="Functions" colour="290" custom="PROCEDURE"></category> + </xml> +</body> +</html> diff --git a/blockly/tests/playground.html b/blockly/tests/playground.html new file mode 100644 index 0000000..144b4f4 --- /dev/null +++ b/blockly/tests/playground.html @@ -0,0 +1,697 @@ +<!DOCTYPE html> +<html> +<head> +<meta charset="utf-8"> +<title>Blockly Playground</title> +<script src="../blockly_uncompressed.js"></script> +<script src="../generators/javascript.js"></script> +<script src="../generators/javascript/logic.js"></script> +<script src="../generators/javascript/loops.js"></script> +<script src="../generators/javascript/math.js"></script> +<script src="../generators/javascript/text.js"></script> +<script src="../generators/javascript/lists.js"></script> +<script src="../generators/javascript/colour.js"></script> +<script src="../generators/javascript/variables.js"></script> +<script src="../generators/javascript/procedures.js"></script> +<script src="../generators/python.js"></script> +<script src="../generators/python/logic.js"></script> +<script src="../generators/python/loops.js"></script> +<script src="../generators/python/math.js"></script> +<script src="../generators/python/text.js"></script> +<script src="../generators/python/lists.js"></script> +<script src="../generators/python/colour.js"></script> +<script src="../generators/python/variables.js"></script> +<script src="../generators/python/procedures.js"></script> +<script src="../generators/php.js"></script> +<script src="../generators/php/logic.js"></script> +<script src="../generators/php/loops.js"></script> +<script src="../generators/php/math.js"></script> +<script src="../generators/php/text.js"></script> +<script src="../generators/php/lists.js"></script> +<script src="../generators/php/colour.js"></script> +<script src="../generators/php/variables.js"></script> +<script src="../generators/php/procedures.js"></script> +<script src="../generators/lua.js"></script> +<script src="../generators/lua/logic.js"></script> +<script src="../generators/lua/loops.js"></script> +<script src="../generators/lua/math.js"></script> +<script src="../generators/lua/text.js"></script> +<script src="../generators/lua/lists.js"></script> +<script src="../generators/lua/colour.js"></script> +<script src="../generators/lua/variables.js"></script> +<script src="../generators/lua/procedures.js"></script> +<script src="../generators/dart.js"></script> +<script src="../generators/dart/logic.js"></script> +<script src="../generators/dart/loops.js"></script> +<script src="../generators/dart/math.js"></script> +<script src="../generators/dart/text.js"></script> +<script src="../generators/dart/lists.js"></script> +<script src="../generators/dart/colour.js"></script> +<script src="../generators/dart/variables.js"></script> +<script src="../generators/dart/procedures.js"></script> +<script src="../msg/messages.js"></script> +<script src="../blocks/logic.js"></script> +<script src="../blocks/loops.js"></script> +<script src="../blocks/math.js"></script> +<script src="../blocks/text.js"></script> +<script src="../blocks/lists.js"></script> +<script src="../blocks/colour.js"></script> +<script src="../blocks/variables.js"></script> +<script src="../blocks/procedures.js"></script> +<script> +'use strict'; +var workspace = null; +var fakeDragStack = []; + +function start() { + // Parse the URL arguments. + var match = location.search.match(/dir=([^&]+)/); + var rtl = match && match[1] == 'rtl'; + document.forms.options.elements.dir.selectedIndex = Number(rtl); + var toolbox = getToolboxElement(); + document.forms.options.elements.toolbox.selectedIndex = + Number(toolbox.getElementsByTagName('category').length == 0); + match = location.search.match(/side=([^&]+)/); + var side = match ? match[1] : 'start'; + document.forms.options.elements.side.value = side; + // Create main workspace. + workspace = Blockly.inject('blocklyDiv', + {comments: true, + disable: true, + collapse: true, + grid: + {spacing: 25, + length: 3, + colour: '#ccc', + snap: true}, + horizontalLayout: side == 'top' || side == 'bottom', + maxBlocks: Infinity, + media: '../media/', + readOnly: false, + rtl: rtl, + scrollbars: true, + toolbox: toolbox, + toolboxPosition: side == 'top' || side == 'start' ? 'start' : 'end', + zoom: + {controls: true, + wheel: true, + startScale: 1.0, + maxScale: 4, + minScale: .25, + scaleSpeed: 1.1} + }); + // Restore previously displayed text. + if (sessionStorage) { + var text = sessionStorage.getItem('textarea'); + if (text) { + document.getElementById('importExport').value = text; + } + // Restore event logging state. + var state = sessionStorage.getItem('logEvents'); + logEvents(Boolean(Number(state))); + } else { + // MSIE 11 does not support sessionStorage on file:// URLs. + logEvents(false); + } + taChange(); +} + +function getToolboxElement() { + var match = location.search.match(/toolbox=([^&]+)/); + return document.getElementById('toolbox-' + (match ? match[1] : 'categories')); +} + +function toXml() { + var output = document.getElementById('importExport'); + var xml = Blockly.Xml.workspaceToDom(workspace); + output.value = Blockly.Xml.domToPrettyText(xml); + output.focus(); + output.select(); + taChange(); +} + +function fromXml() { + var input = document.getElementById('importExport'); + var xml = Blockly.Xml.textToDom(input.value); + Blockly.Xml.domToWorkspace(xml, workspace); + taChange(); +} + +function toCode(lang) { + var output = document.getElementById('importExport'); + output.value = Blockly[lang].workspaceToCode(workspace); + taChange(); +} + +// Disable the "Import from XML" button if the XML is invalid. +// Preserve text between page reloads. +function taChange() { + var textarea = document.getElementById('importExport'); + if (sessionStorage) { + sessionStorage.setItem('textarea', textarea.value); + } + var valid = true; + try { + Blockly.Xml.textToDom(textarea.value); + } catch (e) { + valid = false; + } + document.getElementById('import').disabled = !valid; +} + +function logEvents(state) { + var checkbox = document.getElementById('logCheck'); + checkbox.checked = state; + if (sessionStorage) { + sessionStorage.setItem('logEvents', Number(state)); + } + if (state) { + workspace.addChangeListener(logger); + } else { + workspace.removeChangeListener(logger); + } +} + +function logger(e) { + console.log(e); +} + +function airstrike(n) { + var prototypes = []; + var toolbox = getToolboxElement(); + var blocks = toolbox.getElementsByTagName('block'); + for (var i = 0, block; block = blocks[i]; i++) { + prototypes.push(block.getAttribute('type')); + } + for (var i = 0; i < n; i++) { + var prototype = prototypes[Math.floor(Math.random() * prototypes.length)]; + var block = workspace.newBlock(prototype); + block.initSvg(); + block.getSvgRoot().setAttribute('transform', 'translate(' + + Math.round(Math.random() * 450 + 40) + ', ' + + Math.round(Math.random() * 600 + 40) + ')'); + block.render(); + } +} + +function fakeDrag(id, dx, dy, opt_workspace) { + var ws = opt_workspace || Blockly.getMainWorkspace(); + var blockToDrag = ws.getBlockById(id); + + if (!blockToDrag) { + fakeDragWrapper(); + return; + } + var blockTop = blockToDrag.svgGroup_.getBoundingClientRect().top; + var blockLeft = blockToDrag.svgGroup_.getBoundingClientRect().left; + + // Click somewhere on the block. + var mouseDownEvent = new MouseEvent('mousedown', + {clientX: blockLeft + 5, clientY: blockTop + 5}); + blockToDrag.onMouseDown_(mouseDownEvent); + + // Throw in a move for good measure. + setTimeout( + function() { + var mouseMoveEvent = new MouseEvent('mousemove', + {clientX: blockLeft + dx, + clientY: blockTop + dy}); + blockToDrag.onMouseMove_(mouseMoveEvent); + + // Drop at dx, dy. + setTimeout( + function() { + var mouseUpEvent = new MouseEvent('mouseup', + {clientX: blockLeft + dx, + clientY: blockTop + dy}); + blockToDrag.onMouseUp_(mouseUpEvent); + + setTimeout(fakeDragWrapper(), 100); + }, 30); + }, 30); +}; + +function fakeDragWrapper() { + var dragInfo = fakeDragStack.pop(); + if (dragInfo) { + fakeDrag(dragInfo.id, dragInfo.dx, dragInfo.dy, dragInfo.workspace); + } +} + +function fakeManyDrags() { + var blockList = workspace.getAllBlocks(); + for (var i = 0; i < 2 * blockList.length; i++) { + fakeDragStack.push( + { + id: blockList[Math.round(Math.random() * (blockList.length - 1))].id, + // Move some blocks up and to the left, but mostly down and to the right. + dx: Math.round((Math.random() - 0.25) * 200), + dy: Math.round((Math.random() - 0.25) * 200), + workspace: workspace + }); + } + fakeDragWrapper(); +} + +function spaghetti(n) { + var xml = spaghettiXml; + for(var i = 0; i < n; i++) { + xml = xml.replace(/(<(statement|next)( name="DO0")?>)<\//g, + '$1' + spaghettiXml + '</'); + } + xml = '<xml xmlns="http://www.w3.org/1999/xhtml">' + xml + '</xml>'; + var dom = Blockly.Xml.textToDom(xml); + console.time('Spaghetti domToWorkspace'); + Blockly.Xml.domToWorkspace(dom, workspace); + console.timeEnd('Spaghetti domToWorkspace'); +} +var spaghettiXml = [ + ' <block type="controls_if">', + ' <value name="IF0">', + ' <block type="logic_compare">', + ' <field name="OP">EQ</field>', + ' <value name="A">', + ' <block type="math_arithmetic">', + ' <field name="OP">MULTIPLY</field>', + ' <value name="A">', + ' <block type="math_number">', + ' <field name="NUM">6</field>', + ' </block>', + ' </value>', + ' <value name="B">', + ' <block type="math_number">', + ' <field name="NUM">7</field>', + ' </block>', + ' </value>', + ' </block>', + ' </value>', + ' <value name="B">', + ' <block type="math_number">', + ' <field name="NUM">42</field>', + ' </block>', + ' </value>', + ' </block>', + ' </value>', + ' <statement name="DO0"></statement>', + ' <next></next>', + ' </block>'].join('\n'); + +</script> + +<style> +html, body { + height: 100%; +} +body { + background-color: #fff; + font-family: sans-serif; + overflow: hidden; +} +h1 { + font-weight: normal; + font-size: 140%; +} +#blocklyDiv { + float: right; + height: 95%; + width: 70%; +} +#importExport { + font-family: monospace; +} +</style> +</head> +<body onload="start()"> + + <div id="blocklyDiv"></div> + + <h1>Blockly Playground</h1> + + <p><a href="javascript:void(workspace.setVisible(true))">Show</a> + - <a href="javascript:void(workspace.setVisible(false))">Hide</a></p> + + <form id="options"> + <select name="dir" onchange="document.forms.options.submit()"> + <option value="ltr">LTR</option> + <option value="rtl">RTL</option> + </select> + <select name="toolbox" onchange="document.forms.options.submit()"> + <option value="categories">Categories</option> + <option value="simple">Simple</option> + </select> + <select name="side" onchange="document.forms.options.submit()"> + <option value="start">Start</option> + <option value="end">End</option> + <option value="top">Top</option> + <option value="bottom">Bottom</option> + </select> + </form> + + <p> + <input type="button" value="Export to XML" onclick="toXml()"> + + <input type="button" value="Import from XML" onclick="fromXml()" id="import"> + <br> + <input type="button" value="To JavaScript" onclick="toCode('JavaScript')"> + + <input type="button" value="To Python" onclick="toCode('Python')"> + + <input type="button" value="To PHP" onclick="toCode('PHP')"> + + <input type="button" value="To Lua" onclick="toCode('Lua')"> + + <input type="button" value="To Dart" onclick="toCode('Dart')"> + <br> + <textarea id="importExport" style="width: 26%; height: 12em" + onchange="taChange();" onkeyup="taChange()"></textarea> + </p> + + <p> + Stress test: + <input type="button" value="Airstrike!" onclick="airstrike(100)"> + <input type="button" value="Spaghetti!" onclick="spaghetti(8)"> + <input type="button" value="Fake some drags!" onclick="fakeManyDrags()"> + </p> + <p> + Log events: + <input type="checkbox" onclick="logEvents(this.checked)" id="logCheck"> + </p> + + <xml id="toolbox-simple" style="display: none"> + <block type="controls_if"></block> + <block type="logic_compare"></block> + <!-- <block type="control_repeat"></block> --> + <block type="logic_operation"></block> + <block type="controls_repeat_ext"> + <value name="TIMES"> + <shadow type="math_number"> + <field name="NUM">10</field> + </shadow> + </value> + </block> + <block type="logic_operation"></block> + <block type="logic_negate"></block> + <block type="logic_boolean"></block> + <block type="logic_null" disabled="true"></block> + <block type="logic_ternary"></block> + </xml> + + <xml id="toolbox-categories" style="display: none"> + <category name="Logic" colour="210"> + <block type="controls_if"></block> + <block type="logic_compare"></block> + <block type="logic_operation"></block> + <block type="logic_negate"></block> + <block type="logic_boolean"></block> + <block type="logic_null" disabled="true"></block> + <block type="logic_ternary"></block> + </category> + <category name="Loops" colour="120"> + <block type="controls_repeat_ext"> + <value name="TIMES"> + <shadow type="math_number"> + <field name="NUM">10</field> + </shadow> + </value> + </block> + <block type="controls_repeat" disabled="true"></block> + <block type="controls_whileUntil"></block> + <block type="controls_for"> + <value name="FROM"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + <value name="TO"> + <shadow type="math_number"> + <field name="NUM">10</field> + </shadow> + </value> + <value name="BY"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + </block> + <block type="controls_forEach"></block> + <block type="controls_flow_statements"></block> + </category> + <category name="Math" colour="230"> + <block type="math_number" gap="32"></block> + <block type="math_arithmetic"> + <value name="A"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + <value name="B"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + </block> + <block type="math_single"> + <value name="NUM"> + <shadow type="math_number"> + <field name="NUM">9</field> + </shadow> + </value> + </block> + <block type="math_trig"> + <value name="NUM"> + <shadow type="math_number"> + <field name="NUM">45</field> + </shadow> + </value> + </block> + <block type="math_constant"></block> + <block type="math_number_property"> + <value name="NUMBER_TO_CHECK"> + <shadow type="math_number"> + <field name="NUM">0</field> + </shadow> + </value> + </block> + <block type="math_round"> + <value name="NUM"> + <shadow type="math_number"> + <field name="NUM">3.1</field> + </shadow> + </value> + </block> + <block type="math_on_list"></block> + <block type="math_modulo"> + <value name="DIVIDEND"> + <shadow type="math_number"> + <field name="NUM">64</field> + </shadow> + </value> + <value name="DIVISOR"> + <shadow type="math_number"> + <field name="NUM">10</field> + </shadow> + </value> + </block> + <block type="math_constrain"> + <value name="VALUE"> + <shadow type="math_number"> + <field name="NUM">50</field> + </shadow> + </value> + <value name="LOW"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + <value name="HIGH"> + <shadow type="math_number"> + <field name="NUM">100</field> + </shadow> + </value> + </block> + <block type="math_random_int"> + <value name="FROM"> + <shadow type="math_number"> + <field name="NUM">1</field> + </shadow> + </value> + <value name="TO"> + <shadow type="math_number"> + <field name="NUM">100</field> + </shadow> + </value> + </block> + <block type="math_random_float"></block> + </category> + <category name="Text" colour="160"> + <block type="text"></block> + <block type="text_join"></block> + <block type="text_append"> + <value name="TEXT"> + <shadow type="text"></shadow> + </value> + </block> + <block type="text_length"> + <value name="VALUE"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_isEmpty"> + <value name="VALUE"> + <shadow type="text"> + <field name="TEXT"></field> + </shadow> + </value> + </block> + <block type="text_indexOf"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + <value name="FIND"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_charAt"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + <block type="text_getSubstring"> + <value name="STRING"> + <block type="variables_get"> + <field name="VAR">text</field> + </block> + </value> + </block> + <block type="text_changeCase"> + <value name="TEXT"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_trim"> + <value name="TEXT"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_print"> + <value name="TEXT"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + <block type="text_prompt_ext"> + <value name="TEXT"> + <shadow type="text"> + <field name="TEXT">abc</field> + </shadow> + </value> + </block> + </category> + <category name="Lists" colour="260"> + <block type="lists_create_with"> + <mutation items="0"></mutation> + </block> + <block type="lists_create_with"></block> + <block type="lists_repeat"> + <value name="NUM"> + <shadow type="math_number"> + <field name="NUM">5</field> + </shadow> + </value> + </block> + <block type="lists_length"></block> + <block type="lists_isEmpty"></block> + <block type="lists_indexOf"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + <block type="lists_getIndex"> + <value name="VALUE"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + <block type="lists_setIndex"> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + <block type="lists_getSublist"> + <value name="LIST"> + <block type="variables_get"> + <field name="VAR">list</field> + </block> + </value> + </block> + <block type="lists_split"> + <value name="DELIM"> + <shadow type="text"> + <field name="TEXT">,</field> + </shadow> + </value> + </block> + <block type="lists_sort"></block> + </category> + <category name="Colour" colour="20"> + <block type="colour_picker"></block> + <block type="colour_random"></block> + <block type="colour_rgb"> + <value name="RED"> + <shadow type="math_number"> + <field name="NUM">100</field> + </shadow> + </value> + <value name="GREEN"> + <shadow type="math_number"> + <field name="NUM">50</field> + </shadow> + </value> + <value name="BLUE"> + <shadow type="math_number"> + <field name="NUM">0</field> + </shadow> + </value> + </block> + <block type="colour_blend"> + <value name="COLOUR1"> + <shadow type="colour_picker"> + <field name="COLOUR">#ff0000</field> + </shadow> + </value> + <value name="COLOUR2"> + <shadow type="colour_picker"> + <field name="COLOUR">#3333ff</field> + </shadow> + </value> + <value name="RATIO"> + <shadow type="math_number"> + <field name="NUM">0.5</field> + </shadow> + </value> + </block> + </category> + <sep></sep> + <category name="Variables" colour="330" custom="VARIABLE"></category> + <category name="Functions" colour="290" custom="PROCEDURE"></category> + </xml> +</body> +</html> |