2020-02-19 03:19:33 +00:00
|
|
|
const yomichanTest = require('./yomichan-test');
|
|
|
|
const dictionaryValidate = require('./dictionary-validate');
|
|
|
|
|
|
|
|
|
|
|
|
async function main() {
|
2020-02-22 18:40:57 +00:00
|
|
|
const dictionaries = [
|
|
|
|
{name: 'valid-dictionary1', valid: true},
|
|
|
|
{name: 'invalid-dictionary1', valid: false},
|
|
|
|
{name: 'invalid-dictionary2', valid: false},
|
|
|
|
{name: 'invalid-dictionary3', valid: false},
|
|
|
|
{name: 'invalid-dictionary4', valid: false},
|
|
|
|
{name: 'invalid-dictionary5', valid: false},
|
|
|
|
{name: 'invalid-dictionary6', valid: false}
|
|
|
|
];
|
|
|
|
|
2020-02-19 03:19:33 +00:00
|
|
|
const schemas = dictionaryValidate.getSchemas();
|
2020-02-22 18:40:57 +00:00
|
|
|
|
|
|
|
for (const {name, valid} of dictionaries) {
|
|
|
|
const archive = yomichanTest.createTestDictionaryArchive(name);
|
|
|
|
|
|
|
|
let error = null;
|
|
|
|
try {
|
|
|
|
await dictionaryValidate.validateDictionary(archive, schemas);
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
if (error !== null) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (error === null) {
|
|
|
|
throw new Error(`Expected dictionary ${name} to be invalid`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-19 03:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (require.main === module) { main(); }
|