forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (49 loc) · 1.53 KB
/
Copy pathindex.js
File metadata and controls
57 lines (49 loc) · 1.53 KB
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
var test = require('../util/test')(__filename);
var splitAt = require('../../packages/array-split-at');
test('splits array into two at a given position within the array bounds', function(t) {
t.deepEqual(splitAt([1, 2, 3, 4, 5], 2), [[1, 2], [3, 4, 5]]);
t.end();
});
test('splits array into two at a given position outside the array bounds', function(t) {
t.deepEqual(splitAt([1, 2, 3, 4, 5], 10), [[1, 2, 3, 4, 5], []]);
t.end();
});
test('splits array into two at a given negative position within the array bounds', function(t) {
t.deepEqual(splitAt([1, 2, 3, 4, 5], -1), [[1, 2, 3, 4], [5]]);
t.end();
});
test('splits array into two at a given negative position outside the array bounds', function(t) {
t.deepEqual(splitAt([1, 2, 3, 4, 5], -10), [[], [1, 2, 3, 4, 5]]);
t.end();
});
test('when no second argument, all elements go to second array', function(t) {
t.deepEqual(splitAt([1, 2, 3, 4, 5]), [[], [1, 2, 3, 4, 5]]);
t.end();
});
test('splits array into two at an empty array', function(t) {
t.deepEqual(splitAt([], 2), [[], []]);
t.end();
});
test('throws if first argument is not an array', function(t) {
t.plan(3);
t.throws(function() {
splitAt(undefined, 2);
});
t.throws(function() {
splitAt(null, 4);
});
t.throws(function() {
splitAt({}, 3);
});
t.end();
});
test('throws if second argument is not null/undefined or a number', function(t) {
t.plan(2);
t.throws(function() {
splitAt([1, 2, 3, 4], '2');
});
t.throws(function() {
splitAt([1, 2, 3, 4], {});
});
t.end();
});