From a080fc59a3fca08bdc6e23a2eeae440f5c7047b3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 7 Jul 2016 22:17:34 +0100 Subject: Use exports for all tests --- test/xml/reader.tests.js | 132 ++++++++++++++++++++++----------------------- test/xml/writer.tests.js | 136 +++++++++++++++++++++++------------------------ 2 files changed, 132 insertions(+), 136 deletions(-) (limited to 'test/xml') diff --git a/test/xml/reader.tests.js b/test/xml/reader.tests.js index 005753c..6b7d3a0 100644 --- a/test/xml/reader.tests.js +++ b/test/xml/reader.tests.js @@ -1,87 +1,85 @@ var assert = require("assert"); var xmlreader = require("../../lib/xml/reader"); -var test = require("../testing").test; +var test = require("../test")(module); -describe('xmlreader.readString', function() { - test('should read self-closing element', function() { - return xmlreader.readString("").then(function(result) { - assert.deepEqual({type: "element", name: "body", attributes: {}, children: []}, result); - }); +test('should read self-closing element', function() { + return xmlreader.readString("").then(function(result) { + assert.deepEqual({type: "element", name: "body", attributes: {}, children: []}, result); }); - - test('should read empty element with separate closing tag', function() { - return xmlreader.readString("").then(function(result) { - assert.deepEqual({type: "element", name: "body", attributes: {}, children: []}, result); - }); +}); + +test('should read empty element with separate closing tag', function() { + return xmlreader.readString("").then(function(result) { + assert.deepEqual({type: "element", name: "body", attributes: {}, children: []}, result); }); - - test('should read attributes of tags', function() { - return xmlreader.readString('').then(function(result) { - assert.deepEqual({name: "bob"}, result.attributes); - }); +}); + +test('should read attributes of tags', function() { + return xmlreader.readString('').then(function(result) { + assert.deepEqual({name: "bob"}, result.attributes); }); - - test('can read text element', function() { - return xmlreader.readString('Hello!').then(function(result) { - assert.deepEqual({type: "text", value: "Hello!"}, result.children[0]); - }); +}); + +test('can read text element', function() { + return xmlreader.readString('Hello!').then(function(result) { + assert.deepEqual({type: "text", value: "Hello!"}, result.children[0]); }); - - test('should read element with children', function() { - return xmlreader.readString("").then(function(root) { - assert.equal(2, root.children.length); - assert.equal("a", root.children[0].name); - assert.equal("b", root.children[1].name); - }); +}); + +test('should read element with children', function() { + return xmlreader.readString("").then(function(root) { + assert.equal(2, root.children.length); + assert.equal("a", root.children[0].name); + assert.equal("b", root.children[1].name); }); +}); - test('unmapped namespaces URIs are included in braces as prefix', function() { - return xmlreader.readString('').then(function(result) { - assert.deepEqual(result.name, "{word}body"); - }); +test('unmapped namespaces URIs are included in braces as prefix', function() { + return xmlreader.readString('').then(function(result) { + assert.deepEqual(result.name, "{word}body"); }); +}); - test('mapped namespaces URIs are translated using map', function() { - var namespaceMap = { - "word": "x" - }; - - return xmlreader.readString('', namespaceMap).then(function(result) { - assert.deepEqual(result.name, "x:body"); - }); +test('mapped namespaces URIs are translated using map', function() { + var namespaceMap = { + "word": "x" + }; + + return xmlreader.readString('', namespaceMap).then(function(result) { + assert.deepEqual(result.name, "x:body"); }); +}); - test('namespace of attributes is mapped to prefix', function() { - var namespaceMap = { - "word": "x" - }; - var xmlString = ''; - return xmlreader.readString(xmlString, namespaceMap).then(function(result) { - assert.deepEqual(result.attributes["x:val"], "Hello!"); - }); +test('namespace of attributes is mapped to prefix', function() { + var namespaceMap = { + "word": "x" + }; + var xmlString = ''; + return xmlreader.readString(xmlString, namespaceMap).then(function(result) { + assert.deepEqual(result.attributes["x:val"], "Hello!"); }); - - test('can find first element with name', function() { - return xmlreader.readString('').then(function(result) { - var first = result.first("b"); - assert.equal("1", first.attributes.index); - }); +}); + +test('can find first element with name', function() { + return xmlreader.readString('').then(function(result) { + var first = result.first("b"); + assert.equal("1", first.attributes.index); }); - - test('whitespace between xml declaration and root tag is ignored', function() { - return xmlreader.readString('\n').then(function(result) { - assert.deepEqual("body", result.name); - }); +}); + +test('whitespace between xml declaration and root tag is ignored', function() { + return xmlreader.readString('\n').then(function(result) { + assert.deepEqual("body", result.name); }); - - test('error if XML is badly formed', function() { - return xmlreader.readString("'); - }); - - test('can write empty child elements', function() { - assertXmlString(xml.element("root", {}, [xml.element("album"), xml.element("single")]), {}, - ''); - }); - - test('can write empty descendant elements', function() { - var element = xml.element("root", {}, [ - xml.element("album", {}, [ - xml.element("year"), - xml.element("song") - ]) - ]); - assertXmlString(element, {}, - ''); - }); - - test('can write element attributes', function() { - var element = xml.element("root", {}, [ - xml.element("album", {"title": "Everything in Transit"}) - ]); - assertXmlString(element, {}, - ''); - }); - - test('can write text nodes', function() { - var element = xml.element("root", {}, [ - xml.element("album", {}, [ - xml.text("Everything in Transit") - ]) - ]); - assertXmlString(element, {}, - 'Everything in Transit'); - }); - - test('can write root element with long-form prefix when URI is namespace', function() { - var element = xml.element("{music}root"); - assertXmlString(element, {"m": "music"}, - ''); - }); - - test('can write child elements with long-form prefix when URI is namespace', function() { - var element = xml.element("root", {}, [ - xml.element("{music}album") - ]); - assertXmlString(element, {"m": "music"}, - ''); - }); - - test('can write child elements with short-form prefix when URI is namespace', function() { - var element = xml.element("root", {}, [ - xml.element("m:album") - ]); - assertXmlString(element, {"m": "music"}, - ''); - }); - - test('default namespace has key of empty string', function() { - var element = xml.element("root", {}, [ - xml.element("{music}album") - ]); - assertXmlString(element, {"": "music"}, - ''); - }); +test('writing empty root element writes out xml declaration and empty root element', function() { + assertXmlString(xml.element("root"), {}, ''); +}); + +test('can write empty child elements', function() { + assertXmlString(xml.element("root", {}, [xml.element("album"), xml.element("single")]), {}, + ''); +}); + +test('can write empty descendant elements', function() { + var element = xml.element("root", {}, [ + xml.element("album", {}, [ + xml.element("year"), + xml.element("song") + ]) + ]); + assertXmlString(element, {}, + ''); +}); + +test('can write element attributes', function() { + var element = xml.element("root", {}, [ + xml.element("album", {"title": "Everything in Transit"}) + ]); + assertXmlString(element, {}, + ''); +}); + +test('can write text nodes', function() { + var element = xml.element("root", {}, [ + xml.element("album", {}, [ + xml.text("Everything in Transit") + ]) + ]); + assertXmlString(element, {}, + 'Everything in Transit'); +}); + +test('can write root element with long-form prefix when URI is namespace', function() { + var element = xml.element("{music}root"); + assertXmlString(element, {"m": "music"}, + ''); +}); + +test('can write child elements with long-form prefix when URI is namespace', function() { + var element = xml.element("root", {}, [ + xml.element("{music}album") + ]); + assertXmlString(element, {"m": "music"}, + ''); +}); + +test('can write child elements with short-form prefix when URI is namespace', function() { + var element = xml.element("root", {}, [ + xml.element("m:album") + ]); + assertXmlString(element, {"m": "music"}, + ''); +}); + +test('default namespace has key of empty string', function() { + var element = xml.element("root", {}, [ + xml.element("{music}album") + ]); + assertXmlString(element, {"": "music"}, + ''); }); -- cgit v1.2.3