Add some basic invalid dictionaries to test
This commit is contained in:
parent
77a3dadd0b
commit
12e0923b63
7
test/data/dictionaries/invalid-dictionary1/index.json
Normal file
7
test/data/dictionaries/invalid-dictionary1/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Invalid Dictionary 1",
|
||||
"format": 0,
|
||||
"revision": "test",
|
||||
"sequenced": true,
|
||||
"description": "Invalid format number"
|
||||
}
|
7
test/data/dictionaries/invalid-dictionary2/index.json
Normal file
7
test/data/dictionaries/invalid-dictionary2/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Invalid Dictionary 2",
|
||||
"format": 3,
|
||||
"revision": "test",
|
||||
"sequenced": true,
|
||||
"description": "Empty entry in kanji bank"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
[
|
||||
[]
|
||||
]
|
7
test/data/dictionaries/invalid-dictionary3/index.json
Normal file
7
test/data/dictionaries/invalid-dictionary3/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Invalid Dictionary 3",
|
||||
"format": 3,
|
||||
"revision": "test",
|
||||
"sequenced": true,
|
||||
"description": "Invalid type entry in kanji meta bank"
|
||||
}
|
@ -0,0 +1 @@
|
||||
{}
|
7
test/data/dictionaries/invalid-dictionary4/index.json
Normal file
7
test/data/dictionaries/invalid-dictionary4/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Invalid Dictionary 4",
|
||||
"format": 3,
|
||||
"revision": "test",
|
||||
"sequenced": true,
|
||||
"description": "Invalid value as part of a tag bank entry"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
[
|
||||
[{"invalid": true}, "category1", 0, "tag1 notes", 0]
|
||||
]
|
7
test/data/dictionaries/invalid-dictionary5/index.json
Normal file
7
test/data/dictionaries/invalid-dictionary5/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Invalid Dictionary 5",
|
||||
"format": 3,
|
||||
"revision": "test",
|
||||
"sequenced": true,
|
||||
"description": "Invalid type as part of a term bank entry"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
[
|
||||
["打", "だ", "tag1 tag2", "", 2, false, 1, "tag3 tag4 tag5"]
|
||||
]
|
7
test/data/dictionaries/invalid-dictionary6/index.json
Normal file
7
test/data/dictionaries/invalid-dictionary6/index.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"title": "Invalid Dictionary 6",
|
||||
"format": 3,
|
||||
"revision": "test",
|
||||
"sequenced": true,
|
||||
"description": "Invalid root type for term meta bank"
|
||||
}
|
@ -0,0 +1 @@
|
||||
false
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user