forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmergeLeft.js
60 lines (48 loc) · 1.63 KB
/
mergeLeft.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
var assert = require('assert');
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('mergeLeft', function() {
it('takes two objects, merges their own properties and returns a new object', function() {
var a = {w: 1, x: 2};
var b = {y: 3, z: 4};
eq(R.mergeLeft(a, b), {w: 1, x: 2, y: 3, z: 4});
});
it('overrides properties in the second object with properties in the first object', function() {
var a = {w: 1, x: 2};
var b = {w: 100, y: 3, z: 4};
eq(R.mergeLeft(a, b), {w: 1, x: 2, y: 3, z: 4});
});
it('is not destructive', function() {
var a = {w: 1, x: 2};
var res = R.mergeLeft(a, {x: 3, y: 4});
assert.notStrictEqual(a, res);
eq(res, {w: 1, x: 2, y: 4});
});
it('reports only own properties', function() {
var a = {w: 1, x: 2};
function Cla() {}
Cla.prototype.x = 5;
eq(R.mergeLeft(new Cla(), a), {w: 1, x: 2});
eq(R.mergeLeft(a, new Cla()), {w: 1, x: 2});
});
it('is shallow', function() {
var a = { x: { u: 1, v: 2 }, y: 0 };
var b = { x: { u: 3, w: 4 }, z: 0 };
var res = R.mergeLeft(a, b);
assert.strictEqual(a.x, res.x);
eq(res, { x: { u: 1, v: 2 }, y: 0, z: 0 });
});
describe('acts as if nil values are simply empty objects', function() {
var a = {w: 1, x: 2};
var b = {w: 100, y: 3, z: 4};
it('... if the first object is nil', function() {
eq(R.mergeLeft(null, b), b);
});
it('... if the second object is nil', function() {
eq(R.mergeLeft(a, undefined), a);
});
it('... if both objects are nil', function() {
eq(R.mergeLeft(null, undefined), {});
});
});
});