From a54f44122a3a245c1b1579c15b2faf9d50c15c55 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 22 Feb 2020 12:58:33 -0500 Subject: Update location of test dictionary data --- .../data/dictionaries/valid-dictionary1/index.json | 6 ++++ .../valid-dictionary1/kanji_bank_1.json | 42 ++++++++++++++++++++++ .../valid-dictionary1/kanji_meta_bank_1.json | 4 +++ .../dictionaries/valid-dictionary1/tag_bank_1.json | 7 ++++ .../dictionaries/valid-dictionary1/tag_bank_2.json | 9 +++++ .../valid-dictionary1/term_bank_1.json | 34 ++++++++++++++++++ .../valid-dictionary1/term_meta_bank_1.json | 5 +++ 7 files changed, 107 insertions(+) create mode 100644 test/data/dictionaries/valid-dictionary1/index.json create mode 100644 test/data/dictionaries/valid-dictionary1/kanji_bank_1.json create mode 100644 test/data/dictionaries/valid-dictionary1/kanji_meta_bank_1.json create mode 100644 test/data/dictionaries/valid-dictionary1/tag_bank_1.json create mode 100644 test/data/dictionaries/valid-dictionary1/tag_bank_2.json create mode 100644 test/data/dictionaries/valid-dictionary1/term_bank_1.json create mode 100644 test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json (limited to 'test/data') diff --git a/test/data/dictionaries/valid-dictionary1/index.json b/test/data/dictionaries/valid-dictionary1/index.json new file mode 100644 index 00000000..3034bf38 --- /dev/null +++ b/test/data/dictionaries/valid-dictionary1/index.json @@ -0,0 +1,6 @@ +{ + "title": "Test Dictionary", + "format": 3, + "revision": "test", + "sequenced": true +} \ No newline at end of file diff --git a/test/data/dictionaries/valid-dictionary1/kanji_bank_1.json b/test/data/dictionaries/valid-dictionary1/kanji_bank_1.json new file mode 100644 index 00000000..264f94c1 --- /dev/null +++ b/test/data/dictionaries/valid-dictionary1/kanji_bank_1.json @@ -0,0 +1,42 @@ +[ + [ + "打", + "ダ ダアス", + "う.つ う.ち- ぶ.つ", + "ktag1 ktag2", + [ + "meaning1", + "meaning2", + "meaning3", + "meaning4", + "meaning5" + ], + { + "kstat1": "1", + "kstat2": "2", + "kstat3": "3", + "kstat4": "4", + "kstat5": "5" + } + ], + [ + "込", + "", + "-こ.む こ.む こ.み -こ.み こ.める", + "ktag1 ktag2", + [ + "meaning1", + "meaning2", + "meaning3", + "meaning4", + "meaning5" + ], + { + "kstat1": "1", + "kstat2": "2", + "kstat3": "3", + "kstat4": "4", + "kstat5": "5" + } + ] +] \ No newline at end of file diff --git a/test/data/dictionaries/valid-dictionary1/kanji_meta_bank_1.json b/test/data/dictionaries/valid-dictionary1/kanji_meta_bank_1.json new file mode 100644 index 00000000..73e75b8a --- /dev/null +++ b/test/data/dictionaries/valid-dictionary1/kanji_meta_bank_1.json @@ -0,0 +1,4 @@ +[ + ["打", "freq", 1], + ["込", "freq", 2] +] \ No newline at end of file diff --git a/test/data/dictionaries/valid-dictionary1/tag_bank_1.json b/test/data/dictionaries/valid-dictionary1/tag_bank_1.json new file mode 100644 index 00000000..109ad395 --- /dev/null +++ b/test/data/dictionaries/valid-dictionary1/tag_bank_1.json @@ -0,0 +1,7 @@ +[ + ["tag1", "category1", 0, "tag1 notes", 0], + ["tag2", "category2", 0, "tag2 notes", 0], + ["tag3", "category3", 0, "tag3 notes", 0], + ["tag4", "category4", 0, "tag4 notes", 0], + ["tag5", "category5", 0, "tag5 notes", 0] +] \ No newline at end of file diff --git a/test/data/dictionaries/valid-dictionary1/tag_bank_2.json b/test/data/dictionaries/valid-dictionary1/tag_bank_2.json new file mode 100644 index 00000000..5e7936b3 --- /dev/null +++ b/test/data/dictionaries/valid-dictionary1/tag_bank_2.json @@ -0,0 +1,9 @@ +[ + ["ktag1", "kcategory1", 0, "ktag1 notes", 0], + ["ktag2", "kcategory2", 0, "ktag2 notes", 0], + ["kstat1", "kcategory3", 0, "kstat1 notes", 0], + ["kstat2", "kcategory4", 0, "kstat2 notes", 0], + ["kstat3", "kcategory5", 0, "kstat3 notes", 0], + ["kstat4", "kcategory6", 0, "kstat4 notes", 0], + ["kstat5", "kcategory7", 0, "kstat5 notes", 0] +] \ 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 new file mode 100644 index 00000000..755d9f6a --- /dev/null +++ b/test/data/dictionaries/valid-dictionary1/term_bank_1.json @@ -0,0 +1,34 @@ +[ + ["打", "だ", "tag1 tag2", "", 2, ["definition1a (打, だ)", "definition1b (打, だ)"], 1, "tag3 tag4 tag5"], + ["打", "ダース", "tag1 tag2", "", 1, ["definition1a (打, ダース)", "definition1b (打, ダース)"], 2, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 3, ["definition1a (打つ, うつ)", "definition1b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 4, ["definition2a (打つ, うつ)", "definition2b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 5, ["definition3a (打つ, うつ)", "definition3b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 6, ["definition4a (打つ, うつ)", "definition4b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 7, ["definition5a (打つ, うつ)", "definition5b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 8, ["definition6a (打つ, うつ)", "definition6b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 9, ["definition7a (打つ, うつ)", "definition7b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 10, ["definition8a (打つ, うつ)", "definition8b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 11, ["definition9a (打つ, うつ)", "definition9b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 12, ["definition10a (打つ, うつ)", "definition10b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 13, ["definition11a (打つ, うつ)", "definition11b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 14, ["definition12a (打つ, うつ)", "definition12b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 15, ["definition13a (打つ, うつ)", "definition13b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 16, ["definition14a (打つ, うつ)", "definition14b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "うつ", "tag1 tag2", "v5", 17, ["definition15a (打つ, うつ)", "definition15b (打つ, うつ)"], 3, "tag3 tag4 tag5"], + ["打つ", "ぶつ", "tag1 tag2", "v5", 18, ["definition1a (打つ, ぶつ)", "definition1b (打つ, ぶつ)"], 4, "tag3 tag4 tag5"], + ["打つ", "ぶつ", "tag1 tag2", "v5", 19, ["definition2a (打つ, ぶつ)", "definition2b (打つ, ぶつ)"], 4, "tag3 tag4 tag5"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 20, ["definition1a (打ち込む, うちこむ)", "definition1b (打ち込む, うちこむ)"], 5, "tag3 tag4 tag5"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 21, ["definition2a (打ち込む, うちこむ)", "definition2b (打ち込む, うちこむ)"], 5, "tag5 tag6 tag7"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 22, ["definition3a (打ち込む, うちこむ)", "definition3b (打ち込む, うちこむ)"], 5, "tag5 tag6 tag7"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 23, ["definition4a (打ち込む, うちこむ)", "definition4b (打ち込む, うちこむ)"], 5, "tag5 tag6 tag7"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 24, ["definition5a (打ち込む, うちこむ)", "definition5b (打ち込む, うちこむ)"], 5, "tag5 tag6 tag7"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 25, ["definition6a (打ち込む, うちこむ)", "definition6b (打ち込む, うちこむ)"], 5, "tag5 tag6 tag7"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 26, ["definition7a (打ち込む, うちこむ)", "definition7b (打ち込む, うちこむ)"], 5, "tag5 tag6 tag7"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 27, ["definition8a (打ち込む, うちこむ)", "definition8b (打ち込む, うちこむ)"], 5, "tag5 tag6 tag7"], + ["打ち込む", "うちこむ", "tag1 tag2", "v5", 28, ["definition9a (打ち込む, うちこむ)", "definition9b (打ち込む, うちこむ)"], 5, "tag5 tag6 tag7"], + ["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 29, ["definition1a (打ち込む, ぶちこむ)", "definition1b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"], + ["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 30, ["definition2a (打ち込む, ぶちこむ)", "definition2b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"], + ["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 31, ["definition3a (打ち込む, ぶちこむ)", "definition3b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"], + ["打ち込む", "ぶちこむ", "tag1 tag2", "v5", 32, ["definition4a (打ち込む, ぶちこむ)", "definition4b (打ち込む, ぶちこむ)"], 6, "tag3 tag4 tag5"] +] \ No newline at end of file diff --git a/test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json b/test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json new file mode 100644 index 00000000..78096502 --- /dev/null +++ b/test/data/dictionaries/valid-dictionary1/term_meta_bank_1.json @@ -0,0 +1,5 @@ +[ + ["打", "freq", 1], + ["打つ", "freq", 2], + ["打ち込む", "freq", 3] +] \ No newline at end of file -- cgit v1.2.3 From 12e0923b63492c8ba5ca949d5ce0f3ad8aeb01d0 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 22 Feb 2020 13:38:03 -0500 Subject: Add some basic invalid dictionaries to test --- .../dictionaries/invalid-dictionary1/index.json | 7 ++++ .../dictionaries/invalid-dictionary2/index.json | 7 ++++ .../invalid-dictionary2/kanji_bank_1.json | 3 ++ .../dictionaries/invalid-dictionary3/index.json | 7 ++++ .../invalid-dictionary3/kanji_meta_bank_1.json | 1 + .../dictionaries/invalid-dictionary4/index.json | 7 ++++ .../invalid-dictionary4/tag_bank_1.json | 3 ++ .../dictionaries/invalid-dictionary5/index.json | 7 ++++ .../invalid-dictionary5/term_bank_1.json | 3 ++ .../dictionaries/invalid-dictionary6/index.json | 7 ++++ .../invalid-dictionary6/term_meta_bank_1.json | 1 + test/test-database.js | 42 ++++++++++++++++++++++ 12 files changed, 95 insertions(+) create mode 100644 test/data/dictionaries/invalid-dictionary1/index.json create mode 100644 test/data/dictionaries/invalid-dictionary2/index.json create mode 100644 test/data/dictionaries/invalid-dictionary2/kanji_bank_1.json create mode 100644 test/data/dictionaries/invalid-dictionary3/index.json create mode 100644 test/data/dictionaries/invalid-dictionary3/kanji_meta_bank_1.json create mode 100644 test/data/dictionaries/invalid-dictionary4/index.json create mode 100644 test/data/dictionaries/invalid-dictionary4/tag_bank_1.json create mode 100644 test/data/dictionaries/invalid-dictionary5/index.json create mode 100644 test/data/dictionaries/invalid-dictionary5/term_bank_1.json create mode 100644 test/data/dictionaries/invalid-dictionary6/index.json create mode 100644 test/data/dictionaries/invalid-dictionary6/term_meta_bank_1.json (limited to 'test/data') diff --git a/test/data/dictionaries/invalid-dictionary1/index.json b/test/data/dictionaries/invalid-dictionary1/index.json new file mode 100644 index 00000000..1be3b360 --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary1/index.json @@ -0,0 +1,7 @@ +{ + "title": "Invalid Dictionary 1", + "format": 0, + "revision": "test", + "sequenced": true, + "description": "Invalid format number" +} \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary2/index.json b/test/data/dictionaries/invalid-dictionary2/index.json new file mode 100644 index 00000000..ba2cc669 --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary2/index.json @@ -0,0 +1,7 @@ +{ + "title": "Invalid Dictionary 2", + "format": 3, + "revision": "test", + "sequenced": true, + "description": "Empty entry in kanji bank" +} \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary2/kanji_bank_1.json b/test/data/dictionaries/invalid-dictionary2/kanji_bank_1.json new file mode 100644 index 00000000..5825bcac --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary2/kanji_bank_1.json @@ -0,0 +1,3 @@ +[ + [] +] \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary3/index.json b/test/data/dictionaries/invalid-dictionary3/index.json new file mode 100644 index 00000000..f23fa3f0 --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary3/index.json @@ -0,0 +1,7 @@ +{ + "title": "Invalid Dictionary 3", + "format": 3, + "revision": "test", + "sequenced": true, + "description": "Invalid type entry in kanji meta bank" +} \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary3/kanji_meta_bank_1.json b/test/data/dictionaries/invalid-dictionary3/kanji_meta_bank_1.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary3/kanji_meta_bank_1.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary4/index.json b/test/data/dictionaries/invalid-dictionary4/index.json new file mode 100644 index 00000000..542791d7 --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary4/index.json @@ -0,0 +1,7 @@ +{ + "title": "Invalid Dictionary 4", + "format": 3, + "revision": "test", + "sequenced": true, + "description": "Invalid value as part of a tag bank entry" +} \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary4/tag_bank_1.json b/test/data/dictionaries/invalid-dictionary4/tag_bank_1.json new file mode 100644 index 00000000..4f19b476 --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary4/tag_bank_1.json @@ -0,0 +1,3 @@ +[ + [{"invalid": true}, "category1", 0, "tag1 notes", 0] +] \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary5/index.json b/test/data/dictionaries/invalid-dictionary5/index.json new file mode 100644 index 00000000..e0d0f00e --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary5/index.json @@ -0,0 +1,7 @@ +{ + "title": "Invalid Dictionary 5", + "format": 3, + "revision": "test", + "sequenced": true, + "description": "Invalid type as part of a term bank entry" +} \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary5/term_bank_1.json b/test/data/dictionaries/invalid-dictionary5/term_bank_1.json new file mode 100644 index 00000000..7288a996 --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary5/term_bank_1.json @@ -0,0 +1,3 @@ +[ + ["打", "だ", "tag1 tag2", "", 2, false, 1, "tag3 tag4 tag5"] +] \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary6/index.json b/test/data/dictionaries/invalid-dictionary6/index.json new file mode 100644 index 00000000..b91acca3 --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary6/index.json @@ -0,0 +1,7 @@ +{ + "title": "Invalid Dictionary 6", + "format": 3, + "revision": "test", + "sequenced": true, + "description": "Invalid root type for term meta bank" +} \ No newline at end of file diff --git a/test/data/dictionaries/invalid-dictionary6/term_meta_bank_1.json b/test/data/dictionaries/invalid-dictionary6/term_meta_bank_1.json new file mode 100644 index 00000000..02e4a84d --- /dev/null +++ b/test/data/dictionaries/invalid-dictionary6/term_meta_bank_1.json @@ -0,0 +1 @@ +false \ No newline at end of file diff --git a/test/test-database.js b/test/test-database.js index 6fe515e6..4fb3805d 100644 --- a/test/test-database.js +++ b/test/test-database.js @@ -849,6 +849,45 @@ async function testDatabase2() { } +async function testDatabase3() { + const invalidDictionaries = [ + 'invalid-dictionary1', + 'invalid-dictionary2', + 'invalid-dictionary3', + 'invalid-dictionary4', + 'invalid-dictionary5', + 'invalid-dictionary6' + ]; + + // Setup database + const database = new Database(); + await database.prepare(); + + for (const invalidDictionary of invalidDictionaries) { + const testDictionary = yomichanTest.createTestDictionaryArchive(invalidDictionary); + const testDictionarySource = await testDictionary.generateAsync({type: 'string'}); + + let error = null; + try { + await database.importDictionary(testDictionarySource, () => {}, {}); + } catch (e) { + error = e; + } + + if (error === null) { + assert.ok(false, `Expected an error while importing ${invalidDictionary}`); + } else { + const prefix = 'Dictionary has invalid data'; + const message = error.message; + assert.ok(typeof message, 'string'); + assert.ok(message.startsWith(prefix), `Expected error message to start with '${prefix}': ${message}`); + } + } + + await database.close(); +} + + async function main() { const clearTimeout = 5000; try { @@ -857,6 +896,9 @@ async function main() { await testDatabase2(); await clearDatabase(clearTimeout); + + await testDatabase3(); + await clearDatabase(clearTimeout); } catch (e) { console.log(e); process.exit(-1); -- cgit v1.2.3