parent
afd39a1a3c
commit
406ef1c5f8
@ -1,8 +1,13 @@ |
|||||||
import spectrum from "csv-spectrum"; |
import spectrum from "csv-spectrum"; |
||||||
import csv from "neat-csv"; |
import csv from "neat-csv"; |
||||||
|
|
||||||
spectrum(async (err, data) => { |
spectrum(async (err, samples) => { |
||||||
for(let sample of data) { |
|
||||||
console.log(await csv(sample.csv.toString())); |
for(let sample of samples) { |
||||||
|
const raw_csv = sample.csv.toString(); |
||||||
|
console.log("RAW CSV:\n", raw_csv); |
||||||
|
|
||||||
|
const parsed = await csv(raw_csv); |
||||||
|
console.log("PARSED:\n", parsed); |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
@ -0,0 +1,28 @@ |
|||||||
|
import spectrum from "csv-spectrum"; |
||||||
|
|
||||||
|
/* |
||||||
|
* A naive CVS parser to start comparing with the existing neat-csv |
||||||
|
* parser. This wrong for many CSV inputs, but you'll take this and |
||||||
|
* work to make it behave as well as the neat-csv parser. |
||||||
|
*/ |
||||||
|
const simple_parse = (raw_csv) => { |
||||||
|
const rows = raw_csv.split("\n"); |
||||||
|
const result = []; |
||||||
|
|
||||||
|
for(let row of rows) { |
||||||
|
result.push(row.split(',')); |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
spectrum(async (err, samples) => { |
||||||
|
for(let sample of samples) { |
||||||
|
const raw_csv = sample.csv.toString(); |
||||||
|
console.log("RAW CSV:\n", raw_csv); |
||||||
|
|
||||||
|
const parsed = await simple_parse(raw_csv); |
||||||
|
console.log("PARSED:\n", parsed); |
||||||
|
} |
||||||
|
}); |
@ -0,0 +1,27 @@ |
|||||||
|
import spectrum from "csv-spectrum"; |
||||||
|
import csv from "neat-csv"; |
||||||
|
import equal from "deep-equal"; |
||||||
|
|
||||||
|
const simple_parse = (raw_csv) => { |
||||||
|
const rows = raw_csv.split("\n"); |
||||||
|
const result = []; |
||||||
|
|
||||||
|
for(let row of rows) { |
||||||
|
result.push(row.split(',')); |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
spectrum(async (err, samples) => { |
||||||
|
for(let sample of samples) { |
||||||
|
const raw_csv = sample.csv.toString(); |
||||||
|
const good = await csv(raw_csv); |
||||||
|
const ours = await simple_parse(raw_csv); |
||||||
|
|
||||||
|
if(!equal(ours, good)) { |
||||||
|
console.error("EXPECTED", good, "\nGOT", ours); |
||||||
|
process.exit(1); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
Loading…
Reference in new issue