forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvariants.js
45 lines (38 loc) · 1.4 KB
/
invariants.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('invariants', function() {
it('-- applying function f with length n (where n > 0) to no arguments gives function with length n', function() {
for (var prop in R) {
if (typeof R[prop] === 'function' && R[prop].length > 0) {
var result = R[prop]();
eq(typeof result, 'function');
eq(result.length, R[prop].length);
}
}
});
it('-- applying function f with length n (where n > 0) to R.__ gives function with length n', function() {
var unsupportedFunctionNames = ['identical'];
for (var prop in R) {
if (typeof R[prop] === 'function' && R[prop].length > 0 && unsupportedFunctionNames.indexOf(prop) === -1) {
var result = R[prop](R.__);
eq(typeof result, 'function');
eq(result.length, R[prop].length);
}
}
});
it('-- applying function f with length n (where n > 1) to any value other than R.__ gives function with length n - 1', function() {
var testPartialApplication = function(fn, name) {
if (fn.length > 1) {
var result = fn(null);
eq(typeof result, 'function');
eq(result.length, fn.length - 1);
testPartialApplication(result, name + "'");
}
};
for (var prop in R) {
if (typeof R[prop] === 'function') {
testPartialApplication(R[prop], prop);
}
}
});
});