generated from nhcarrigan/template
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
/* eslint-disable max-nested-callbacks -- Not sure how to better optimise this. */
|
||||
|
||||
import compare from "string-comparison";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { phrases } from "../src/config/phrases.ts";
|
||||
|
||||
describe("phrases", () => {
|
||||
it("should have enough phrases", () => {
|
||||
expect.assertions(1);
|
||||
expect(phrases.length, "less than 100 phrases").toBeGreaterThan(100);
|
||||
});
|
||||
|
||||
it.each(phrases)(`%s should be unique`, (phrase) => {
|
||||
expect.assertions(1);
|
||||
const filtered = phrases.filter((p) => {
|
||||
return p !== phrase;
|
||||
}).map((line) => {
|
||||
return line.
|
||||
replaceAll("{{ mommy }}", "").
|
||||
replaceAll("{{ name }}", "");
|
||||
});
|
||||
|
||||
const matches = compare.levenshtein.sortMatch(phrase.
|
||||
replaceAll("{{ mommy }}", "").
|
||||
replaceAll("{{ name }}", ""), filtered);
|
||||
const closest = matches.reverse()[0];
|
||||
expect(closest?.rating, `${phrase} is not unique! Matches ${closest?.member}`).toBeLessThan(0.8);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user