diff options
Diffstat (limited to 'test/deinflector.test.js')
-rw-r--r-- | test/deinflector.test.js | 17 |
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(); } |