Skip to content

Commit 28efe08

Browse files
committed
added test for #11, #12
1 parent 86481e2 commit 28efe08

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,58 @@ describe('deepcopy', function() {
385385
assert(functionInArrayInArray.a[1][1] === copiedFunctionInArrayInArray.a[1][1]);
386386
});
387387

388+
it('can copy deeper Object and Array', function() {
389+
const array = [
390+
1,
391+
2,
392+
[
393+
3,
394+
4,
395+
[
396+
function() {},
397+
6,
398+
7
399+
]
400+
]
401+
];
402+
403+
const copiedArray = deepcopy(array);
404+
405+
assert(array !== copiedArray);
406+
assert(array[0] === copiedArray[0]);
407+
assert(array[1] === copiedArray[1]);
408+
assert(array[2] !== copiedArray[2]);
409+
assert(array[2][0] === copiedArray[2][0]);
410+
assert(array[2][1] === copiedArray[2][1]);
411+
assert(array[2][2] !== copiedArray[2][2]);
412+
assert(array[2][2][0] !== copiedArray[2][2][0]);
413+
assert(array[2][2][1] === copiedArray[2][2][1]);
414+
assert(array[2][2][2] === copiedArray[2][2][2]);
415+
416+
const object = {
417+
a: 'a',
418+
b: 'b',
419+
c: {
420+
d: function() {},
421+
e: {
422+
f: 'f',
423+
g: 'g'
424+
}
425+
}
426+
};
427+
428+
const copiedObject = deepcopy(object);
429+
430+
assert(object !== copiedObject);
431+
assert(object.a === copiedObject.a);
432+
assert(object.b === copiedObject.b);
433+
assert(object.c !== copiedObject.c);
434+
assert(object.c.d !== copiedObject.c.d);
435+
assert(object.c.e !== copiedObject.c.e);
436+
assert(object.c.e.f === copiedObject.c.e.f);
437+
assert(object.c.e.g === copiedObject.c.e.g);
438+
});
439+
388440
it('can copy Class from Array and Object by customizer', function() {
389441
function MyClass(number) {
390442
this.number = +number;

0 commit comments

Comments
 (0)