Skip to content

Commit 7fb0fba

Browse files
committed
Write a mutation check for toHTMLTree and renderJsonML (renderJsonML fails)
1 parent 9782714 commit 7fb0fba

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/render_tree.t.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
var markdown = require("../src/markdown"),
22
tap = require("tap");
33

4+
function clone_array( input ) {
5+
// Helper method. Since the objects are plain round trip through JSON to get
6+
// a clone
7+
return JSON.parse( JSON.stringify( input ) );
8+
}
9+
410
tap.test("undefined attribute", function(t) {
511
var tree = markdown.renderJsonML( ['html', ['p', {style: undefined }, 'hello'] ] );
612
t.equivalent( tree, '<p>hello</p>' );
@@ -12,3 +18,17 @@ tap.test("escaped attribute", function(t) {
1218
t.equivalent( tree, '<p style="color: blue">hello</p>' );
1319
t.end();
1420
});
21+
22+
tap.test("intermediate trees left alone", function(t) {
23+
var markdownTree = [ [ "bulletlist", [ "listitem", "foo\nbaz" ], [ "listitem", "bar\nbaz" ] ] ];
24+
var cloneMarkdownTree = clone_array( markdownTree );
25+
markdown.toHTMLTree( markdownTree );
26+
t.equivalent( markdownTree, cloneMarkdownTree, 'toHTMLTree should not mutate its argument' );
27+
28+
var htmlTree = ['html', ['p', {style: "color: blue" }, 'hello'] ];
29+
var cloneHtmlTree = clone_array( htmlTree );
30+
markdown.renderJsonML( htmlTree );
31+
t.equivalent( htmlTree, cloneHtmlTree, 'renderJsonML should not mutate its argument' );
32+
33+
t.end();
34+
});

0 commit comments

Comments
 (0)