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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
testSupport.lib('responder');
testSupport.lib('sax');
testSupport.lib('sax/base');
suite('caldav/sax/base', function() {
var data,
subject,
parser,
Parse,
Base,
handler;
suiteSetup(function() {
Parse = Caldav.require('sax');
Base = Caldav.require('sax/base');
});
setup(function() {
//we omit the option to pass base parser
//because we are the base parser
subject = new Parse();
});
test('#create', function() {
function childText() {}
var Child = Base.create({
ontext: childText
});
assert.equal(Child.ontext, childText);
assert.equal(Child.tagField, Base.tagField);
assert.isTrue(
Base.isPrototypeOf(Child),
'should have base in proto chain'
);
assert.equal(Child._super, Base);
var ChildChild = Child.create();
assert.isTrue(
Child.isPrototypeOf(ChildChild),
'should have child in childchild protochain'
);
assert.isTrue(
Base.isPrototypeOf(ChildChild),
'should have base in childchild protochain'
);
assert.equal(ChildChild._super, Child);
});
suite('base parser', function() {
var xml, data;
testSupport.defineSample('xml/simple.xml', function(data) {
xml = data;
});
//base baser does not
//care about attrs at this point
var expected = {
simple: {
a: [
{ value: 'Foo' },
{ value: 'Foo\n bar' }
],
div: {
span: {
value: 'span'
}
}
}
};
test('simple tree', function(done) {
subject.once('complete', function(data) {
assert.deepEqual(
data, expected,
"expected \n '" + JSON.stringify(data) + "'\n to equal \n '" +
JSON.stringify(expected) + '\n"'
);
done();
});
subject.write(xml).close();
});
});
});
|