forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnAry.js
48 lines (38 loc) · 1.39 KB
/
nAry.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
var assert = require('assert');
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('nAry', function() {
function toArray(args) { return Array.prototype.slice.call(args, 0); }
it('turns multiple-argument function into a nullary one', function() {
var fn = R.nAry(0, function(x, y, z) { void z; return toArray(arguments); });
eq(fn.length, 0);
eq(fn(1, 2, 3), []);
});
it('turns multiple-argument function into a ternary one', function() {
var fn = R.nAry(3, function(a, b, c, d) { void d; return toArray(arguments); });
eq(fn.length, 3);
eq(fn(1, 2, 3, 4), [1, 2, 3]);
eq(fn(1), [1, undefined, undefined]);
});
it('creates functions of arity less than or equal to ten', function() {
var fn = R.nAry(10, function() { return toArray(arguments); });
eq(fn.length, 10);
eq(fn.apply(null, R.range(0, 25)), R.range(0, 10));
var undefs = fn();
var ns = R.repeat(undefined, 10);
eq(undefs.length, ns.length);
var idx = undefs.length - 1;
while (idx >= 0) {
eq(undefs[idx], ns[idx]);
idx -= 1;
}
});
it('throws if n is greater than ten', function() {
assert.throws(function() {
R.nAry(11, function() {});
}, function(err) {
return (err instanceof Error &&
err.message === 'First argument to nAry must be a non-negative integer no greater than ten');
});
});
});