diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-02-22 13:38:03 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-02-22 13:38:03 -0500 |
commit | 12e0923b63492c8ba5ca949d5ce0f3ad8aeb01d0 (patch) | |
tree | 86df1a58cf00f5ddf0f29c3c9130bd8113003648 /test/test-database.js | |
parent | 77a3dadd0b128f4421e16c3465fbf609c483241b (diff) |
Add some basic invalid dictionaries to test
Diffstat (limited to 'test/test-database.js')
-rw-r--r-- | test/test-database.js | 42 |
1 files changed, 42 insertions, 0 deletions
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); |