From ef55c29d5285debdc6fa1887d5e02630153f3129 Mon Sep 17 00:00:00 2001 From: Rodrigo Queiro Date: Tue, 9 Aug 2016 15:33:45 +0200 Subject: [PATCH] Add a test for domToWorkspace This would have caught a recent [Scratch Blocks regression](https://github.com/LLK/scratch-blocks/pull/557) where domToWorkspace failed unless given a WorkspaceSvg instance. --- tests/jsunit/xml_test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/jsunit/xml_test.js b/tests/jsunit/xml_test.js index 7487b6f3e..25e2655ea 100644 --- a/tests/jsunit/xml_test.js +++ b/tests/jsunit/xml_test.js @@ -59,6 +59,29 @@ function test_domToText() { text.replace(/\s+/g, '')); } +function test_domToWorkspace() { + Blockly.Blocks.test_block = { + init: function() { + this.jsonInit({ + message0: 'test', + }); + } + }; + + try { + var dom = Blockly.Xml.textToDom( + '' + + ' ' + + ' ' + + ''); + 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);