From 1467f746f661ceb1f91c16bf124baa16b3990de1 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 25 Nov 2014 15:57:31 -0800 Subject: [PATCH] Add XML unit tests. --- tests/{ => jsunit}/blockly_test.js | 0 tests/{ => jsunit}/generator_test.js | 0 .../{blockly_test.html => jsunit/index.html} | 4 +- tests/{ => jsunit}/names_test.js | 0 tests/jsunit/xml_test.js | 69 +++++++++++++++++++ 5 files changed, 71 insertions(+), 2 deletions(-) rename tests/{ => jsunit}/blockly_test.js (100%) rename tests/{ => jsunit}/generator_test.js (100%) rename tests/{blockly_test.html => jsunit/index.html} (70%) rename tests/{ => jsunit}/names_test.js (100%) create mode 100644 tests/jsunit/xml_test.js diff --git a/tests/blockly_test.js b/tests/jsunit/blockly_test.js similarity index 100% rename from tests/blockly_test.js rename to tests/jsunit/blockly_test.js diff --git a/tests/generator_test.js b/tests/jsunit/generator_test.js similarity index 100% rename from tests/generator_test.js rename to tests/jsunit/generator_test.js diff --git a/tests/blockly_test.html b/tests/jsunit/index.html similarity index 70% rename from tests/blockly_test.html rename to tests/jsunit/index.html index 40d3a4482..710f092d0 100644 --- a/tests/blockly_test.html +++ b/tests/jsunit/index.html @@ -3,13 +3,13 @@ Unit Tests for Blockly - + - + diff --git a/tests/names_test.js b/tests/jsunit/names_test.js similarity index 100% rename from tests/names_test.js rename to tests/jsunit/names_test.js diff --git a/tests/jsunit/xml_test.js b/tests/jsunit/xml_test.js new file mode 100644 index 000000000..fbdc5e534 --- /dev/null +++ b/tests/jsunit/xml_test.js @@ -0,0 +1,69 @@ +/** + * 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 = ['', + ' ', + ' ', + ' ', + ' 10', + ' ', + ' ', + ' ', + ' ', + ' item', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' Hello', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ''].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_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, '')); +} + + +