-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
61 lines (49 loc) · 1.68 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var sys = require('util')
var xml = require('./index')
var assert = require('assert')
describe('xml-events', function() {
it('should return an error for a null string', function(done) {
var parse = xml.parser(function(err, root) {
assert.ok(err)
done()
})
parse(null)
})
it('should error if not complete', function(done) {
xml.parse("<root", function(err, root) {
assert.ok(err, "Parser should have returned an error on parse if incomplete")
done()
})
})
it('should parse some xml', function(done) {
xml.parse("<root><one>hello</one><two att='value'/></root>", function(err, root) {
assert.ifError(err)
assert.ok(root.toString())
root.on('one', function(node) {
assert.equal(node.text, "hello")
root.on('two', function(node) {
assert.equal(node.attr('att'), "value")
root.onEnd(function() {
done()
})
})
})
})
})
it('should parse a stream', function(done) {
var parse = xml.parser(function(err, root) {
var names = []
root.on('name', function(name) {
names.push(name.text)
})
root.onEnd(function() {
assert.equal(names.length, 4)
done()
})
})
parse("<roo")
parse("t><name>henry</name><name>bo")
parse("b</name><name>john</na")
parse("me><name>will</name></root>")
})
})