aboutsummaryrefslogtreecommitdiff
path: root/test/deinflection/test.ts
blob: 291ed83f256985ba0e8b136cd755b3114a831b50 (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
import cases from "./cases.ts";
import { core } from '../base.ts';
import { TokenTag } from "../../search/tags.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");

		let tag: TokenTag;
		for (tag of mustHave)
			if (!result.tags.includes(tag))
				throw new Error(`Deconjugation doesn't include required tag ${tag}`);

		for (tag of mustNotHave)
			if (result.tags.includes(tag))
				throw new Error(`Deconjugation includes unallowed tag ${tag}`);

		// console.log(result.writing + " + " + result.tags.filter(tag => tag.startsWith("infl:") && !tag.startsWith("infl:reason:")).join(" + "));
	});
})