-
Notifications
You must be signed in to change notification settings - Fork 28
/
equal.test.ts
57 lines (51 loc) · 1.5 KB
/
equal.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import equal from "./equal.ts";
import { assert, assertEquals } from "testing/asserts.ts";
Deno.test("equal", () => {
assert(equal(1, 1));
assertEquals(equal(1, 2), false);
assertEquals(equal(1, "1"), false);
assert(equal("1", "1"));
assert(equal(null, null));
assertEquals(equal(null, undefined), false);
assertEquals(equal(null, {}), false);
assert(equal([], []));
assertEquals(equal([], {}), false);
assertEquals(equal([], [1]), false);
assert(equal([1], [1]));
assertEquals(equal([1], [1, "a"]), false);
assert(equal([1, "a"], [1, "a"]));
assertEquals(equal([1, [2, [3, [4, 5], 6]]], []), false);
assert(equal([1, [2, [3, [4, 5], 6]]], [1, [2, [3, [4, 5], 6]]]));
{
const obj = {};
assert(equal(obj, obj));
assert(equal(obj, {}));
}
assertEquals(equal({ foo: "bar" }, { foo: "baz" }), false);
assert(equal({ foo: "bar" }, { foo: "bar" }));
assertEquals(equal({ foo: "bar" }, { foo: "bar", bar: "baz" }), false);
assertEquals(equal({ a: { b: { c: "d" }, e: "f" } }, {}), false);
assertEquals(
equal({ a: { b: { c: "d" }, e: "f" } }, { a: { b: { c: "d" }, e: "f" } }),
true,
);
assertEquals(
equal({ a: [{ b: 1 }, { c: [[{ d: ["e"] }]] }] }, { foo: [] }),
false,
);
assertEquals(
equal(
{ a: [{ b: 1 }, { c: [[{ d: ["e"] }]] }] },
{ a: [{ b: 1 }, { c: [[{ d: ["e"] }]] }] },
),
true,
);
{
const fun = () => {};
assert(equal(fun, fun));
assertEquals(
equal(fun, () => {}),
false,
);
}
});