aboutsummaryrefslogtreecommitdiff
path: root/test/xml/reader.tests.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-07-07 22:17:34 +0100
committerMichael Williamson <mike@zwobble.org>2016-07-07 22:17:34 +0100
commita080fc59a3fca08bdc6e23a2eeae440f5c7047b3 (patch)
tree3d56033c294c617eb7de6b693750efb70a81dd4f /test/xml/reader.tests.js
parent28a0e40b645c051d91626ca90959e847b061c8da (diff)
Use exports for all tests
Diffstat (limited to 'test/xml/reader.tests.js')
-rw-r--r--test/xml/reader.tests.js132
1 files changed, 65 insertions, 67 deletions
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("<body/>").then(function(result) {
- assert.deepEqual({type: "element", name: "body", attributes: {}, children: []}, result);
- });
+test('should read self-closing element', function() {
+ return xmlreader.readString("<body/>").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("<body></body>").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("<body></body>").then(function(result) {
+ assert.deepEqual({type: "element", name: "body", attributes: {}, children: []}, result);
});
-
- test('should read attributes of tags', function() {
- return xmlreader.readString('<body name="bob"/>').then(function(result) {
- assert.deepEqual({name: "bob"}, result.attributes);
- });
+});
+
+test('should read attributes of tags', function() {
+ return xmlreader.readString('<body name="bob"/>').then(function(result) {
+ assert.deepEqual({name: "bob"}, result.attributes);
});
-
- test('can read text element', function() {
- return xmlreader.readString('<body>Hello!</body>').then(function(result) {
- assert.deepEqual({type: "text", value: "Hello!"}, result.children[0]);
- });
+});
+
+test('can read text element', function() {
+ return xmlreader.readString('<body>Hello!</body>').then(function(result) {
+ assert.deepEqual({type: "text", value: "Hello!"}, result.children[0]);
});
-
- test('should read element with children', function() {
- return xmlreader.readString("<body><a/><b/></body>").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("<body><a/><b/></body>").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('<w:body xmlns:w="word"/>').then(function(result) {
- assert.deepEqual(result.name, "{word}body");
- });
+test('unmapped namespaces URIs are included in braces as prefix', function() {
+ return xmlreader.readString('<w:body xmlns:w="word"/>').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('<w:body xmlns:w="word"/>', 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('<w:body xmlns:w="word"/>', 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 = '<w:body xmlns:w="word" w:val="Hello!"/>';
- 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 = '<w:body xmlns:w="word" w:val="Hello!"/>';
+ 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('<body><a/><b index="1"/><b index="2"/></body>').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('<body><a/><b index="1"/><b index="2"/></body>').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('<?xml version="1.0" ?>\n<body/>').then(function(result) {
- assert.deepEqual("body", result.name);
- });
+});
+
+test('whitespace between xml declaration and root tag is ignored', function() {
+ return xmlreader.readString('<?xml version="1.0" ?>\n<body/>').then(function(result) {
+ assert.deepEqual("body", result.name);
});
-
- test('error if XML is badly formed', function() {
- return xmlreader.readString("<bo").then(function(result) {
- throw new Error("Expected failure");
- }, function(error) {
- assert.ok(error);
- return 1;
- });
+});
+
+test('error if XML is badly formed', function() {
+ return xmlreader.readString("<bo").then(function(result) {
+ throw new Error("Expected failure");
+ }, function(error) {
+ assert.ok(error);
+ return 1;
});
});