aboutsummaryrefslogtreecommitdiff
path: root/test/deinflector.test.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /test/deinflector.test.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'test/deinflector.test.js')
-rw-r--r--test/deinflector.test.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/test/deinflector.test.js b/test/deinflector.test.js
index edb85833..bd538428 100644
--- a/test/deinflector.test.js
+++ b/test/deinflector.test.js
@@ -17,12 +17,23 @@
*/
import fs from 'fs';
+import {fileURLToPath} from 'node:url';
import path from 'path';
import {describe, expect, test} from 'vitest';
import {Deinflector} from '../ext/js/language/deinflector.js';
+const dirname = path.dirname(fileURLToPath(import.meta.url));
+
+/**
+ * @param {Deinflector} deinflector
+ * @param {string} source
+ * @param {string} expectedTerm
+ * @param {string} expectedRule
+ * @param {string[]|undefined} expectedReasons
+ * @returns {{has: false, reasons: null, rules: null}|{has: true, reasons: string[], rules: number}}
+ */
function hasTermReasons(deinflector, source, expectedTerm, expectedRule, expectedReasons) {
- for (const {term, reasons, rules} of deinflector.deinflect(source, source)) {
+ for (const {term, reasons, rules} of deinflector.deinflect(source)) {
if (term !== expectedTerm) { continue; }
if (typeof expectedRule !== 'undefined') {
const expectedFlags = Deinflector.rulesToRuleFlags([expectedRule]);
@@ -46,6 +57,7 @@ function hasTermReasons(deinflector, source, expectedTerm, expectedRule, expecte
}
+/** */
function testDeinflections() {
const data = [
{
@@ -915,7 +927,7 @@ function testDeinflections() {
}
];
- const deinflectionReasons = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'ext', 'data/deinflect.json')));
+ const deinflectionReasons = JSON.parse(fs.readFileSync(path.join(dirname, '..', 'ext', 'data/deinflect.json'), {encoding: 'utf8'}));
const deinflector = new Deinflector(deinflectionReasons);
describe('deinflections', () => {
@@ -939,6 +951,7 @@ function testDeinflections() {
}
+/** */
function main() {
testDeinflections();
}