aboutsummaryrefslogtreecommitdiff
path: root/test/test-anki-note-builder.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-07-09 17:48:27 -0400
committerGitHub <noreply@github.com>2021-07-09 17:48:27 -0400
commit8c68fa4d9435b562ffe23df92a2b7b620a0ed78e (patch)
tree8c622fe11063b3f9694033f10e47b2ac05badccc /test/test-anki-note-builder.js
parent0d167095479822adf1ed8918e3d1a349b3a53377 (diff)
Anki text furigana parsing and {sentence-furigana} marker (#1814)
* Add support for textFurigana media * Add readingMode parameter * Implement readingMode * Add {sentence-furigana} marker * Fallback to sentence if furigana isn't available * Update test data
Diffstat (limited to 'test/test-anki-note-builder.js')
-rw-r--r--test/test-anki-note-builder.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/test/test-anki-note-builder.js b/test/test-anki-note-builder.js
index af9cd061..c7d91325 100644
--- a/test/test-anki-note-builder.js
+++ b/test/test-anki-note-builder.js
@@ -128,7 +128,7 @@ async function createVM() {
}
vm.set({TemplateRendererProxy});
- return {vm, AnkiNoteBuilder};
+ return {vm, AnkiNoteBuilder, JapaneseUtil};
}
function getFieldMarkers(type) {
@@ -160,6 +160,7 @@ function getFieldMarkers(type) {
'search-query',
'selection-text',
'sentence',
+ 'sentence-furigana',
'tags',
'url'
];
@@ -180,6 +181,7 @@ function getFieldMarkers(type) {
'search-query',
'selection-text',
'sentence',
+ 'sentence-furigana',
'stroke-count',
'tags',
'url'
@@ -189,13 +191,14 @@ function getFieldMarkers(type) {
}
}
-async function getRenderResults(dictionaryEntries, type, mode, template, AnkiNoteBuilder, write) {
+async function getRenderResults(dictionaryEntries, type, mode, template, AnkiNoteBuilder, JapaneseUtil, write) {
const markers = getFieldMarkers(type);
const fields = [];
for (const marker of markers) {
fields.push([marker, `{${marker}}`]);
}
+ const japaneseUtil = new JapaneseUtil(null);
const clozePrefix = 'cloze-prefix';
const clozeSuffix = 'cloze-suffix';
const results = [];
@@ -211,7 +214,7 @@ async function getRenderResults(dictionaryEntries, type, mode, template, AnkiNot
}
break;
}
- const ankiNoteBuilder = new AnkiNoteBuilder();
+ const ankiNoteBuilder = new AnkiNoteBuilder({japaneseUtil});
const context = {
url: 'url:',
sentence: {
@@ -250,7 +253,7 @@ async function getRenderResults(dictionaryEntries, type, mode, template, AnkiNot
async function main() {
const write = (process.argv[2] === '--write');
- const {vm, AnkiNoteBuilder} = await createVM();
+ const {vm, AnkiNoteBuilder, JapaneseUtil} = await createVM();
const testInputsFilePath = path.join(__dirname, 'data', 'translator-test-inputs.json');
const {optionsPresets, tests} = JSON.parse(fs.readFileSync(testInputsFilePath, {encoding: 'utf8'}));
@@ -270,7 +273,7 @@ async function main() {
const {name, mode, text} = test;
const options = vm.buildOptions(optionsPresets, test.options);
const {dictionaryEntries} = clone(await vm.translator.findTerms(mode, text, options));
- const results = mode !== 'simple' ? clone(await getRenderResults(dictionaryEntries, 'terms', mode, template, AnkiNoteBuilder, write)) : null;
+ const results = mode !== 'simple' ? clone(await getRenderResults(dictionaryEntries, 'terms', mode, template, AnkiNoteBuilder, JapaneseUtil, write)) : null;
actualResults1.push({name, results});
if (!write) {
assert.deepStrictEqual(results, expected1.results);
@@ -282,7 +285,7 @@ async function main() {
const {name, text} = test;
const options = vm.buildOptions(optionsPresets, test.options);
const dictionaryEntries = clone(await vm.translator.findKanji(text, options));
- const results = clone(await getRenderResults(dictionaryEntries, 'kanji', null, template, AnkiNoteBuilder, write));
+ const results = clone(await getRenderResults(dictionaryEntries, 'kanji', null, template, AnkiNoteBuilder, JapaneseUtil, write));
actualResults1.push({name, results});
if (!write) {
assert.deepStrictEqual(results, expected1.results);