forked from soldair/node-jsontoxml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
63 lines (54 loc) · 1.22 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
copyright Ryan Day 2010 <http://ryanday.org> [MIT Licensed]
no testing framework required!
HOW TO:
node test.js
*/
var jsonxml = require("./jsontoxml.js");
var date = (new Date())+'';
var input = {
node:'text content',
parent:[
{name:'taco',text:'beef taco',children:{salsa:'hot!'}},
{name:'taco',text:'fish taco',attrs:{mood:'sad'},children:[
{name:'salsa',text:'mild'},
'hi',
{name:'salsa',text:'weak',attrs:{type:2}}
]},
{name:'taco',attrs:"mood='party!'"}
],
parent2:{
hi:'is a nice thing to say',
node:'i am another not special child node',
date:function(){
return date;
}
}
};
var expected = '<node>text content</node>'
+'<parent>'
+'<taco>'
+'beef taco'
+'<salsa>hot!</salsa>'
+'</taco>'
+'<taco mood="sad">'
+'fish taco'
+'<salsa>mild</salsa>'
+'hi'
+'<salsa type="2">weak</salsa>'
+'</taco>'
+"<taco mood='party!'/>"
+'</parent>'
+'<parent2>'
+'<hi>is a nice thing to say</hi>'
+'<node>i am another not special child node</node>'
+'<date>'+date+'</date>'
+'</parent2>';
var result = jsonxml.obj_to_xml(input);
if(result == expected){
console.log('PASSED!');
} else {
console.log('FAILED!');
console.log(result);
console.log('did not match expected!');
}