summaryrefslogtreecommitdiff
path: root/test/test-dictionary.js
blob: b157dd5de2c2e4683516665e695caa4304864803 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const yomichanTest = require('./yomichan-test');
const dictionaryValidate = require('./dictionary-validate');


async function main() {
    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}
    ];

    const schemas = dictionaryValidate.getSchemas();

    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`);
            }
        }
    }
}


if (require.main === module) { main(); }