//copyright Ryan Day 2010 [MIT Licensed] var test = require('tape') , jsonxml = require("./jsontoxml.js") ; var date = (new Date()); var input = { node:'text content', parent:[ {name:'taco',text:'beef taco',children:{salsa:'hot!'}}, {name:'xml',text:'tag'}, {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:'this & this is a nice thing to say', node:'i am another not special child node', date:date+'', date2:date } }; var expected_no_element_substitution = 'text content' +'' +'' +'beef taco' +'hot!' +'' +'tag' +'' +'fish taco' +'mild' +'hi' +'weak' +'' +"" +'' +'' +'this & this is a nice thing to say' +'i am another not special child node' +''+date+'' +''+date.toJSON()+'' +''; var expected_with_element_substitution = 'text content' +'' +'' +'beef taco' +'hot!' +'' +'<_>tag' +'' +'fish taco' +'mild' +'hi' +'weak' +'' +"" +'' +'' +'this & this is a nice thing to say' +'i am another not special child node' +''+date+'' +''+date.toJSON()+'' +''; var expected = expected_no_element_substitution; var buffer = new Buffer(JSON.stringify(input)); test("creates correct object from buffer",function(t){ var result = jsonxml(buffer,{escape:true}); t.equals(result,expected,' should have generated correct xml'); t.end() }); test("creates correct object from string",function(t){ var result = jsonxml(input,{escape:true}); t.equals(result,expected,' test should have generated correct xml'); t.end() }); test("creates correct object with element fixup",function(t){ var result = jsonxml(input,{escape:true, removeIllegalNameCharacters:true}); t.equals(result,expected_with_element_substitution,' test should have generated correct xml'); t.end() });