1
1
var markdown = require ( "../src/markdown" ) ,
2
2
tap = require ( "tap" ) ;
3
3
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
+
4
10
tap . test ( "undefined attribute" , function ( t ) {
5
11
var tree = markdown . renderJsonML ( [ 'html' , [ 'p' , { style : undefined } , 'hello' ] ] ) ;
6
12
t . equivalent ( tree , '<p>hello</p>' ) ;
@@ -12,3 +18,17 @@ tap.test("escaped attribute", function(t) {
12
18
t . equivalent ( tree , '<p style="color: blue">hello</p>' ) ;
13
19
t . end ( ) ;
14
20
} ) ;
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