|
Jared K. Smith |
b6ad37d |
'use strict';
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
require('mocha');
|
|
Jared K. Smith |
b6ad37d |
var assert = require('assert');
|
|
Jared K. Smith |
b6ad37d |
var clone = require('./');
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
describe('cloneDeep()', function() {
|
|
Jared K. Smith |
b6ad37d |
it('should clone arrays', function() {
|
|
Jared K. Smith |
b6ad37d |
assert.deepEqual(clone(['alpha', 'beta', 'gamma']), ['alpha', 'beta', 'gamma']);
|
|
Jared K. Smith |
b6ad37d |
assert.deepEqual(clone([1, 2, 3]), [1, 2, 3]);
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
var a = [{ 'a': 0 }, { 'b': 1 }];
|
|
Jared K. Smith |
b6ad37d |
var b = clone(a);
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
assert.deepEqual(b, a);
|
|
Jared K. Smith |
b6ad37d |
assert.deepEqual(b[0], a[0]);
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
var val = [0, 'a', {}, [{}], [function() {}], function() {}];
|
|
Jared K. Smith |
b6ad37d |
assert.deepEqual(clone(val), val);
|
|
Jared K. Smith |
b6ad37d |
});
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
it('should deep clone object', function() {
|
|
Jared K. Smith |
b6ad37d |
var one = {a: 'b'};
|
|
Jared K. Smith |
b6ad37d |
var two = clone(one);
|
|
Jared K. Smith |
b6ad37d |
two.c = 'd';
|
|
Jared K. Smith |
b6ad37d |
assert.notDeepEqual(one, two);
|
|
Jared K. Smith |
b6ad37d |
});
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
it('should deep clone arrays', function() {
|
|
Jared K. Smith |
b6ad37d |
var one = {a: 'b'};
|
|
Jared K. Smith |
b6ad37d |
var arr1 = [one];
|
|
Jared K. Smith |
b6ad37d |
var arr2 = clone(arr1);
|
|
Jared K. Smith |
b6ad37d |
one.c = 'd';
|
|
Jared K. Smith |
b6ad37d |
assert.notDeepEqual(arr1, arr2);
|
|
Jared K. Smith |
b6ad37d |
});
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
it('should return primitives', function() {
|
|
Jared K. Smith |
b6ad37d |
assert.equal(clone(0), 0);
|
|
Jared K. Smith |
b6ad37d |
assert.equal(clone('foo'), 'foo');
|
|
Jared K. Smith |
b6ad37d |
});
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
it('should clone a regex', function() {
|
|
Jared K. Smith |
b6ad37d |
assert.deepEqual(clone(/foo/g), /foo/g);
|
|
Jared K. Smith |
b6ad37d |
});
|
|
Jared K. Smith |
b6ad37d |
|
|
Jared K. Smith |
b6ad37d |
it('should clone objects', function() {
|
|
Jared K. Smith |
b6ad37d |
assert.deepEqual(clone({a: 1, b: 2, c: 3 }), {a: 1, b: 2, c: 3 });
|
|
Jared K. Smith |
b6ad37d |
});
|
|
Jared K. Smith |
b6ad37d |
});
|