From 3647b6e38e5420b87fc334752b7452d29f49c06d Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 12 Jul 2019 12:05:55 -0700 Subject: [PATCH] =?UTF-8?q?Add=20XSD=20to=20validate=20Blockly=E2=80=99s?= =?UTF-8?q?=20XML=20(#2633)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add XSD to validate Blockly’s XML This XSD might be used in tests or other tooling. --- core/block_events.js | 2 +- tests/xml/README.txt | 11 ++ tests/xml/blockly.xsd | 178 +++++++++++++++++++++++ tests/xml/invalid.xml | 6 + tests/xml/toolbox.xml | 311 ++++++++++++++++++++++++++++++++++++++++ tests/xml/workspace.xml | 114 +++++++++++++++ 6 files changed, 621 insertions(+), 1 deletion(-) create mode 100644 tests/xml/README.txt create mode 100644 tests/xml/blockly.xsd create mode 100644 tests/xml/invalid.xml create mode 100644 tests/xml/toolbox.xml create mode 100644 tests/xml/workspace.xml diff --git a/core/block_events.js b/core/block_events.js index 4a3f82773..c016bca46 100644 --- a/core/block_events.js +++ b/core/block_events.js @@ -197,7 +197,7 @@ Blockly.Events.Change.prototype.run = function(forward) { oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom); } if (block.domToMutation) { - var dom = Blockly.Xml.textToDom(value || ''); + var dom = Blockly.Xml.textToDom(value || ''); block.domToMutation(dom); } Blockly.Events.fire(new Blockly.Events.Change( diff --git a/tests/xml/README.txt b/tests/xml/README.txt new file mode 100644 index 000000000..8fe34d8c1 --- /dev/null +++ b/tests/xml/README.txt @@ -0,0 +1,11 @@ +This directory contains the schema for validating Blockly XML files: +* blockly.xsd + +Also included are three sample XML files: +* workspace.xml - XML for a complicated workspace. +* toolbox.xml - XML for a complicated toolbox with categories and separators. +* invalid.xml - XML that violates the DTD. + +Testing can be performed using an online tool: +https://www.corefiling.com/opensource/schemaValidate/ +http://www.utilities-online.info/xsdvalidation/ diff --git a/tests/xml/blockly.xsd b/tests/xml/blockly.xsd new file mode 100644 index 000000000..4ab48e443 --- /dev/null +++ b/tests/xml/blockly.xsd @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/xml/invalid.xml b/tests/xml/invalid.xml new file mode 100644 index 000000000..5debaafd4 --- /dev/null +++ b/tests/xml/invalid.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/xml/toolbox.xml b/tests/xml/toolbox.xml new file mode 100644 index 000000000..63474ece7 --- /dev/null +++ b/tests/xml/toolbox.xml @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 10 + + + + + + i + + + 1 + + + + + 10 + + + + + 1 + + + + + + + + + 123 + + + + + + + + + + + + + 1 + + + + + 100 + + + + + + + 1 + + + + + 100 + + + + + + + + + + + + + 5 + + + + + + + + + + + + + + + + + + + + + + randomize + + + x + + + 1 + + + + + + + list + + + + + + + 1 + + + + + y + + + + + 1 + + + + + + + list + + + + + + + + + temp + + + + GET + FROM_START + + + y + + + + + list + + + + + + + + + y + + + + + list + + + + + + GET + FROM_START + + + x + + + + + list + + + + + + + + + x + + + + + list + + + + + temp + + + + + + + + + + + + + + + + + + + 'Twas brillig, and the slithy toves + + + + + + + Did gyre and gimble in the wabe: + + + + + + + All mimsy were the borogroves, + + + + + + + And the mome raths outgrabe. + + + + + + + + + + + + + "Beware the Jabberwock, my son! + + + + + + + The jaws that bite, the claws that catch! + + + + + + + Beware the Jubjub bird, and shun + + + + + + + The frumious Bandersnatch!" + + + + + + + + + + + + diff --git a/tests/xml/workspace.xml b/tests/xml/workspace.xml new file mode 100644 index 000000000..708544b92 --- /dev/null +++ b/tests/xml/workspace.xml @@ -0,0 +1,114 @@ + + + x + i + text + + This is a workspace comment. + This is a new line on the workspace comment. + + + + + + + bar + Describe this function... + + + + + + LT + + + + FIRST + FROM_START + + + text + + + + + + + + + + + + + + + + + + + + + <html> + + + + + + + i + + + 1 + + + + + + + + + + foo + This function does... + +...nothing! + + + + + + + TRUE + + + + + + + 100 + + + + + 50 + + + + + 0 + + + + + + + + + + + + + + + +