Skip to content

Commit

Permalink
tests for node / attribute name non-agnostic processor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Shaffer committed Jan 24, 2017
1 parent b8e2621 commit 2a1db93
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/processors.test.coffee
@@ -1,7 +1,13 @@
processors = require '../lib/processors'
xml2js = require '../lib/xml2js'
assert = require 'assert'
equ = assert.equal

parseNumbersExceptAccount = (value, key) ->
if (key == 'accountNumber')
return value;
return processors.parseNumbers(value);

module.exports =
'test normalize': (test) ->
demo = 'This shOUld BE loWErcase'
Expand Down Expand Up @@ -45,4 +51,20 @@ module.exports =
equ processors.parseBooleans('xtrue'), 'xtrue'
equ processors.parseBooleans('x'), 'x'
equ processors.parseBooleans(''), ''
test.done()
test.done()

'test a processor that filters by node name': (test) ->
xml = '<account><accountNumber>0012345</accountNumber><balance>123.45</balance></account>'
options = { valueProcessors: [parseNumbersExceptAccount] }
xml2js.parseString xml, options, (err, parsed) ->
equ parsed.account.accountNumber, '0012345'
equ parsed.account.balance, 123.45
test.finish()

'test a processor that filters by attr name': (test) ->
xml = '<account accountNumber="0012345" balance="123.45" />'
options = { attrValueProcessors: [parseNumbersExceptAccount] }
xml2js.parseString xml, options, (err, parsed) ->
equ parsed.account.$.accountNumber, '0012345'
equ parsed.account.$.balance, 123.45
test.finish()

0 comments on commit 2a1db93

Please sign in to comment.