forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat.js
40 lines (31 loc) · 1.06 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
var assert = require('assert');
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('concat', function() {
var z1 = {
x: 'z1',
concat: function(that) { return this.x + ' ' + that.x; }
};
var z2 = {
x: 'z2'
};
it('adds combines the elements of the two lists', function() {
eq(R.concat(['a', 'b'], ['c', 'd']), ['a', 'b', 'c', 'd']);
eq(R.concat([], ['c', 'd']), ['c', 'd']);
});
it('works on strings', function() {
eq(R.concat('foo', 'bar'), 'foobar');
eq(R.concat('x', ''), 'x');
eq(R.concat('', 'x'), 'x');
eq(R.concat('', ''), '');
});
it('delegates to non-String object with a concat method, as second param', function() {
eq(R.concat(z1, z2), 'z1 z2');
});
it('throws if attempting to combine an array with a non-array', function() {
assert.throws(function() { return R.concat([1], 2); }, TypeError);
});
it('throws if not an array, String, or object with a concat method', function() {
assert.throws(function() { return R.concat({}, {}); }, TypeError);
});
});