Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit fb6c20b

Browse files
committed
* 'master' of https://github.com/buglabs/node-xml2json: add coverage test option so as to see what's untested convert array notation test to lab. remove unnecesary makefile convert coerce tests to lab
2 parents eb2bc72 + 8448c66 commit fb6c20b

File tree

5 files changed

+56
-56
lines changed

5 files changed

+56
-56
lines changed

Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"main": "index",
88
"scripts": {
9-
"test": "make test"
9+
"test": "lab -a code -v -t 93 test/test.js"
1010
},
1111
"dependencies": {
1212
"hoek": "^2.14.0",

test/test-array-notation.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/test-coerce.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,50 @@ describe('xml2json', function () {
106106
expect(throws).to.throw();
107107
done();
108108
});
109+
110+
describe('coercion', function () {
111+
112+
var file = __dirname + '/fixtures/coerce.xml';
113+
var data = fs.readFileSync(file);
114+
115+
it('works with coercion', function(done) {
116+
117+
// With coercion
118+
var result = parser.toJson(data, {reversible: true, coerce: true, object: true});
119+
expect(result.itemRecord.value[0].longValue['$t']).to.equal(12345);
120+
expect(result.itemRecord.value[1].stringValue.number).to.equal(false);
121+
expect(result.itemRecord.value[2].moneyValue.number).to.equal(true);
122+
expect(result.itemRecord.value[2].moneyValue['$t']).to.equal(104.95);
123+
expect(result.itemRecord.value[2].moneyValue.text).to.equal(123.45);
124+
expect(result.itemRecord.value[8].text['$t']).to.equal(42.42);
125+
done();
126+
});
127+
128+
it('works without coercion', function(done) {
129+
130+
var result = parser.toJson(data, {reversible: true, coerce: false, object: true});
131+
expect(result.itemRecord.value[0].longValue['$t']).to.equal('12345');
132+
expect(result.itemRecord.value[1].stringValue.number).to.equal('false');
133+
expect(result.itemRecord.value[2].moneyValue.number).to.equal('true');
134+
expect(result.itemRecord.value[2].moneyValue['$t']).to.equal('104.95');
135+
expect(result.itemRecord.value[2].moneyValue.text).to.equal('123.45');
136+
expect(result.itemRecord.value[8].text['$t']).to.equal('42.42');
137+
done();
138+
});
139+
140+
it('works with coercion as an optional object', function(done) {
141+
142+
var result = parser.toJson(data, {reversible: true, coerce: {text:String}, object: true});
143+
expect(result.itemRecord.value[0].longValue['$t']).to.equal(12345);
144+
expect(result.itemRecord.value[1].stringValue.number).to.equal(false);
145+
expect(result.itemRecord.value[2].moneyValue.number).to.equal(true);
146+
expect(result.itemRecord.value[2].moneyValue['$t']).to.equal(104.95);
147+
expect(result.itemRecord.value[2].moneyValue.text).to.equal('123.45');
148+
expect(result.itemRecord.value[8].text['$t']).to.equal('42.42');
149+
done();
150+
});
151+
})
152+
109153
});
110154

111155

@@ -122,6 +166,17 @@ describe('json2xml', function () {
122166
done();
123167
});
124168

169+
it('works with array notation', function (done) {
170+
171+
var xml = fs.readFileSync('./test/fixtures/array-notation.xml');
172+
var expectedJson = JSON.parse( fs.readFileSync('./test/fixtures/array-notation.json') );
173+
174+
var json = parser.toJson(xml, {object: true, arrayNotation: true});
175+
176+
expect(json).to.deep.equal(expectedJson);
177+
178+
done();
179+
});
125180
});
126181

127182

0 commit comments

Comments
 (0)