aboutsummaryrefslogtreecommitdiff
path: root/test/deinflection/test.ts
blob: 1d2f172f59e89f7c837ac27e5d9ed7e28cf51f5c (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
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);
		var result = terms.find(t => t.source == input);
		if (force)
			result = terms.find(t => t.reading == force.reading && t.writing == force.writing);

		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}`);
	});
})