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

Commit c0730c6

Browse files
committed
jfdi straight comparison
1 parent 58984ec commit c0730c6

7 files changed

+37
-25
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"unit":{"test":{"case":[{"justText":{"$t":"blah blah"}},{"attribText":{"attrib":"das","$t":"capital"}},{"spaces":{"$t":"abc\nasdf\n a"}},{"type":"SANATISE","san":{"b":"Smith & Son","$t":"Alpha & Omega"}}]}}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"unit":{"test":{"case":[{"justText":{"_t":"blah blah"}},{"attribText":{"attrib":"das","_t":"capital"}},{"spaces":{"_t":"abc\nasdf\n a"}},{"type":"SANATISE","san":{"b":"Smith & Son","_t":"Alpha & Omega"}}]}}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"unit":{"test":{"case":[{"justText":{"xx":"blah blah"}},{"attribText":{"attrib":"das","xx":"capital"}},{"spaces":{"xx":"abc\nasdf\n a"}},{"type":"SANATISE","san":{"b":"Smith & Son","xx":"Alpha & Omega"}}]}}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"unit":{"test":{"case":[{"justText":{"zz":"blah blah"}},{"attribText":{"attrib":"das","zz":"capital"}},{"spaces":{"zz":"abc\nasdf\n a"}},{"type":"SANATISE","san":{"b":"Smith & Son","zz":"Alpha & Omega"}}]}}}

test/fixtures/alternate-text-node.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/fixtures/alternate-text-node.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<unit>
2-
<tst>
2+
<test>
33
<case>
44
<justText>blah blah</justText>
55
</case>
@@ -17,6 +17,6 @@ asdf
1717
Alpha &amp; Omega
1818
</san>
1919
</case>
20-
</tst>
20+
</test>
2121
</unit>
2222

test/test.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -172,43 +172,52 @@ describe('xml2json', function () {
172172

173173
describe('alternateTextNode', function () {
174174

175-
var file = __dirname + '/fixtures/alternate-text-node.xml';
176-
var data = fs.readFileSync(file);
177-
it('A: defaults without the option being defined', function(done) {
175+
it('A1: defaults without the option being defined', function(done) {
176+
177+
var xml = internals.readFixture('alternate-text-node.xml');
178+
var result = parser.toJson(data, {});
179+
var json = internals.readFixture('alternate-text-node-A.json');
180+
181+
expect(result).to.equal(json);
178182

179-
var result = parser.toJson(data, {object: true});
180-
console.log(`${JSON.stringify(result, null, 2)}`)
181-
expect(result.tst.case[0].justText['$t']).to.equal('blah blah');
182-
expect(result.unit.tst.case[1].attribText['$t']).to.equal('capital');
183+
done();
183184
});
184185

185-
it('B: defaults with option as false', function(done) {
186+
it('A2: defaults with option as false', function(done) {
187+
188+
var xml = internals.readFixture('alternate-text-node.xml');
189+
var result = parser.toJson(data, {alternateTextNode: false});
190+
var json = internals.readFixture('alternate-text-node-A.json');
191+
192+
expect(result).to.equal(json);
186193

187-
var result = parser.toJson(data, {alternateTextNode: false, reversible: true});
188-
expect(result.unit.test.case[0].justText['$t']).to.equal('blah blah');
189-
expect(result.unit.test.case[1].attribText['$t']).to.equal('capital');
194+
done();
190195
});
191196

192197

193-
it('C: uses alternate text node with option as true', function(done) {
198+
it('B: uses alternate text node with option as true', function(done) {
199+
200+
var xml = internals.readFixture('alternate-text-node.xml');
201+
var result = parser.toJson(data, {alternateTextNode: true});
202+
var json = internals.readFixture('alternate-text-node-B.json');
194203

195-
var result = parser.toJson(data, {alternateTextNode: true, reversible: true});
196-
expect(result.unit.test.case[0].justText['_t']).to.equal('blah blah');
197-
expect(result.unit.test.case[1].attribText['_t']).to.equal('capital');
204+
expect(result).to.equal(json);
205+
206+
done();
198207
});
199208

200-
it('D: overrides text node with option as "xx" string', function(done) {
209+
it('C: overrides text node with option as "xx" string', function(done) {
201210

202-
var result = parser.toJson(data, {alternateTextNode: "xx", reversible: true});
203-
expect(result.unit.test.case[0].justText['xx']).to.equal('blah blah');
204-
expect(result.unit.test.case[1].attribText['xx']).to.equal('capital');
211+
var xml = internals.readFixture('alternate-text-node.xml');
212+
var result = parser.toJson(data, {alternateTextNode: "xx"});
213+
var json = internals.readFixture('alternate-text-node-C.json');
205214
});
206215

207-
it('E: double check sanatize and trim', function (done) {
216+
it('D: double check sanatize and trim', function (done) {
208217

209218
var xml = internals.readFixture('alternate-text-node.xml');
210-
var result = parser.toJson(xml, {alternateTextNode: "zz", reversible: true, sanitize: true, trim: true});
211-
var json = internals.readFixture('alternate-text-node.json');
219+
var result = parser.toJson(xml, {alternateTextNode: "zz", sanitize: true, trim: true});
220+
var json = internals.readFixture('alternate-text-node-D.json');
212221

213222
expect(result).to.equal(json);
214223

0 commit comments

Comments
 (0)