2014-11-25 15:57:31 -08:00
|
|
|
/**
|
2015-01-22 15:58:10 -08:00
|
|
|
* @license
|
2014-11-25 15:57:31 -08:00
|
|
|
* 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">',
|
2015-09-24 15:20:31 -07:00
|
|
|
' <block type="controls_repeat_ext" inline="true" x="21" y="23">',
|
2014-11-25 15:57:31 -08:00
|
|
|
' <value name="TIMES">',
|
2015-09-24 15:20:31 -07:00
|
|
|
' <block type="math_number">',
|
2014-11-25 15:57:31 -08:00
|
|
|
' <field name="NUM">10</field>',
|
|
|
|
' </block>',
|
|
|
|
' </value>',
|
|
|
|
' <statement name="DO">',
|
2015-09-24 15:20:31 -07:00
|
|
|
' <block type="variables_set" inline="true">',
|
2014-11-25 15:57:31 -08:00
|
|
|
' <field name="VAR">item</field>',
|
|
|
|
' <value name="VALUE">',
|
2015-09-24 15:20:31 -07:00
|
|
|
' <block type="lists_create_empty"></block>',
|
2014-11-25 15:57:31 -08:00
|
|
|
' </value>',
|
|
|
|
' <next>',
|
2015-09-24 15:20:31 -07:00
|
|
|
' <block type="text_print" inline="false">',
|
2014-11-25 15:57:31 -08:00
|
|
|
' <value name="TEXT">',
|
2015-09-24 15:20:31 -07:00
|
|
|
' <block type="text">',
|
2014-11-25 15:57:31 -08:00
|
|
|
' <field name="TEXT">Hello</field>',
|
|
|
|
' </block>',
|
|
|
|
' </value>',
|
|
|
|
' </block>',
|
|
|
|
' </next>',
|
|
|
|
' </block>',
|
|
|
|
' </statement>',
|
|
|
|
' </block>',
|
2015-09-24 15:20:31 -07:00
|
|
|
'</xml>'].join('\n');
|
2014-11-25 15:57:31 -08:00
|
|
|
|
|
|
|
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_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, ''));
|
|
|
|
}
|