1'use strict'; 2 3var test = require('tape'); 4var utils = require('../lib/utils'); 5 6test('merge()', function (t) { 7 t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key'); 8 9 var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } }); 10 t.deepEqual(oneMerged, { foo: ['bar', { first: '123' }] }, 'merges a standalone and an object into an array'); 11 12 var twoMerged = utils.merge({ foo: ['bar', { first: '123' }] }, { foo: { second: '456' } }); 13 t.deepEqual(twoMerged, { foo: { 0: 'bar', 1: { first: '123' }, second: '456' } }, 'merges a standalone and two objects into an array'); 14 15 var sandwiched = utils.merge({ foo: ['bar', { first: '123', second: '456' }] }, { foo: 'baz' }); 16 t.deepEqual(sandwiched, { foo: ['bar', { first: '123', second: '456' }, 'baz'] }, 'merges an object sandwiched by two standalones into an array'); 17 18 var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] }); 19 t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] }); 20 21 t.end(); 22}); 23 24test('assign()', function (t) { 25 var target = { a: 1, b: 2 }; 26 var source = { b: 3, c: 4 }; 27 var result = utils.assign(target, source); 28 29 t.equal(result, target, 'returns the target'); 30 t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged'); 31 t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched'); 32 33 t.end(); 34}); 35