blob: fac757ea77e530cec4d097c6135363759759df3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
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}`);
});
})
|