Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)
at lambda-fork/main 104 lines 3.7 kB view raw
1/* 2 * Copyright (C) 2023-2025 Yomitan Authors 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18import {describe} from 'vitest'; 19import {createAnkiTemplateRendererTest} from './fixtures/anki-template-renderer-test.js'; 20 21const test = await createAnkiTemplateRendererTest(); 22 23describe('AnkiTemplateRenderer', () => { 24 /** @type {import('template-renderer').CompositeRenderData} */ 25 const data = { 26 marker: 'test', 27 commonData: { 28 dictionaryEntry: { 29 type: 'kanji', 30 character: 'c', 31 dictionary: 'dictionary', 32 dictionaryIndex: 0, 33 dictionaryAlias: 'dictionaryAlias', 34 onyomi: [], 35 kunyomi: [], 36 tags: [], 37 stats: {}, 38 definitions: [], 39 frequencies: [], 40 }, 41 resultOutputMode: 'split', 42 cardFormat: { 43 type: 'term', 44 name: 'test', 45 deck: 'deck', 46 model: 'model', 47 fields: {}, 48 icon: 'big-circle', 49 }, 50 glossaryLayoutMode: 'default', 51 compactTags: false, 52 context: { 53 url: 'http://localhost/', 54 documentTitle: 'documentTitle', 55 query: 'query', 56 fullQuery: 'query.full', 57 sentence: { 58 text: 'sentence.query.full', 59 offset: 9, 60 }, 61 }, 62 media: void 0, 63 dictionaryStylesMap: new Map(), 64 }, 65 }; 66 const testCases = [ 67 { 68 name: 'regexMatch 1', 69 template: '{{#regexMatch "test" "gu"}}this is a test of regexMatch{{/regexMatch}}', 70 result: 'test', 71 }, 72 { 73 name: 'regexMatch 2', 74 template: '{{regexMatch "test" "gu" "this is a test of regexMatch"}}', 75 result: 'test', 76 }, 77 { 78 name: 'regexMatch 3', 79 template: '{{#if (regexMatch "test" "gu" "this is a test of regexMatch")}}true{{else}}false{{/if}}', 80 result: 'true', 81 }, 82 { 83 name: 'regexReplace 1', 84 template: '{{#regexReplace "test" "TEST" "gu"}}this is a test of regexReplace{{/regexReplace}}', 85 result: 'this is a TEST of regexReplace', 86 }, 87 { 88 name: 'regexReplace 2', 89 template: '{{regexReplace "test" "TEST" "gu" "this is a test of regexReplace"}}', 90 result: 'this is a TEST of regexReplace', 91 }, 92 { 93 name: 'regexReplace 3', 94 template: '{{#if (regexReplace "test" "" "gu" "test")}}true{{else}}false{{/if}}', 95 result: 'false', 96 }, 97 ]; 98 describe.each(testCases)('$name', ({template, result: expectedResult}) => { 99 test('Test', ({expect, ankiTemplateRenderer}) => { 100 const {result} = ankiTemplateRenderer.templateRenderer.render(template, data, 'ankiNote'); 101 expect(result).toEqual(expectedResult); 102 }); 103 }); 104});