pronoun-monster/tests/data-test.js
2023-03-16 00:34:58 -05:00

62 lines
1.4 KiB
JavaScript

import fs from "fs";
import test from "ava";
import fetchData, {
splitNewLines,
cleanupArrayOfStrings,
stringCsvToDataObject,
} from "../data.js";
test("splitNewLines", (t) => {
const result = splitNewLines(`foo\nbar`);
t.deepEqual(result, ["foo", "bar"]);
});
test("cleanupArrayOfStrings", (t) => {
const result = cleanupArrayOfStrings(["", " foo", "bar ", ""]);
t.deepEqual(result, ["foo", "bar"]);
});
test("clean an array made from a string of new lines", (t) => {
const result = cleanupArrayOfStrings(
splitNewLines(`
foo
bar
`)
);
t.deepEqual(result, ["foo", "bar"]);
});
test("stringCsvToDataObject", (t) => {
const result = stringCsvToDataObject("they,them,them, their,themself");
t.deepEqual(result, {
nominative: "they",
accusative: "them",
pronominalPossessive: "them",
predicativePossessive: "their",
reflexive: "themself",
});
});
test("stringCsvToDataObject with missing pronominalPossessive", (t) => {
const result = stringCsvToDataObject("they,them,,their,themself");
t.deepEqual(result, {
nominative: "they",
accusative: "them",
pronominalPossessive: "them",
predicativePossessive: "their",
reflexive: "themself",
});
});
test("database.csv loads into array of valid data", (t) => {
const data = fetchData();
t.truthy(Array.isArray(data));
t.is(typeof data[0], "object");
t.is(typeof data[0].nominative, "string");
});