summaryrefslogtreecommitdiff
path: root/test/html
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/html
parent28a0e40b645c051d91626ca90959e847b061c8da (diff)
Use exports for all tests
Diffstat (limited to 'test/html')
-rw-r--r--test/html/simplify.tests.js182
-rw-r--r--test/html/write.tests.js60
2 files changed, 119 insertions, 123 deletions
diff --git a/test/html/simplify.tests.js b/test/html/simplify.tests.js
index 1058fe9..50593ee 100644
--- a/test/html/simplify.tests.js
+++ b/test/html/simplify.tests.js
@@ -2,107 +2,105 @@ var assert = require("assert");
var _ = require("underscore");
-var test = require("../testing").test;
+var test = require("../test")(module);
var html = require("../../lib/html");
var htmlPaths = require("../../lib/html-paths");
var nonFreshElement = html.nonFreshElement;
var text = html.text;
-describe("simplify", function() {
- test("empty text nodes are removed", function() {
- assert.deepEqual(
- simplifyNode(text("")),
- []
- );
- });
-
- test("elements with no children are removed", function() {
- assert.deepEqual(
- simplifyNode(nonFreshElement("p", {}, [])),
- []
- );
- });
-
- test("elements only containing empty nodes are removed", function() {
- assert.deepEqual(
- simplifyNode(nonFreshElement("p", {}, [text("")])),
- []
- );
- });
-
- test("empty children of element are removed", function() {
- assert.deepEqual(
- simplifyNode(nonFreshElement("p", {}, [text("Hello"), text("")])),
- [nonFreshElement("p", {}, [text("Hello")])]
- );
- });
+test("empty text nodes are removed", function() {
+ assert.deepEqual(
+ simplifyNode(text("")),
+ []
+ );
+});
+
+test("elements with no children are removed", function() {
+ assert.deepEqual(
+ simplifyNode(nonFreshElement("p", {}, [])),
+ []
+ );
+});
+
+test("elements only containing empty nodes are removed", function() {
+ assert.deepEqual(
+ simplifyNode(nonFreshElement("p", {}, [text("")])),
+ []
+ );
+});
+
+test("empty children of element are removed", function() {
+ assert.deepEqual(
+ simplifyNode(nonFreshElement("p", {}, [text("Hello"), text("")])),
+ [nonFreshElement("p", {}, [text("Hello")])]
+ );
+});
+
+test("successive fresh elements are not collapsed", function() {
+ var path = htmlPaths.elements([
+ htmlPaths.element("p", {}, {fresh: true})
+ ]);
+ var original = concat(
+ pathToNodes(path, [text("Hello")]),
+ pathToNodes(path, [text(" there")])
+ );
- test("successive fresh elements are not collapsed", function() {
- var path = htmlPaths.elements([
- htmlPaths.element("p", {}, {fresh: true})
- ]);
- var original = concat(
+ assert.deepEqual(
+ html.simplify(original),
+ original);
+});
+
+test("successive plain non-fresh elements are collapsed if they have the same tag name", function() {
+ var path = htmlPaths.elements([
+ htmlPaths.element("p", {}, {fresh: false})
+ ]);
+ assert.deepEqual(
+ html.simplify(concat(
pathToNodes(path, [text("Hello")]),
pathToNodes(path, [text(" there")])
- );
-
- assert.deepEqual(
- html.simplify(original),
- original);
- });
-
- test("successive plain non-fresh elements are collapsed if they have the same tag name", function() {
- var path = htmlPaths.elements([
- htmlPaths.element("p", {}, {fresh: false})
- ]);
- assert.deepEqual(
- html.simplify(concat(
- pathToNodes(path, [text("Hello")]),
- pathToNodes(path, [text(" there")])
- )),
- pathToNodes(path, [text("Hello"), text(" there")])
- );
- });
-
- test("non-fresh can collapse into preceding fresh element", function() {
- var freshPath = htmlPaths.elements([
- htmlPaths.element("p", {}, {fresh: true})]);
- var nonFreshPath = htmlPaths.elements([
- htmlPaths.element("p", {}, {fresh: false})]);
- assert.deepEqual(
- html.simplify(concat(
- pathToNodes(freshPath, [text("Hello")]),
- pathToNodes(nonFreshPath, [text(" there")])
- )),
- pathToNodes(freshPath, [text("Hello"), text(" there")])
- );
- });
-
- test("children of collapsed element can collapse with children of another collapsed element", function() {
- assert.deepEqual(
- html.simplify([
- nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("Hello")])]),
- nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("there")])])
- ]),
- [nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("Hello"), text("there")])])]
- );
- });
-
- test("empty elements are removed before collapsing", function() {
- var freshPath = htmlPaths.elements([
- htmlPaths.element("p", {}, {fresh: true})]);
- var nonFreshPath = htmlPaths.elements([
- htmlPaths.element("p", {}, {fresh: false})]);
- assert.deepEqual(
- html.simplify(concat(
- pathToNodes(nonFreshPath, [text("Hello")]),
- pathToNodes(freshPath, []),
- pathToNodes(nonFreshPath, [text(" there")])
- )),
- pathToNodes(nonFreshPath, [text("Hello"), text(" there")])
- );
- });
+ )),
+ pathToNodes(path, [text("Hello"), text(" there")])
+ );
+});
+
+test("non-fresh can collapse into preceding fresh element", function() {
+ var freshPath = htmlPaths.elements([
+ htmlPaths.element("p", {}, {fresh: true})]);
+ var nonFreshPath = htmlPaths.elements([
+ htmlPaths.element("p", {}, {fresh: false})]);
+ assert.deepEqual(
+ html.simplify(concat(
+ pathToNodes(freshPath, [text("Hello")]),
+ pathToNodes(nonFreshPath, [text(" there")])
+ )),
+ pathToNodes(freshPath, [text("Hello"), text(" there")])
+ );
+});
+
+test("children of collapsed element can collapse with children of another collapsed element", function() {
+ assert.deepEqual(
+ html.simplify([
+ nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("Hello")])]),
+ nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("there")])])
+ ]),
+ [nonFreshElement("blockquote", {}, [nonFreshElement("p", {}, [text("Hello"), text("there")])])]
+ );
+});
+
+test("empty elements are removed before collapsing", function() {
+ var freshPath = htmlPaths.elements([
+ htmlPaths.element("p", {}, {fresh: true})]);
+ var nonFreshPath = htmlPaths.elements([
+ htmlPaths.element("p", {}, {fresh: false})]);
+ assert.deepEqual(
+ html.simplify(concat(
+ pathToNodes(nonFreshPath, [text("Hello")]),
+ pathToNodes(freshPath, []),
+ pathToNodes(nonFreshPath, [text(" there")])
+ )),
+ pathToNodes(nonFreshPath, [text("Hello"), text(" there")])
+ );
});
function simplifyNode(node) {
diff --git a/test/html/write.tests.js b/test/html/write.tests.js
index 531995f..9db8c79 100644
--- a/test/html/write.tests.js
+++ b/test/html/write.tests.js
@@ -1,40 +1,38 @@
var assert = require("assert");
-var test = require("../testing").test;
+var test = require("../test")(module);
var html = require("../../lib/html");
var writers = require("../../lib/writers");
-describe("HTML write", function() {
- test("text is HTML escaped", function() {
- assert.equal(
- generateString(html.text("<>&")),
- "&lt;&gt;&amp;");
- });
-
- test("double quotes outside of attributes are not escaped", function() {
- assert.equal(
- generateString(html.text('"')),
- '"');
- });
-
- test("element attributes are HTML escaped", function() {
- assert.equal(
- generateString(html.freshElement("p", {"x": "<"})),
- '<p x="&lt;"></p>');
- });
-
- test("double quotes inside attributes are escaped", function() {
- assert.equal(
- generateString(html.freshElement("p", {"x": '"'})),
- '<p x="&quot;"></p>');
- });
-
- test("element children are written", function() {
- assert.equal(
- generateString(html.freshElement("p", {}, [html.text("Hello")])),
- '<p>Hello</p>');
- });
+test("text is HTML escaped", function() {
+ assert.equal(
+ generateString(html.text("<>&")),
+ "&lt;&gt;&amp;");
+});
+
+test("double quotes outside of attributes are not escaped", function() {
+ assert.equal(
+ generateString(html.text('"')),
+ '"');
+});
+
+test("element attributes are HTML escaped", function() {
+ assert.equal(
+ generateString(html.freshElement("p", {"x": "<"})),
+ '<p x="&lt;"></p>');
+});
+
+test("double quotes inside attributes are escaped", function() {
+ assert.equal(
+ generateString(html.freshElement("p", {"x": '"'})),
+ '<p x="&quot;"></p>');
+});
+
+test("element children are written", function() {
+ assert.equal(
+ generateString(html.freshElement("p", {}, [html.text("Hello")])),
+ '<p>Hello</p>');
});
function generateString(node) {