diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-01-28 07:22:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-28 12:22:47 +0000 |
commit | acc013a1a8051d34322f0f5f91d7bdecc0a18843 (patch) | |
tree | 601344b2f047f395548ddfb16a83319af10464f9 /test | |
parent | a51f1ab2dc675a49bfeeb08cc24b97eb8d888e4a (diff) |
JapaneseUtil refactor (#555)
* Copy functions from JapaneseUtil
* Remove JapaneseUtil
* Update usages of JapaneseUtil functions
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/translator-test.js | 6 | ||||
-rw-r--r-- | test/japanese-util.test.js | 12 | ||||
-rw-r--r-- | test/utilities/anki.js | 4 |
3 files changed, 8 insertions, 14 deletions
diff --git a/test/fixtures/translator-test.js b/test/fixtures/translator-test.js index f162972d..6562931c 100644 --- a/test/fixtures/translator-test.js +++ b/test/fixtures/translator-test.js @@ -26,7 +26,6 @@ import {createDictionaryArchive} from '../../dev/util.js'; import {AnkiNoteDataCreator} from '../../ext/js/data/sandbox/anki-note-data-creator.js'; import {DictionaryDatabase} from '../../ext/js/dictionary/dictionary-database.js'; import {DictionaryImporter} from '../../ext/js/dictionary/dictionary-importer.js'; -import {JapaneseUtil} from '../../ext/js/language/sandbox/japanese-util.js'; import {Translator} from '../../ext/js/language/translator.js'; import {chrome, fetch} from '../mocks/common.js'; import {DictionaryImporterMediaLoader} from '../mocks/dictionary-importer-media-loader.js'; @@ -65,14 +64,13 @@ async function createTranslatorContext(dictionaryDirectory, dictionaryName) { expect(errors.length).toEqual(0); // Setup translator - const japaneseUtil = new JapaneseUtil(null); - const translator = new Translator({japaneseUtil, database: dictionaryDatabase}); + const translator = new Translator({database: dictionaryDatabase}); /** @type {import('deinflector').ReasonsRaw} */ const deinflectionReasons = parseJson(readFileSync(deinflectionReasonsPath, {encoding: 'utf8'})); translator.prepare(deinflectionReasons); // Assign properties - const ankiNoteDataCreator = new AnkiNoteDataCreator(japaneseUtil); + const ankiNoteDataCreator = new AnkiNoteDataCreator(); return {translator, ankiNoteDataCreator}; } diff --git a/test/japanese-util.test.js b/test/japanese-util.test.js index ab14f209..d7b05c3e 100644 --- a/test/japanese-util.test.js +++ b/test/japanese-util.test.js @@ -18,10 +18,8 @@ import {describe, expect, test} from 'vitest'; import {TextSourceMap} from '../ext/js/general/text-source-map.js'; -import {JapaneseUtil} from '../ext/js/language/sandbox/japanese-util.js'; -import * as wanakana from '../ext/lib/wanakana.js'; - -const jp = new JapaneseUtil(wanakana); +import * as jpw from '../ext/js/language/japanese-wanakana.js'; +import * as jp from '../ext/js/language/japanese.js'; /** */ function testIsCodePointKanji() { @@ -199,7 +197,7 @@ function testConvertToRomaji() { ]; test.each(data)('%s -> %o', (string, expected) => { - expect(jp.convertToRomaji(string)).toStrictEqual(expected); + expect(jpw.convertToRomaji(string)).toStrictEqual(expected); }); }); } @@ -268,8 +266,8 @@ function testConvertAlphabeticToKana() { for (const [string, expected, expectedSourceMapping] of data) { test(`${string} -> ${string}${typeof expectedSourceMapping !== 'undefined' ? ', ' + JSON.stringify(expectedSourceMapping) : ''}`, () => { const sourceMap = new TextSourceMap(string); - const actual1 = jp.convertAlphabeticToKana(string, null); - const actual2 = jp.convertAlphabeticToKana(string, sourceMap); + const actual1 = jpw.convertAlphabeticToKana(string, null); + const actual2 = jpw.convertAlphabeticToKana(string, sourceMap); expect(actual1).toStrictEqual(expected); expect(actual2).toStrictEqual(expected); if (typeof expectedSourceMapping !== 'undefined') { diff --git a/test/utilities/anki.js b/test/utilities/anki.js index 322acb0d..e30d578f 100644 --- a/test/utilities/anki.js +++ b/test/utilities/anki.js @@ -16,7 +16,6 @@ */ import {AnkiNoteBuilder} from '../../ext/js/data/anki-note-builder.js'; -import {JapaneseUtil} from '../../ext/js/language/sandbox/japanese-util.js'; import {AnkiTemplateRenderer} from '../../ext/js/templates/sandbox/anki-template-renderer.js'; /** @@ -130,7 +129,6 @@ export async function getTemplateRenderResults(dictionaryEntries, type, mode, te const ankiTemplateRenderer = new AnkiTemplateRenderer(); await ankiTemplateRenderer.prepare(); - const japaneseUtil = new JapaneseUtil(null); const clozePrefix = 'cloze-prefix'; const clozeSuffix = 'cloze-suffix'; const results = []; @@ -146,7 +144,7 @@ export async function getTemplateRenderResults(dictionaryEntries, type, mode, te } break; } - const ankiNoteBuilder = new AnkiNoteBuilder(japaneseUtil, ankiTemplateRenderer.templateRenderer); + const ankiNoteBuilder = new AnkiNoteBuilder(ankiTemplateRenderer.templateRenderer); const context = { url: 'url:', sentence: { |