Skip to content

Commit b9a7b93

Browse files
authored
Initial work on unit tests, more coming soon
1 parent 4251a49 commit b9a7b93

File tree

8 files changed

+50
-6
lines changed

8 files changed

+50
-6
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"cli"
4040
],
4141
"dependencies": {
42-
"deeks": "2.4.0",
42+
"deeks": "2.4.1",
4343
"doc-path": "3.0.0"
4444
},
4545
"devDependencies": {

test/config/testCsvFilesList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const fs = require('fs'),
4040
{key: 'emptyLastFieldValue', file: '../data/csv/emptyLastFieldValue.csv'},
4141
{key: 'emptyLastFieldValueNoEol', file: '../data/csv/emptyLastFieldValueNoEol.csv'},
4242
{key: 'lastCharFieldDelimiter', file: '../data/csv/lastCharFieldDelimiter.csv'},
43-
{key: 'nativeMapMethod', file: '../data/csv/nativeMapMethod.csv'}
43+
{key: 'nativeMapMethod', file: '../data/csv/nativeMapMethod.csv'},
44+
{key: 'nestedDotKeys', file: '../data/csv/nestedDotKeys.csv'}
4445
];
4546

4647
function readCsvFile(filePath) {

test/config/testJsonFilesList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ module.exports = {
3030
firstColumnWrapCRLF: require('../data/json/firstColumnWrapCRLF.json'),
3131
emptyLastFieldValue: require('../data/json/emptyLastFieldValue.json'),
3232
emptyLastFieldValueNoEol: require('../data/json/emptyLastFieldValueNoEol.json'),
33-
nativeMapMethod: require('../data/json/nativeMapMethod.json')
33+
nativeMapMethod: require('../data/json/nativeMapMethod.json'),
34+
nestedDotKeys: require('../data/json/nestedDotKeys.json')
3435
};

test/csv2json.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ function runTests(jsonTestData, csvTestData) {
198198
done();
199199
});
200200
});
201+
202+
// Test case for #184
203+
it('should properly convert keys with escaped/nested dots in them', (done) => {
204+
converter.csv2json(csvTestData.nestedDotKeys, (err, json) => {
205+
if (err) done(err);
206+
json.should.deepEqual(jsonTestData.nestedDotKeys);
207+
done();
208+
});
209+
});
201210
});
202211

203212
describe('Error Handling', () => {

test/data/csv/nestedDotKeys.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a\.a,a\.b.c\.d,a\.b.c,a\.b.c\.f,a.a,a.b,a.b\.c\.d,a.f.g\.h,a.f.g\.h\.k,a.f.h.l\.m\.n\.o\.p
2+
a,4,5,6,1,2,32,3,5,qrstuv

test/data/json/nestedDotKeys.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"a.a": "a",
4+
"a.b": {
5+
"c.d": 4,
6+
"c": 5,
7+
"c.f": 6
8+
},
9+
"a": {
10+
"a": 1,
11+
"b": 2,
12+
"b.c.d": 32,
13+
"f": {
14+
"g.h": 3,
15+
"g.h.k": 5,
16+
"h": {
17+
"l.m.n.o.p": "qrstuv"
18+
}
19+
}
20+
}
21+
}
22+
]

test/json2csv.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ function runTests(jsonTestData, csvTestData) {
145145
done();
146146
});
147147
});
148+
149+
// Test case for #184
150+
it('should properly handle keys with nested dots in them', (done) => {
151+
converter.json2csv(jsonTestData.nestedDotKeys, (err, csv) => {
152+
if (err) done(err);
153+
csv.should.equal(csvTestData.nestedDotKeys);
154+
done();
155+
});
156+
});
148157
});
149158

150159
describe('Error Handling', () => {

0 commit comments

Comments
 (0)