diff --git a/01-parse-a-csv-file/step3.js b/01-parse-a-csv-file/step3.js index 057556f..6a88079 100644 --- a/01-parse-a-csv-file/step3.js +++ b/01-parse-a-csv-file/step3.js @@ -20,7 +20,7 @@ spectrum(async (err, samples) => { const ours = simple_parse(raw_csv); if(!equal(ours, good)) { - console.error("EXPECTED", good, "\nGOT", ours); + console.error("FAIL EXPECTED", good, "\nGOT", ours); process.exit(1); } } diff --git a/01-parse-a-csv-file/step4.js b/01-parse-a-csv-file/step4.js index e354cc4..d9c6b48 100644 --- a/01-parse-a-csv-file/step4.js +++ b/01-parse-a-csv-file/step4.js @@ -13,25 +13,21 @@ const simple_parse = (raw_csv) => { return result; } -test('spectrum samples match', async t => { - const samples = await new Promise((res, rej) => { - spectrum((err, samples) => res(samples)); - }); - - for(let sample of samples) { - const raw_csv = sample.csv.toString(); - const good = []; +test('failing spectrum samples match', async t => { + spectrum(async (err, samples) => { + for(let sample of samples) { + const raw_csv = sample.csv.toString(); + const ours = simple_parse(raw_csv); - const count = await new Promise((res, rej) => { parseString(raw_csv) - .on('error', rej()) + .on('error', t.fail()) .on('data', row => good.push(row)) - .on('end', rowCount => res(rowCount)); - }); - - const ours = simple_parse(raw_csv); - - t.is(ours.length, count); - t.is(ours, good); - } + .on('end', rowCount => { + if(!equal(ours, good)) { + console.error("FAIL EXPECTED", good, "\nGOT", ours); + process.exit(1); + } + }); + } + }); }) diff --git a/01-parse-a-csv-file/step5.js b/01-parse-a-csv-file/step5.js new file mode 100644 index 0000000..bae8e59 --- /dev/null +++ b/01-parse-a-csv-file/step5.js @@ -0,0 +1,36 @@ +import spectrum from "csv-spectrum"; +import { parseString } from "fast-csv"; +import test from "ava"; + +const simple_parse = (raw_csv) => { + const rows = raw_csv.split("\n"); + const result = []; + + for(let row of rows) { + result.push(row.split(',')); + } + + return result; +} + +test('spectrum samples match', async t => { + const samples = await new Promise((res, rej) => { + spectrum((err, samples) => res(samples)); + }); + + for(let sample of samples) { + const raw_csv = sample.csv.toString(); + const good = []; + + const count = await new Promise((res, rej) => { + parseString(raw_csv) + .on('error', err => rej(err)) + .on('data', row => good.push(row)) + .on('end', rowCount => res(rowCount)); + }); + + const ours = simple_parse(raw_csv); + + t.is(ours, good); + } +})