-
Notifications
You must be signed in to change notification settings - Fork 28
/
clone.test.ts
38 lines (30 loc) · 850 Bytes
/
clone.test.ts
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
import clone from "./clone.ts";
import { assertEquals, assertNotStrictEquals } from "testing/asserts.ts";
Deno.test("clone", () => {
assertEquals(clone(1), 1);
assertEquals(clone(null), null);
assertEquals(clone("foo"), "foo");
{
const v = [1, "a", { foo: ["bar", { baz: [[2, 3]] }, "a"] }];
assertEquals(clone(v), v);
assertNotStrictEquals(clone(v), v);
}
{
const v: any = {};
v.p = v;
const cloned = clone(v);
assertEquals(cloned, v);
assertNotStrictEquals(cloned, v);
assertEquals(cloned.p, cloned);
assertNotStrictEquals(cloned.p, v);
}
{
const v: any = { foo: {} };
v.foo.bar = v;
const cloned = clone(v);
assertEquals(cloned, v);
assertNotStrictEquals(cloned, v);
assertEquals(cloned.foo.bar, cloned);
assertNotStrictEquals(cloned.foo.bar, v);
}
});