-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Change default delimiter to semicolon (#64)
closes #61
- Loading branch information
1 parent
7c6a93f
commit d1221b8
Showing
6 changed files
with
148 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,72 @@ | ||
import { csvGenerateRow } from "../src/generate"; | ||
|
||
test("csv generator correctly handles custom delimiters", () => { | ||
const mockData = { | ||
id: 1, | ||
text: "Lee Perry", | ||
}; | ||
describe("csvGenerateRow", () => { | ||
|
||
expect(csvGenerateRow(mockData, ["id", "text"], ",")).toEqual( | ||
`1,"Lee Perry"` | ||
); | ||
}); | ||
test("correctly handles empty, number, and boolean values", () => { | ||
const mockData = { | ||
id: 0, | ||
one: true, | ||
two: false, | ||
empty: "", | ||
}; | ||
|
||
expect(csvGenerateRow(mockData, ["id", "one", "two", "empty"], ",")).toEqual( | ||
`0,true,false,` | ||
); | ||
}); | ||
|
||
test("correctly handles custom delimiters", () => { | ||
const mockData = { | ||
id: 1, | ||
text: "Lee Perry", | ||
}; | ||
|
||
expect(csvGenerateRow(mockData, ["id", "text"], ";")).toEqual( | ||
`1;Lee Perry` | ||
); | ||
}); | ||
|
||
test("correctly handles data with double-quotes", () => { | ||
const mockData = { | ||
id: 1, | ||
text: 'Lee "Scratch" Perry', | ||
}; | ||
expect(csvGenerateRow(mockData, ["id", "text"], ";")).toEqual( | ||
`1;"Lee ""Scratch"" Perry"` | ||
); | ||
}); | ||
|
||
test("row generator correctly handles data with double-quotes", () => { | ||
const mockData = { | ||
id: 1, | ||
text: 'Lee "Scratch" Perry', | ||
}; | ||
test("correctly handles data with carriage return / newline and whitespace", () => { | ||
const mockData = { | ||
id: 1, | ||
text: `Lee | ||
Perry `, | ||
}; | ||
expect(csvGenerateRow(mockData, ["id", "text"], ",")).toEqual( | ||
`1,"Lee | ||
Perry "` | ||
); | ||
}); | ||
|
||
test("correctly handles data containing the delimiter (semicolon)", () => { | ||
const mockData = { | ||
id: 1, | ||
text: 'Bond; James Bond', | ||
}; | ||
expect(csvGenerateRow(mockData, ["id", "text"], ";")).toEqual( | ||
`1;"Bond; James Bond"` | ||
); | ||
}); | ||
|
||
expect(csvGenerateRow(mockData, ["id", "text"], ";")).toEqual( | ||
`1;"Lee ""Scratch"" Perry"` | ||
); | ||
test("correctly handles data containing the delimiter (comma)", () => { | ||
const mockData = { | ||
id: 1, | ||
name: 'Baggins, Frodo', | ||
location: 'The Shire; Eriador', | ||
}; | ||
expect(csvGenerateRow(mockData, ["id", "name", "location"], ",")).toEqual( | ||
`1,"Baggins, Frodo",The Shire; Eriador` | ||
); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters