From 576dece97e6546aea774d1bac4a05b7854c512a4 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 5 Feb 2024 06:16:00 -0500 Subject: Reduce repeated anki field marker code (#632) * Unify repeated code for getting anki field markers * Throw because type safety exists * Simplify * Update order * Update test data --- test/data/anki-note-builder-test-results.json | 96 +++++++++++++++++++++++++ test/dictionary-data.test.js | 4 +- test/dictionary-data.write.js | 4 +- test/utilities/anki.js | 100 +++++--------------------- 4 files changed, 116 insertions(+), 88 deletions(-) (limited to 'test') diff --git a/test/data/anki-note-builder-test-results.json b/test/data/anki-note-builder-test-results.json index 364c4ee9..8dbe27ee 100644 --- a/test/data/anki-note-builder-test-results.json +++ b/test/data/anki-note-builder-test-results.json @@ -93,6 +93,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -128,6 +129,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -168,6 +170,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -203,6 +206,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -238,6 +242,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -273,6 +278,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -308,6 +314,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -343,6 +350,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -383,6 +391,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -418,6 +427,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -453,6 +463,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -488,6 +499,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -523,6 +535,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -558,6 +571,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -593,6 +607,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -628,6 +643,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -663,6 +679,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -698,6 +715,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -738,6 +756,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "がぞう", "screenshot": "", @@ -778,6 +797,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -818,6 +838,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -858,6 +879,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -893,6 +915,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -933,6 +956,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -968,6 +992,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -1008,6 +1033,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -1043,6 +1069,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -1078,6 +1105,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -1113,6 +1141,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -1153,6 +1182,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -1188,6 +1218,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -1223,6 +1254,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -1258,6 +1290,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -1298,6 +1331,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "がぞう", "screenshot": "", @@ -1350,6 +1384,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -1385,6 +1420,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -1420,6 +1456,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -1455,6 +1492,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -1490,6 +1528,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -1525,6 +1564,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -1565,6 +1605,7 @@ "pitch-accents": "
  1. (うちこむ only)
  2. (うちこむ only)
  3. (ぶちこむ only)
  4. (ぶちこむ only)
", "pitch-accent-graphs": "
  1. (うちこむ only)
  2. (うちこむ only)
  3. (ぶちこむ only)
  4. (ぶちこむ only)
", "pitch-accent-positions": "
  1. (うちこむ only) [0]
  2. (うちこむ only) [3]
  3. (ぶちこむ only) [0]
  4. (ぶちこむ only) [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ、ぶちこむ", "screenshot": "", @@ -1600,6 +1641,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ、ぶつ", "screenshot": "", @@ -1635,6 +1677,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -1670,6 +1713,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -1710,6 +1754,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -1745,6 +1790,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -1780,6 +1826,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -1815,6 +1862,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -1850,6 +1898,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -1885,6 +1934,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -1920,6 +1970,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -1955,6 +2006,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -1990,6 +2042,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -2025,6 +2078,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -2065,6 +2119,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -2100,6 +2155,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -2135,6 +2191,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -2170,6 +2227,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -2205,6 +2263,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -2240,6 +2299,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -2275,6 +2335,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -2310,6 +2371,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -2345,6 +2407,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -2380,6 +2443,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -2420,6 +2484,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -2455,6 +2520,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -2490,6 +2556,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ", "screenshot": "", @@ -2525,6 +2592,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [0]
  2. [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "ぶちこむ", "screenshot": "", @@ -2560,6 +2628,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -2595,6 +2664,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -2630,6 +2700,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -2665,6 +2736,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ぶつ", "screenshot": "", @@ -2700,6 +2772,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "だ", "screenshot": "", @@ -2735,6 +2808,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "ダース", "screenshot": "", @@ -2775,6 +2849,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "よむ", "screenshot": "", @@ -2815,6 +2890,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "つよみ", "screenshot": "", @@ -2855,6 +2931,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "よむ", "screenshot": "", @@ -2895,6 +2972,7 @@ "pitch-accents": "
  1. (うちこむ only)
  2. (うちこむ only)
  3. (ぶちこむ only)
  4. (ぶちこむ only)
", "pitch-accent-graphs": "
  1. (うちこむ only)
  2. (うちこむ only)
  3. (ぶちこむ only)
  4. (ぶちこむ only)
", "pitch-accent-positions": "
  1. (うちこむ only) [0]
  2. (うちこむ only) [3]
  3. (ぶちこむ only) [0]
  4. (ぶちこむ only) [3]
", + "pitch-accent-categories": "heiban,kifuku", "phonetic-transcriptions": "", "reading": "うちこむ、ぶちこむ", "screenshot": "", @@ -2930,6 +3008,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ、ぶつ", "screenshot": "", @@ -2970,6 +3049,7 @@ "pitch-accents": "
", "pitch-accent-graphs": "
", "pitch-accent-positions": "
  1. [2]
  2. [2]
  3. [0]
", + "pitch-accent-categories": "nakadaka,heiban", "phonetic-transcriptions": "", "reading": "おてまえ", "screenshot": "", @@ -3010,6 +3090,7 @@ "pitch-accents": "", "pitch-accent-graphs": "", "pitch-accent-positions": "[3]", + "pitch-accent-categories": "nakadaka", "phonetic-transcriptions": "", "reading": "ばんごう", "screenshot": "", @@ -3050,6 +3131,7 @@ "pitch-accents": "", "pitch-accent-graphs": "", "pitch-accent-positions": "[0]", + "pitch-accent-categories": "heiban", "phonetic-transcriptions": "", "reading": "ちゅうごし", "screenshot": "", @@ -3090,6 +3172,7 @@ "pitch-accents": "", "pitch-accent-graphs": "", "pitch-accent-positions": "[0]", + "pitch-accent-categories": "heiban", "phonetic-transcriptions": "", "reading": "しょぎょう", "screenshot": "", @@ -3130,6 +3213,7 @@ "pitch-accents": "", "pitch-accent-graphs": "", "pitch-accent-positions": "[4]", + "pitch-accent-categories": "nakadaka", "phonetic-transcriptions": "", "reading": "どぼくこうじ", "screenshot": "", @@ -3170,6 +3254,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "すき", "screenshot": "", @@ -3210,6 +3295,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "こうぞう", "screenshot": "", @@ -3250,6 +3336,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "のたまう", "screenshot": "", @@ -3290,6 +3377,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "さんきゅう", "screenshot": "", @@ -3330,6 +3418,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -3365,6 +3454,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -3405,6 +3495,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -3440,6 +3531,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -3480,6 +3572,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "テキスト", "screenshot": "", @@ -3520,6 +3613,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -3555,6 +3649,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "うつ", "screenshot": "", @@ -3595,6 +3690,7 @@ "pitch-accents": "No pitch accent data", "pitch-accent-graphs": "No pitch accent data", "pitch-accent-positions": "No pitch accent data", + "pitch-accent-categories": "", "phonetic-transcriptions": "", "reading": "すごい", "screenshot": "", diff --git a/test/dictionary-data.test.js b/test/dictionary-data.test.js index dcc03d72..bf2d0ace 100644 --- a/test/dictionary-data.test.js +++ b/test/dictionary-data.test.js @@ -63,7 +63,7 @@ describe('Dictionary data', () => { const {mode, text} = data; const options = createFindTermsOptions(dictionaryName, optionsPresets, data.options); const {dictionaryEntries, originalTextLength} = await translator.findTerms(mode, text, options); - const renderResults = mode !== 'simple' ? await getTemplateRenderResults(dictionaryEntries, 'terms', mode, template, expect) : null; + const renderResults = mode !== 'simple' ? await getTemplateRenderResults(dictionaryEntries, mode, template, expect) : null; const noteDataList = mode !== 'simple' ? dictionaryEntries.map((dictionaryEntry) => createTestAnkiNoteData(dictionaryEntry, mode)) : null; expect.soft(originalTextLength).toStrictEqual(expected1.originalTextLength); expect.soft(dictionaryEntries).toStrictEqual(expected1.dictionaryEntries); @@ -76,7 +76,7 @@ describe('Dictionary data', () => { const {text} = data; const options = createFindKanjiOptions(dictionaryName, optionsPresets, data.options); const dictionaryEntries = await translator.findKanji(text, options); - const renderResults = await getTemplateRenderResults(dictionaryEntries, 'kanji', 'split', template, expect); + const renderResults = await getTemplateRenderResults(dictionaryEntries, 'split', template, expect); const noteDataList = dictionaryEntries.map((dictionaryEntry) => createTestAnkiNoteData(dictionaryEntry, 'split')); expect.soft(dictionaryEntries).toStrictEqual(expected1.dictionaryEntries); expect.soft(noteDataList).toEqual(expected2.noteDataList); diff --git a/test/dictionary-data.write.js b/test/dictionary-data.write.js index a6e14656..b271da57 100644 --- a/test/dictionary-data.write.js +++ b/test/dictionary-data.write.js @@ -64,7 +64,7 @@ test('Write dictionary data expected data', async ({window, translator, expect}) const {mode, text} = data; const options = createFindTermsOptions(dictionaryName, optionsPresets, data.options); const {dictionaryEntries, originalTextLength} = await translator.findTerms(mode, text, options); - const renderResults = mode !== 'simple' ? await getTemplateRenderResults(dictionaryEntries, 'terms', mode, template, null) : null; + const renderResults = mode !== 'simple' ? await getTemplateRenderResults(dictionaryEntries, mode, template, null) : null; const noteDataList = mode !== 'simple' ? dictionaryEntries.map((dictionaryEntry) => createTestAnkiNoteData(dictionaryEntry, mode)) : null; actualResults1.push({name, originalTextLength, dictionaryEntries}); actualResults2.push({name, noteDataList}); @@ -76,7 +76,7 @@ test('Write dictionary data expected data', async ({window, translator, expect}) const {text} = data; const options = createFindKanjiOptions(dictionaryName, optionsPresets, data.options); const dictionaryEntries = await translator.findKanji(text, options); - const renderResults = await getTemplateRenderResults(dictionaryEntries, 'kanji', 'split', template, null); + const renderResults = await getTemplateRenderResults(dictionaryEntries, 'split', template, null); const noteDataList = dictionaryEntries.map((dictionaryEntry) => createTestAnkiNoteData(dictionaryEntry, 'split')); actualResults1.push({name, dictionaryEntries}); actualResults2.push({name, noteDataList}); diff --git a/test/utilities/anki.js b/test/utilities/anki.js index 4c6c6d57..9f9bfef3 100644 --- a/test/utilities/anki.js +++ b/test/utilities/anki.js @@ -16,9 +16,23 @@ */ import {AnkiNoteBuilder} from '../../ext/js/data/anki-note-builder.js'; +import {getStandardFieldMarkers} from '../../ext/js/data/anki-template-util.js'; import {createAnkiNoteData} from '../../ext/js/data/sandbox/anki-note-data-creator.js'; import {AnkiTemplateRenderer} from '../../ext/js/templates/sandbox/anki-template-renderer.js'; +/** + * @param {import('dictionary').DictionaryEntryType} type + * @returns {import('anki-note-builder').Field[]} + */ +function createTestFields(type) { + /** @type {import('anki-note-builder').Field[]} */ + const fields = []; + for (const marker of getStandardFieldMarkers(type)) { + fields.push([marker, `{${marker}}`]); + } + return fields; +} + /** * @param {import('dictionary').DictionaryEntry} dictionaryEntry * @param {import('settings').ResultOutputMode} mode @@ -46,96 +60,14 @@ export function createTestAnkiNoteData(dictionaryEntry, mode) { return createAnkiNoteData(marker, data); } -/** - * @param {'terms'|'kanji'} type - * @returns {string[]} - */ -function getFieldMarkers(type) { - switch (type) { - case 'terms': - return [ - 'audio', - 'clipboard-image', - 'clipboard-text', - 'cloze-body', - 'cloze-prefix', - 'cloze-suffix', - 'conjugation', - 'dictionary', - 'document-title', - 'expression', - 'frequencies', - 'frequency-harmonic-rank', - 'frequency-harmonic-occurrence', - 'frequency-average-rank', - 'frequency-average-occurrence', - 'furigana', - 'furigana-plain', - 'glossary', - 'glossary-brief', - 'glossary-no-dictionary', - 'part-of-speech', - 'pitch-accents', - 'pitch-accent-graphs', - 'pitch-accent-positions', - 'phonetic-transcriptions', - 'reading', - 'screenshot', - 'search-query', - 'selection-text', - 'sentence', - 'sentence-furigana', - 'tags', - 'url' - ]; - case 'kanji': - return [ - 'character', - 'clipboard-image', - 'clipboard-text', - 'cloze-body', - 'cloze-prefix', - 'cloze-suffix', - 'dictionary', - 'document-title', - 'frequencies', - 'frequency-harmonic-rank', - 'frequency-harmonic-occurrence', - 'frequency-average-rank', - 'frequency-average-occurrence', - 'glossary', - 'kunyomi', - 'onyomi', - 'screenshot', - 'search-query', - 'selection-text', - 'sentence', - 'sentence-furigana', - 'stroke-count', - 'tags', - 'url' - ]; - default: - return []; - } -} - /** * @param {import('dictionary').DictionaryEntry[]} dictionaryEntries - * @param {'terms'|'kanji'} type * @param {import('settings').ResultOutputMode} mode * @param {string} template * @param {?import('vitest').ExpectStatic} expect * @returns {Promise} */ -export async function getTemplateRenderResults(dictionaryEntries, type, mode, template, expect) { - const markers = getFieldMarkers(type); - /** @type {import('anki-note-builder').Field[]} */ - const fields = []; - for (const marker of markers) { - fields.push([marker, `{${marker}}`]); - } - +export async function getTemplateRenderResults(dictionaryEntries, mode, template, expect) { const ankiTemplateRenderer = new AnkiTemplateRenderer(); await ankiTemplateRenderer.prepare(); const clozePrefix = 'cloze-prefix'; @@ -173,7 +105,7 @@ export async function getTemplateRenderResults(dictionaryEntries, type, mode, te template, deckName: 'deckName', modelName: 'modelName', - fields, + fields: createTestFields(dictionaryEntry.type), tags: ['yomitan'], checkForDuplicates: true, duplicateScope: 'collection', -- cgit v1.2.3