Skip to main content
Module

x/csv/csv_spectrum_test.ts

Streaming API for reading and writing CSV for https://deno.land/
Latest
File
import { readCSVObjects } from "./mod.ts";import { assertEquals } from "./dev_deps.ts";
for await (const file of Deno.readDir("./third_party/csv-spectrum/csvs")) { const csvFilePath = "./third_party/csv-spectrum/csvs/" + file.name; const jsonFilePath = csvFilePath .replace(/\/csvs\//, "/json/") .replace(/\.csv$/, ".json");
Deno.test({ name: csvFilePath, async fn() { const csvFile = await Deno.open(csvFilePath); const expectedJSON = JSON.parse(await Deno.readTextFile(jsonFilePath)); const actualJSON = []; const options = { lineSeparator: csvFilePath.includes("crlf") ? "\r\n" : "\n", };
for await (const row of readCSVObjects(csvFile, options)) { actualJSON.push(row); }
assertEquals(actualJSON, expectedJSON);
csvFile.close(); }, });}