forked from cheggaaa/geddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml.js
57 lines (46 loc) · 1.51 KB
/
xml.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
// Load the basic Geddy toolkit
require('../lib/geddy');
var XML = geddy.XML
, assert = require('assert')
, obj
, xml
, res;
XML.setNoWhitespace();
var tests = new (function () {
this.testObject = function () {
obj = {foo: 'bar'};
xml = XML.stringify(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><object><foo>bar</foo></object>';
assert.equal(res, xml);
};
this.testArrayNumbers = function () {
obj = [1, 2, 3];
xml = XML.stringify(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><numbers type="array"><number>1</number><number>2</number><number>3</number></numbers>';
assert.equal(res, xml);
};
this.testArrayStrings = function () {
obj = ['foo', 'bar'];
xml = XML.stringify(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><strings type="array"><string>foo</string><string>bar</string></strings>';
assert.equal(res, xml);
};
this.testArrayMixed = function () {
obj = ['foo', 1];
xml = XML.stringify(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><records type="array"><record>foo</record><record>1</record></records>';
assert.equal(res, xml);
};
this.testArrayPropOfObject = function () {
obj = {foo: ['bar', 'baz']};
xml = XML.stringify(obj);
res = '<?xml version="1.0" encoding="UTF-8"?><object><foo type="array"><foo>bar</foo><foo>baz</foo></foo></object>';
assert.equal(res, xml);
};
})();
for (var p in tests) {
if (typeof tests[p] == 'function') {
console.log('Running ' + p);
tests[p]();
}
}