Skip to content

Commit

Permalink
Add test cases for header with quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdudabeecoded committed Aug 2, 2024
1 parent fd6ee99 commit 7dfd212
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"name": "json-2-csv",
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.",
"version": "5.5.4",
"version": "5.5.5",
"homepage": "https://mrodrig.github.io/json-2-csv",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions test/config/testCsvFilesList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const csvFileConfig = [
{key: 'nestedMissingField', file: '../data/csv/nestedMissingField.csv'},
{key: 'comma', file: '../data/csv/comma.csv'},
{key: 'quotes', file: '../data/csv/quotes.csv'},
{key: 'quotesHeader', file: '../data/csv/quotesHeader.csv'},
{key: 'quotesAndCommas', file: '../data/csv/quotesAndCommas.csv'},
{key: 'eol', file: '../data/csv/eol.csv'},
{key: 'assortedValues', file: '../data/csv/assortedValues.csv'},
Expand Down
1 change: 1 addition & 0 deletions test/config/testJsonFilesList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default {
nestedMissingField: require('../data/json/nestedMissingField'),
comma: require('../data/json/comma'),
quotes: require('../data/json/quotes'),
quotesHeader: require('../data/json/quotesHeader'),
quotesAndCommas: require('../data/json/quotesAndCommas'),
eol: require('../data/json/eol'),
assortedValues: require('../data/json/assortedValues'),
Expand Down
5 changes: 5 additions & 0 deletions test/csv2json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export function runTests() {
assert.deepEqual(json, jsonTestData.quotes);
});

it('should convert csv containing a header with quotes to json', () => {
const json = csv2json(csvTestData.quotesHeader);
assert.deepEqual(json, jsonTestData.quotesHeader);
});

it('should convert csv containing quotes and commas to json', () => {
const json = csv2json(csvTestData.quotesAndCommas);
assert.deepEqual(json, jsonTestData.quotesAndCommas);
Expand Down
4 changes: 4 additions & 0 deletions test/data/csv/quotesHeader.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"author
(original)",quote
Carol Burnett,"""Only I can change my life. No one can do it for me."""
Professor,"Please submit all assignment names inside ""quotation"" marks (""), like ""Homework 7"""
10 changes: 10 additions & 0 deletions test/data/json/quotesHeader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"author\n(original)": "Carol Burnett",
"quote": "\"Only I can change my life. No one can do it for me.\""
},
{
"author\n(original)": "Professor",
"quote": "Please submit all assignment names inside \"quotation\" marks (\"), like \"Homework 7\""
}
]
5 changes: 5 additions & 0 deletions test/json2csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export function runTests() {
assert.equal(csv, csvTestData.quotes);
});

it('should convert a document with header containing quotes to csv', () => {
const csv = json2csv(jsonTestData.quotesHeader);
assert.equal(csv, csvTestData.quotesHeader);
});

it('should convert a document with fields containing quotes and commas to csv', () => {
const csv = json2csv(jsonTestData.quotesAndCommas);
assert.equal(csv, csvTestData.quotesAndCommas);
Expand Down

0 comments on commit 7dfd212

Please sign in to comment.