import cases from "./cases.ts"; import { core } from '../base.ts'; import { Tag, TokenTag } from "../../search/tags.ts"; import { recursiveValues } from "../../util/object.ts"; cases.forEach(({ input, mustHave, mustNotHave, force }) => { Deno.test(`deinflection - ${input}`, async () => { var terms = await core.search.terms(input); if (terms.length == 0) throw new Error("No parsed terms for input"); // console.log(terms); terms = terms.filter(t => t.source == input); if (force) terms = terms.filter(t => t.reading == force.reading && t.writing == force.writing); var result = terms[0]; if (!result) throw new Error("No deconjugation found for input"); function bail(msg: string) { console.log(` wanted tags: ${mustHave.join(" + ")}`); console.log(`unwanted tags: ${mustNotHave.join(" + ")}`); console.log(`actual result: ${result.writing} + ${result.tags.filter(tag => recursiveValues(Tag.Inflection).includes(tag) && !recursiveValues(Tag.Inflection.Reason).includes(tag)).join(" + ")}`); throw new Error(msg); } let tag: TokenTag; for (tag of mustHave) if (!result.tags.includes(tag)) return bail(`Deconjugation doesn't include required tag ${tag}`); for (tag of mustNotHave) if (result.tags.includes(tag)) return bail(`Deconjugation includes unallowed tag ${tag}`); }); })