Permalink
Browse files

Made XML tests prettier and not fail due to dangling whitespace

  • Loading branch information...
Leonidas-from-XIV committed Jan 2, 2014
1 parent ad05a02 commit fd9a299ed85d34985315b5899184d10a27a64bd2
Showing with 17 additions and 18 deletions.
  1. +1 −1 package.json
  2. +16 −17 test/builder.test.coffee
View
@@ -49,7 +49,7 @@
"coffee-script" : ">=1.6.3",
"zap" : ">=0.2.5",
"docco" : ">=0.6.2",
- "diff" : ">=1.0.7"
+ "diff" : ">=1.0.8"
},
"licenses": [
{
View
@@ -13,25 +13,24 @@ equ = assert.equal
# equality test with diff output
diffeq = (expected, actual) ->
diffless = "Index: test\n===================================================================\n--- test\texpected\n+++ test\tactual\n"
- patch = diff.createPatch('test', expected, actual, 'expected', 'actual')
+ patch = diff.createPatch('test', expected.trim(), actual.trim(), 'expected', 'actual')
throw patch unless patch is diffless
module.exports =
'test building basic XML structure': (test) ->
expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xml><Label></Label><MsgId>5850440872586764820</MsgId></xml>'
obj = {"xml":{"Label":[""],"MsgId":["5850440872586764820"]}}
- builder = new xml2js.Builder(renderOpts: { pretty: false })
+ builder = new xml2js.Builder renderOpts: pretty: false
actual = builder.buildObject obj
diffeq expected, actual
test.finish()
'test setting XML declaration': (test) ->
expected = '<?xml version="1.2" encoding="WTF-8" standalone="no"?><root/>'
- opts = {
- renderOpts: { pretty: false }
- xmldec: {'version': '1.2', 'encoding': 'WTF-8', 'standalone': false}
- }
- builder = new xml2js.Builder(opts)
+ opts =
+ renderOpts: pretty: false
+ xmldec: 'version': '1.2', 'encoding': 'WTF-8', 'standalone': false
+ builder = new xml2js.Builder opts
actual = builder.buildObject {}
diffeq expected, actual
test.finish()
@@ -58,44 +57,44 @@ module.exports =
</xml>
"""
- opts = { renderOpts: { pretty: true, indent: ' ' } }
- builder = new xml2js.Builder(opts)
+ opts = renderOpts: pretty: true, indent: ' '
+ builder = new xml2js.Builder opts
obj = {"xml":{"MsgId":["5850440872586764820"]}}
actual = builder.buildObject obj
diffeq expected, actual
test.finish()
'test explicit rootName is always used: 1. when there is only one element': (test) ->
expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><FOO><MsgId>5850440872586764820</MsgId></FOO>'
- opts = { renderOpts: { pretty: false }, rootName: 'FOO' }
- builder = new xml2js.Builder(opts)
+ opts = renderOpts: {pretty: false}, rootName: 'FOO'
+ builder = new xml2js.Builder opts
obj = {"MsgId":["5850440872586764820"]}
actual = builder.buildObject obj
diffeq expected, actual
test.finish()
'test explicit rootName is always used: 2. when there are multiple elements': (test) ->
expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><FOO><MsgId>5850440872586764820</MsgId></FOO>'
- opts = { renderOpts: { pretty: false }, rootName: 'FOO' }
- builder = new xml2js.Builder(opts)
+ opts = renderOpts: {pretty: false}, rootName: 'FOO'
+ builder = new xml2js.Builder opts
obj = {"MsgId":["5850440872586764820"]}
actual = builder.buildObject obj
diffeq expected, actual
test.finish()
'test default rootName is used when there is more than one element in the hash': (test) ->
expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><root><MsgId>5850440872586764820</MsgId><foo>bar</foo></root>'
- opts = { renderOpts: { pretty: false } }
- builder = new xml2js.Builder(opts)
+ opts = renderOpts: pretty: false
+ builder = new xml2js.Builder opts
obj = {"MsgId":["5850440872586764820"],"foo":"bar"}
actual = builder.buildObject obj
diffeq expected, actual
test.finish()
'test when there is only one first-level element in the hash, that is used as root': (test) ->
expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><first><MsgId>5850440872586764820</MsgId><foo>bar</foo></first>'
- opts = { renderOpts: { pretty: false } }
- builder = new xml2js.Builder(opts)
+ opts = renderOpts: pretty: false
+ builder = new xml2js.Builder opts
obj = {"first":{"MsgId":["5850440872586764820"],"foo":"bar"}}
actual = builder.buildObject obj
diffeq expected, actual

0 comments on commit fd9a299

Please sign in to comment.