Skip to content

Commit

Permalink
Ported tests to CoffeeScript
Browse files Browse the repository at this point in the history
We need version 0.2.3 of the zap test runner as it supports CoffeeScript
  • Loading branch information
Leonidas-from-XIV committed Jun 11, 2011
1 parent 47fb32a commit f0685b8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 61 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -23,6 +23,6 @@
"sax" : ">=0.1.1"
},
"devDependencies" : {
"zap" : ">=0.2.0"
"zap" : ">=0.2.3"
}
}
52 changes: 52 additions & 0 deletions test/xml2js.test.coffee
@@ -0,0 +1,52 @@
# use zap to run tests, it also detects CoffeeScript files
xml2js = require('../lib/xml2js')
fs = require('fs')
sys = require('sys')
assert = require('assert')

module.exports =
'test default parse': (test) ->
x2js = new xml2js.Parser()
x2js.addListener 'end', (r) ->
console.log 'Result object: ' + sys.inspect(r, false, 10)
assert.equal r['chartest']['@']['desc'], 'Test for CHARs'
assert.equal r['chartest']['#'], 'Character data here!'
assert.equal r['cdatatest']['@']['desc'], 'Test for CDATA'
assert.equal r['cdatatest']['@']['misc'], 'true'
assert.equal r['cdatatest']['#'], 'CDATA here!'
assert.equal r['nochartest']['@']['desc'], 'No data'
assert.equal r['nochartest']['@']['misc'], 'false'
assert.equal r['listtest']['item'][0]['#'], 'This is character data!'
assert.equal r['listtest']['item'][0]['subitem'][0], 'Foo(1)'
assert.equal r['listtest']['item'][0]['subitem'][1], 'Foo(2)'
assert.equal r['listtest']['item'][0]['subitem'][2], 'Foo(3)'
assert.equal r['listtest']['item'][0]['subitem'][3], 'Foo(4)'
assert.equal r['listtest']['item'][1], 'Qux.'
assert.equal r['listtest']['item'][2], 'Quux.'
test.finish()

fs.readFile __dirname + '/fixtures/sample.xml', (err, data) ->
x2js.parseString data

'test parse EXPLICIT_CHARKEY': (test) ->
x2js = new xml2js.Parser()
x2js.EXPLICIT_CHARKEY = true
x2js.addListener 'end', (r) ->
assert.equal r['chartest']['@']['desc'], 'Test for CHARs'
assert.equal r['chartest']['#'], 'Character data here!'
assert.equal r['cdatatest']['@']['desc'], 'Test for CDATA'
assert.equal r['cdatatest']['@']['misc'], 'true'
assert.equal r['cdatatest']['#'], 'CDATA here!'
assert.equal r['nochartest']['@']['desc'], 'No data'
assert.equal r['nochartest']['@']['misc'], 'false'
assert.equal r['listtest']['item'][0]['#'], 'This is character data!'
assert.equal r['listtest']['item'][0]['subitem'][0]['#'], 'Foo(1)'
assert.equal r['listtest']['item'][0]['subitem'][1]['#'], 'Foo(2)'
assert.equal r['listtest']['item'][0]['subitem'][2]['#'], 'Foo(3)'
assert.equal r['listtest']['item'][0]['subitem'][3]['#'], 'Foo(4)'
assert.equal r['listtest']['item'][1]['#'], 'Qux.'
assert.equal r['listtest']['item'][2]['#'], 'Quux.'
test.finish()

fs.readFile __dirname + '/fixtures/sample.xml', (err, data) ->
x2js.parseString data
60 changes: 0 additions & 60 deletions test/xml2js.test.js

This file was deleted.

0 comments on commit f0685b8

Please sign in to comment.