summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json6
-rw-r--r--test/lint/global-declarations.js27
-rw-r--r--test/test-database.js16
-rw-r--r--test/test-japanese.js64
4 files changed, 60 insertions, 53 deletions
diff --git a/test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json b/test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json
index 26922394..73d74e68 100644
--- a/test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json
+++ b/test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json
@@ -2,6 +2,12 @@
["打", "freq", 1],
["打つ", "freq", 2],
["打ち込む", "freq", 3],
+ ["打", "freq", {"reading": "だ", "frequency": 4}],
+ ["打", "freq", {"reading": "ダース", "frequency": 5}],
+ ["打つ", "freq", {"reading": "うつ", "frequency": 6}],
+ ["打つ", "freq", {"reading": "ぶつ", "frequency": 7}],
+ ["打ち込む", "freq", {"reading": "うちこむ", "frequency": 8}],
+ ["打ち込む", "freq", {"reading": "ぶちこむ", "frequency": 9}],
[
"打ち込む",
"pitch",
diff --git a/test/lint/global-declarations.js b/test/lint/global-declarations.js
index 07ba5570..2fc9a5e2 100644
--- a/test/lint/global-declarations.js
+++ b/test/lint/global-declarations.js
@@ -37,6 +37,18 @@ function getNewline(string) {
}
}
+function getSubstringCount(string, substring) {
+ let start = 0;
+ let count = 0;
+ while (true) {
+ const pos = string.indexOf(substring, start);
+ if (pos < 0) { break; }
+ ++count;
+ start = pos + substring.length;
+ }
+ return count;
+}
+
function validateGlobals(fileName, fix) {
const pattern = /\/\*\s*global\s+([\w\W]*?)\*\//g;
@@ -47,6 +59,7 @@ function validateGlobals(fileName, fix) {
let first = true;
let endIndex = 0;
let newSource = '';
+ const allGlobals = [];
const newline = getNewline(source);
while ((match = pattern.exec(source)) !== null) {
if (!first) {
@@ -74,15 +87,27 @@ function validateGlobals(fileName, fix) {
newSource += source.substring(0, match.index);
newSource += expected;
endIndex = match.index + match[0].length;
+
+ allGlobals.push(...parts);
}
newSource += source.substring(endIndex);
+ // This is an approximate check to see if a global variable is unused.
+ // If the global appears in a comment, string, or similar, the check will pass.
+ let errorCount = 0;
+ for (const global of allGlobals) {
+ if (getSubstringCount(newSource, global) <= 1) {
+ console.error(`Global variable ${global} appears to be unused in ${fileName}`);
+ ++errorCount;
+ }
+ }
+
if (fix) {
fs.writeFileSync(fileName, newSource, {encoding: 'utf8'});
}
- return true;
+ return errorCount === 0;
}
diff --git a/test/test-database.js b/test/test-database.js
index d27f92e1..8b7a163a 100644
--- a/test/test-database.js
+++ b/test/test-database.js
@@ -235,8 +235,8 @@ async function testDatabase1() {
true
);
vm.assert.deepStrictEqual(counts, {
- counts: [{kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 6, tagMeta: 14}],
- total: {kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 6, tagMeta: 14}
+ counts: [{kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 12, tagMeta: 14}],
+ total: {kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 12, tagMeta: 14}
});
// Test find* functions
@@ -626,9 +626,9 @@ async function testFindTermMetaBulk1(database, titles) {
}
],
expectedResults: {
- total: 1,
+ total: 3,
modes: [
- ['freq', 1]
+ ['freq', 3]
]
}
},
@@ -639,9 +639,9 @@ async function testFindTermMetaBulk1(database, titles) {
}
],
expectedResults: {
- total: 1,
+ total: 3,
modes: [
- ['freq', 1]
+ ['freq', 3]
]
}
},
@@ -652,9 +652,9 @@ async function testFindTermMetaBulk1(database, titles) {
}
],
expectedResults: {
- total: 3,
+ total: 5,
modes: [
- ['freq', 1],
+ ['freq', 3],
['pitch', 2]
]
}
diff --git a/test/test-japanese.js b/test/test-japanese.js
index 89e41c36..87efdfad 100644
--- a/test/test-japanese.js
+++ b/test/test-japanese.js
@@ -176,19 +176,19 @@ function testConvertReading() {
[['アリガトウ', 'アリガトウ', 'hiragana'], 'ありがとう'],
[['アリガトウ', 'アリガトウ', 'katakana'], 'アリガトウ'],
[['アリガトウ', 'アリガトウ', 'romaji'], 'arigatou'],
- [['アリガトウ', 'アリガトウ', 'none'], null],
+ [['アリガトウ', 'アリガトウ', 'none'], ''],
[['アリガトウ', 'アリガトウ', 'default'], 'アリガトウ'],
[['ありがとう', 'ありがとう', 'hiragana'], 'ありがとう'],
[['ありがとう', 'ありがとう', 'katakana'], 'アリガトウ'],
[['ありがとう', 'ありがとう', 'romaji'], 'arigatou'],
- [['ありがとう', 'ありがとう', 'none'], null],
+ [['ありがとう', 'ありがとう', 'none'], ''],
[['ありがとう', 'ありがとう', 'default'], 'ありがとう'],
[['有り難う', 'ありがとう', 'hiragana'], 'ありがとう'],
[['有り難う', 'ありがとう', 'katakana'], 'アリガトウ'],
[['有り難う', 'ありがとう', 'romaji'], 'arigatou'],
- [['有り難う', 'ありがとう', 'none'], null],
+ [['有り難う', 'ありがとう', 'none'], ''],
[['有り難う', 'ありがとう', 'default'], 'ありがとう'],
// Cases with falsy readings
@@ -196,44 +196,20 @@ function testConvertReading() {
[['ありがとう', '', 'hiragana'], ''],
[['ありがとう', '', 'katakana'], ''],
[['ありがとう', '', 'romaji'], 'arigatou'],
- [['ありがとう', '', 'none'], null],
+ [['ありがとう', '', 'none'], ''],
[['ありがとう', '', 'default'], ''],
- [['ありがとう', null, 'hiragana'], ''],
- [['ありがとう', null, 'katakana'], ''],
- [['ありがとう', null, 'romaji'], 'arigatou'],
- [['ありがとう', null, 'none'], null],
- [['ありがとう', null, 'default'], null],
-
- [['ありがとう', void 0, 'hiragana'], ''],
- [['ありがとう', void 0, 'katakana'], ''],
- [['ありがとう', void 0, 'romaji'], 'arigatou'],
- [['ありがとう', void 0, 'none'], null],
- [['ありがとう', void 0, 'default'], void 0],
-
// Cases with falsy readings and kanji expressions
[['有り難う', '', 'hiragana'], ''],
[['有り難う', '', 'katakana'], ''],
[['有り難う', '', 'romaji'], ''],
- [['有り難う', '', 'none'], null],
- [['有り難う', '', 'default'], ''],
-
- [['有り難う', null, 'hiragana'], ''],
- [['有り難う', null, 'katakana'], ''],
- [['有り難う', null, 'romaji'], null],
- [['有り難う', null, 'none'], null],
- [['有り難う', null, 'default'], null],
-
- [['有り難う', void 0, 'hiragana'], ''],
- [['有り難う', void 0, 'katakana'], ''],
- [['有り難う', void 0, 'romaji'], void 0],
- [['有り難う', void 0, 'none'], null],
- [['有り難う', void 0, 'default'], void 0]
+ [['有り難う', '', 'none'], ''],
+ [['有り難う', '', 'default'], '']
];
- for (const [[expressionFragment, readingFragment, readingMode], expected] of data) {
- assert.strictEqual(jp.convertReading(expressionFragment, readingFragment, readingMode), expected);
+ for (const [[expression, reading, readingMode], expected] of data) {
+ assert.strictEqual(jp.convertReading(expression, reading, readingMode), expected);
}
}
@@ -303,9 +279,9 @@ function testDistributeFurigana() {
['有り難う', 'ありがとう'],
[
{text: '有', furigana: 'あ'},
- {text: 'り'},
+ {text: 'り', furigana: ''},
{text: '難', furigana: 'がと'},
- {text: 'う'}
+ {text: 'う', furigana: ''}
]
],
[
@@ -317,23 +293,23 @@ function testDistributeFurigana() {
[
['お祝い', 'おいわい'],
[
- {text: 'お'},
+ {text: 'お', furigana: ''},
{text: '祝', furigana: 'いわ'},
- {text: 'い'}
+ {text: 'い', furigana: ''}
]
],
[
['美味しい', 'おいしい'],
[
{text: '美味', furigana: 'おい'},
- {text: 'しい'}
+ {text: 'しい', furigana: ''}
]
],
[
['食べ物', 'たべもの'],
[
{text: '食', furigana: 'た'},
- {text: 'べ'},
+ {text: 'べ', furigana: ''},
{text: '物', furigana: 'もの'}
]
],
@@ -341,9 +317,9 @@ function testDistributeFurigana() {
['試し切り', 'ためしぎり'],
[
{text: '試', furigana: 'ため'},
- {text: 'し'},
+ {text: 'し', furigana: ''},
{text: '切', furigana: 'ぎ'},
- {text: 'り'}
+ {text: 'り', furigana: ''}
]
],
// Ambiguous
@@ -373,16 +349,16 @@ function testDistributeFuriganaInflected() {
['美味しい', 'おいしい', '美味しかた'],
[
{text: '美味', furigana: 'おい'},
- {text: 'し'},
- {text: 'かた'}
+ {text: 'し', furigana: ''},
+ {text: 'かた', furigana: ''}
]
],
[
['食べる', 'たべる', '食べた'],
[
{text: '食', furigana: 'た'},
- {text: 'べ'},
- {text: 'た'}
+ {text: 'べ', furigana: ''},
+ {text: 'た', furigana: ''}
]
]
];