From 8b206e4d0458892d30661353bfb95c6dcefe5b67 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 14 May 2022 18:45:18 -0400 Subject: [PATCH] Update structured content tests (#2134) --- test/data/anki-note-builder-test-results.json | 35 ++++ .../valid-dictionary1/term_bank_1.json | 9 ++ test/data/translator-test-inputs.json | 7 + .../translator-test-results-note-data1.json | 150 ++++++++++++++++++ test/data/translator-test-results.json | 111 +++++++++++++ test/test-anki-note-builder.js | 3 +- test/test-database.js | 6 +- 7 files changed, 317 insertions(+), 4 deletions(-) diff --git a/test/data/anki-note-builder-test-results.json b/test/data/anki-note-builder-test-results.json index 816c1dab..b752e878 100644 --- a/test/data/anki-note-builder-test-results.json +++ b/test/data/anki-note-builder-test-results.json @@ -2711,5 +2711,40 @@ "url": "url:" } ] + }, + { + "name": "Structured content test", + "results": [ + { + "audio": "", + "clipboard-image": "", + "clipboard-text": "", + "cloze-body": "構造", + "cloze-prefix": "cloze-prefix", + "cloze-suffix": "cloze-suffix", + "conjugation": "", + "dictionary": "Test Dictionary 2", + "document-title": "title", + "expression": "構造", + "frequencies": "", + "furigana": "構造こうぞう", + "furigana-plain": "構造[こうぞう]", + "glossary": "
(n, Test Dictionary 2)
", + "glossary-brief": "
", + "glossary-no-dictionary": "
(n)
", + "part-of-speech": "Noun", + "pitch-accents": "No pitch accent data", + "pitch-accent-graphs": "No pitch accent data", + "pitch-accent-positions": "No pitch accent data", + "reading": "こうぞう", + "screenshot": "", + "search-query": "fullQuery", + "selection-text": "", + "sentence": "cloze-prefix構造cloze-suffix", + "sentence-furigana": "cloze-prefix構造cloze-suffix", + "tags": "n", + "url": "url:" + } + ] } ] \ No newline at end of file diff --git a/test/data/dictionaries/valid-dictionary1/term_bank_1.json b/test/data/dictionaries/valid-dictionary1/term_bank_1.json index 114ec88b..c8a83c9a 100644 --- a/test/data/dictionaries/valid-dictionary1/term_bank_1.json +++ b/test/data/dictionaries/valid-dictionary1/term_bank_1.json @@ -307,5 +307,14 @@ ]} ], 100, "P E1" + ], + [ + "構造", "こうぞう", "n", "n", 35, + [ + "kouzou definition 1", + {"type": "structured-content", "content": "kouzou definition 2"}, + {"type": "structured-content", "content": "kouzou definition 3 (構造)"} + ], + 101, "P E1" ] ] \ No newline at end of file diff --git a/test/data/translator-test-inputs.json b/test/data/translator-test-inputs.json index daee53a4..f6b5ea67 100644 --- a/test/data/translator-test-inputs.json +++ b/test/data/translator-test-inputs.json @@ -328,6 +328,13 @@ "mode": "split", "text": "土木工事", "options": "default" + }, + { + "name": "Structured content test", + "func": "findTerms", + "mode": "split", + "text": "構造", + "options": "default" } ] } \ No newline at end of file diff --git a/test/data/translator-test-results-note-data1.json b/test/data/translator-test-results-note-data1.json index a297f587..d686563c 100644 --- a/test/data/translator-test-results-note-data1.json +++ b/test/data/translator-test-results-note-data1.json @@ -28213,5 +28213,155 @@ "media": {} } ] + }, + { + "name": "Structured content test", + "noteDataList": [ + { + "marker": "{marker}", + "definition": { + "type": "term", + "id": 21, + "source": "構造", + "rawSource": "構造", + "sourceTerm": "構造", + "reasons": [], + "score": 35, + "isPrimary": true, + "sequence": 101, + "dictionary": "Test Dictionary 2", + "dictionaryOrder": { + "index": 0, + "priority": 0 + }, + "dictionaryNames": [ + "Test Dictionary 2" + ], + "expression": "構造", + "reading": "こうぞう", + "expressions": [ + { + "sourceTerm": "構造", + "expression": "構造", + "reading": "こうぞう", + "termTags": [ + { + "name": "E1", + "category": "default", + "notes": "example tag 1", + "order": 0, + "score": 0, + "dictionary": "Test Dictionary 2", + "redundant": false + }, + { + "name": "P", + "category": "popular", + "notes": "popular term", + "order": 0, + "score": 0, + "dictionary": "Test Dictionary 2", + "redundant": false + } + ], + "frequencies": [], + "pitches": [], + "furiganaSegments": [ + { + "text": "構造", + "furigana": "こうぞう" + } + ], + "termFrequency": "normal", + "wordClasses": [ + "n" + ] + } + ], + "glossary": [ + "kouzou definition 1", + { + "type": "structured-content", + "content": "kouzou definition 2" + }, + { + "type": "structured-content", + "content": "kouzou definition 3 (構造)" + } + ], + "definitionTags": [ + { + "name": "n", + "category": "partOfSpeech", + "notes": "noun", + "order": 0, + "score": 0, + "dictionary": "Test Dictionary 2", + "redundant": false + } + ], + "termTags": [ + { + "name": "E1", + "category": "default", + "notes": "example tag 1", + "order": 0, + "score": 0, + "dictionary": "Test Dictionary 2", + "redundant": false + }, + { + "name": "P", + "category": "popular", + "notes": "popular term", + "order": 0, + "score": 0, + "dictionary": "Test Dictionary 2", + "redundant": false + } + ], + "frequencies": [], + "pitches": [], + "sourceTermExactMatchCount": 1, + "url": "url:", + "cloze": { + "sentence": "", + "prefix": "", + "body": "", + "suffix": "" + }, + "furiganaSegments": [ + { + "text": "構造", + "furigana": "こうぞう" + } + ] + }, + "glossaryLayoutMode": "default", + "compactTags": false, + "group": false, + "merge": false, + "modeTermKanji": false, + "modeTermKana": false, + "modeKanji": false, + "compactGlossaries": false, + "uniqueExpressions": [ + "構造" + ], + "uniqueReadings": [ + "こうぞう" + ], + "pitches": [], + "pitchCount": 0, + "context": { + "query": "query", + "fullQuery": "fullQuery", + "document": { + "title": "title" + } + }, + "media": {} + } + ] } ] \ No newline at end of file diff --git a/test/data/translator-test-results.json b/test/data/translator-test-results.json index cf2ced0a..98db0ef4 100644 --- a/test/data/translator-test-results.json +++ b/test/data/translator-test-results.json @@ -16117,5 +16117,116 @@ "frequencies": [] } ] + }, + { + "name": "Structured content test", + "originalTextLength": 2, + "dictionaryEntries": [ + { + "type": "term", + "isPrimary": true, + "inflections": [], + "score": 35, + "frequencyOrder": 0, + "dictionaryIndex": 0, + "dictionaryPriority": 0, + "sourceTermExactMatchCount": 1, + "maxTransformedTextLength": 2, + "headwords": [ + { + "index": 0, + "term": "構造", + "reading": "こうぞう", + "sources": [ + { + "originalText": "構造", + "transformedText": "構造", + "deinflectedText": "構造", + "matchType": "exact", + "matchSource": "term", + "isPrimary": true + } + ], + "tags": [ + { + "name": "E1", + "category": "default", + "order": 0, + "score": 0, + "content": [ + "example tag 1" + ], + "dictionaries": [ + "Test Dictionary 2" + ], + "redundant": false + }, + { + "name": "P", + "category": "popular", + "order": 0, + "score": 0, + "content": [ + "popular term" + ], + "dictionaries": [ + "Test Dictionary 2" + ], + "redundant": false + } + ], + "wordClasses": [ + "n" + ] + } + ], + "definitions": [ + { + "index": 0, + "headwordIndices": [ + 0 + ], + "dictionary": "Test Dictionary 2", + "dictionaryIndex": 0, + "dictionaryPriority": 0, + "id": 21, + "score": 35, + "frequencyOrder": 0, + "sequences": [ + 101 + ], + "isPrimary": true, + "tags": [ + { + "name": "n", + "category": "partOfSpeech", + "order": 0, + "score": 0, + "content": [ + "noun" + ], + "dictionaries": [ + "Test Dictionary 2" + ], + "redundant": false + } + ], + "entries": [ + "kouzou definition 1", + { + "type": "structured-content", + "content": "kouzou definition 2" + }, + { + "type": "structured-content", + "content": "kouzou definition 3 (構造)" + } + ] + } + ], + "pronunciations": [], + "frequencies": [] + } + ] } ] \ No newline at end of file diff --git a/test/test-anki-note-builder.js b/test/test-anki-note-builder.js index 3da67955..21aa89bc 100644 --- a/test/test-anki-note-builder.js +++ b/test/test-anki-note-builder.js @@ -34,7 +34,8 @@ async function createVM() { const vm = new TranslatorVM({ Node, NodeFilter, - document + document, + location: new URL('https://yomichan.test/') }); const dictionaryDirectory = path.join(__dirname, 'data', 'dictionaries', 'valid-dictionary1'); diff --git a/test/test-database.js b/test/test-database.js index ef2c6b78..6124f42e 100644 --- a/test/test-database.js +++ b/test/test-database.js @@ -155,7 +155,7 @@ async function testDatabase1() { media: {total: 4}, tagMeta: {total: 15}, termMeta: {total: 38, freq: 31, pitch: 7}, - terms: {total: 20} + terms: {total: 21} } }; @@ -182,8 +182,8 @@ async function testDatabase1() { true ); vm.assert.deepStrictEqual(counts, { - counts: [{kanji: 2, kanjiMeta: 6, terms: 20, termMeta: 38, tagMeta: 15, media: 4}], - total: {kanji: 2, kanjiMeta: 6, terms: 20, termMeta: 38, tagMeta: 15, media: 4} + counts: [{kanji: 2, kanjiMeta: 6, terms: 21, termMeta: 38, tagMeta: 15, media: 4}], + total: {kanji: 2, kanjiMeta: 6, terms: 21, termMeta: 38, tagMeta: 15, media: 4} }); // Test find* functions