forked from BolajiAyodeji/compromise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docs.test.js
83 lines (79 loc) · 1.96 KB
/
docs.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
81
82
83
var test = require('tape');
var nlp = require('../lib/nlp');
var docs = require('../../../docs/api');
var freshPrince = require('../lib/freshPrince');
test('generic-methods-run:', function(t) {
var getters = {
found: true,
length: true
};
var skip = {
whitespace: true,
insertAt: true,
debug: true, //too noisy
forEach: true,
filter: true,
map: true,
find: true,
reduce: true,
};
var needString = {
insertBefore: true,
insertAfter: true,
match: true,
splitOn: true,
splitBefore: true,
splitAfter: true
};
var r = nlp(freshPrince);
Object.keys(docs.generic).forEach(function(type) {
Object.keys(docs.generic[type]).forEach(function(fn) {
//simply call this method to see if it throws an error
var func = function() {
if (getters[fn]) {
//getters dont have a '()'
return r[fn];
} else if (needString[fn]) {
//give a dummy param
return r[fn]('fun');
} else if (skip[fn]) {
//these are too fancy to call
return typeof r[fn] === 'function';
} else {
//call this method
return r[fn]();
}
};
t.doesNotThrow(func, true, fn);
});
});
t.end();
});
test('subsets-methods-exist:', function(t) {
var addParam = {
sentences: {
append: true,
prepend: true
}
};
var r = nlp(freshPrince);
Object.keys(docs.subsets).forEach(function(subset) {
//each subset
t.doesNotThrow(function() {
return r[subset](), true, subset + '()';
});
//each method in that subset
Object.keys(docs.subsets[subset]).forEach(function(method) {
var func = function() {
if (addParam[subset] && addParam[subset][method]) {
r[subset]()[method]('fun');
} else {
r[subset]()[method]();
}
};
var msg = subset + '().' + method;
t.doesNotThrow(func, true, msg);
});
});
t.end();
});