forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlength.js
41 lines (33 loc) · 1.29 KB
/
length.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('length', function() {
it('returns the length of a list', function() {
eq(R.length([]), 0);
eq(R.length(['a', 'b', 'c', 'd']), 4);
});
it('returns the length of a string', function() {
eq(R.length(''), 0);
eq(R.length('xyz'), 3);
});
it('returns the length of a function', function() {
eq(R.length(function() {}), 0);
eq(R.length(function(x, y, z) { return z; }), 3);
});
it('returns the length of an arguments object', function() {
eq(R.length((function() { return arguments; })()), 0);
eq(R.length((function() { return arguments; })('x', 'y', 'z')), 3);
});
it('returns NaN for value of unexpected type', function() {
eq(R.identical(NaN, R.length(0)), true);
eq(R.identical(NaN, R.length({})), true);
eq(R.identical(NaN, R.length(null)), true);
eq(R.identical(NaN, R.length(undefined)), true);
});
it('returns NaN for length property of unexpected type', function() {
eq(R.identical(NaN, R.length({length: ''})), true);
eq(R.identical(NaN, R.length({length: '1.23'})), true);
eq(R.identical(NaN, R.length({length: null})), true);
eq(R.identical(NaN, R.length({length: undefined})), true);
eq(R.identical(NaN, R.length({})), true);
});
});