utils.js 1.3 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var test = require('tape');
  3. var utils = require('../lib/utils');
  4. test('merge()', function (t) {
  5. t.deepEqual(utils.merge(null, true), [null, true], 'merges true into null');
  6. t.deepEqual(utils.merge(null, [42]), [null, 42], 'merges null into an array');
  7. t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
  8. var oneMerged = utils.merge({ foo: 'bar' }, { foo: { first: '123' } });
  9. t.deepEqual(oneMerged, { foo: ['bar', { first: '123' }] }, 'merges a standalone and an object into an array');
  10. var twoMerged = utils.merge({ foo: ['bar', { first: '123' }] }, { foo: { second: '456' } });
  11. t.deepEqual(twoMerged, { foo: { 0: 'bar', 1: { first: '123' }, second: '456' } }, 'merges a standalone and two objects into an array');
  12. var sandwiched = utils.merge({ foo: ['bar', { first: '123', second: '456' }] }, { foo: 'baz' });
  13. t.deepEqual(sandwiched, { foo: ['bar', { first: '123', second: '456' }, 'baz'] }, 'merges an object sandwiched by two standalones into an array');
  14. var nestedArrays = utils.merge({ foo: ['baz'] }, { foo: ['bar', 'xyzzy'] });
  15. t.deepEqual(nestedArrays, { foo: ['baz', 'bar', 'xyzzy'] });
  16. var noOptionsNonObjectSource = utils.merge({ foo: 'baz' }, 'bar');
  17. t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });
  18. t.end();
  19. });