Skip to content
Browse files

Added unittest for the current root eliminating behavior

  • Loading branch information...
1 parent dacd915 commit 48ff730f3bb70140cd22556bb5fe4734e8a23bf0 @Leonidas-from-XIV committed Aug 14, 2011
Showing with 13 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +12 −2 test/xml2js.test.coffee
View
1 .gitignore
@@ -1 +1,2 @@
*.swp
+node_modules
View
14 test/xml2js.test.coffee
@@ -3,15 +3,22 @@ xml2js = require '../lib/xml2js'
fs = require 'fs'
sys = require 'sys'
assert = require 'assert'
+path = require 'path'
skeleton = (options, checks) ->
(test) ->
+ xmlString = options?.__xmlString
+ delete options?.__xmlString
x2js = new xml2js.Parser(options)
x2js.addListener 'end', (r) ->
checks(r)
test.finish()
- fs.readFile __dirname + '/fixtures/sample.xml', (err, data) ->
- x2js.parseString data
+ fileName = path.join(__dirname, '/fixtures/sample.xml')
+ if not xmlString
+ fs.readFile fileName, (err, data) ->
+ x2js.parseString data
+ else
+ x2js.parseString xmlString
module.exports =
'test parse with defaults': skeleton(undefined, (r) ->
@@ -58,3 +65,6 @@ module.exports =
'test disable normalize and trim': skeleton({normalize: false, trim: false}, (r) ->
assert.equal r['whitespacetest']['#'], '\n Line One\n Line Two\n ')
+
+ 'test root node eliminiation': skeleton({__xmlString: '<root></root>'}, (r) ->
+ assert.deepEqual r, {})

0 comments on commit 48ff730

Please sign in to comment.
Something went wrong with that request. Please try again.