forked from lodash/lodash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat.js
65 lines (49 loc) · 1.7 KB
/
concat.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
import assert from 'assert';
import lodashStable from 'lodash';
import concat from '../concat.js';
describe('concat', function() {
it('should shallow clone `array`', function() {
var array = [1, 2, 3],
actual = concat(array);
assert.deepStrictEqual(actual, array);
assert.notStrictEqual(actual, array);
});
it('should concat arrays and values', function() {
var array = [1],
actual = concat(array, 2, [3], [[4]]);
assert.deepStrictEqual(actual, [1, 2, 3, [4]]);
assert.deepStrictEqual(array, [1]);
});
it('should cast non-array `array` values to arrays', function() {
var values = [, null, undefined, false, true, 1, NaN, 'a'];
var expected = lodashStable.map(values, function(value, index) {
return index ? [value] : [];
});
var actual = lodashStable.map(values, function(value, index) {
return index ? concat(value) : concat();
});
assert.deepStrictEqual(actual, expected);
expected = lodashStable.map(values, function(value) {
return [value, 2, [3]];
});
actual = lodashStable.map(values, function(value) {
return concat(value, [2], [[3]]);
});
assert.deepStrictEqual(actual, expected);
});
it('should treat sparse arrays as dense', function() {
var expected = [],
actual = concat(Array(1), Array(1));
expected.push(undefined, undefined);
assert.ok('0'in actual);
assert.ok('1' in actual);
assert.deepStrictEqual(actual, expected);
});
it('should return a new wrapped array', function() {
var array = [1],
wrapped = _(array).concat([2, 3]),
actual = wrapped.value();
assert.deepEqual(array, [1]);
assert.deepEqual(actual, [1, 2, 3]);
});
});