forked from wooorm/dictionaries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
80 lines (60 loc) · 1.61 KB
/
test.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict';
var fs = require('fs');
var path = require('path');
var assert = require('assert');
var test = require('tape');
var vfile = require('to-vfile');
var bail = require('bail');
var not = require('not');
var hidden = require('is-hidden');
var isUTF8 = require('utf-8-validate');
var root = 'dictionaries';
var checks = {
'All required files should exist': requiredFiles,
'All files should be in UTF-8': utf8
};
function utf8(name) {
var dirname = path.join(root, name);
fs.readdirSync(dirname).filter(not(hidden)).forEach(check);
function check(filename) {
var file = vfile.readSync(path.join(dirname, filename));
assert.ok(isUTF8(file.contents), file.basename + ' should be utf8');
}
}
function requiredFiles(name) {
var dirname = path.join(root, name);
var files = fs.readdirSync(dirname).filter(not(hidden));
[
'index.dic',
'index.aff',
'readme.md',
'index.js',
'package.json'
].forEach(check);
function check(basename) {
assert.notEqual(files.indexOf(basename), -1, 'should have `' + basename + '`');
}
}
test('dictionaries', function (t) {
fs.readdir(root, ondir);
function ondir(err, paths) {
bail(err);
paths = paths.filter(not(hidden));
t.plan(paths.length);
paths.forEach(check, t);
}
});
function check(basename) {
this.test(basename, all);
function all(st) {
var descriptions = Object.keys(checks);
st.plan(descriptions.length);
descriptions.forEach(one);
function one(description) {
st.doesNotThrow(check, description);
function check() {
checks[description](basename);
}
}
}
}