2024-07-30 23:24:17 +08:00
|
|
|
import { assertEquals } from "@std/assert";
|
2024-07-06 21:07:40 +08:00
|
|
|
import { cleanupJSON, deepEqual, deepObjectMerge } from "./json.ts";
|
2024-02-29 22:25:28 +08:00
|
|
|
|
|
|
|
Deno.test("utils", () => {
|
|
|
|
assertEquals(deepEqual({ a: 1 }, { a: 1 }), true);
|
|
|
|
assertEquals(deepObjectMerge({ a: 1 }, { a: 2 }), { a: 2 });
|
|
|
|
assertEquals(
|
|
|
|
deepObjectMerge({ list: [1, 2, 3] }, { list: [4, 5, 6] }),
|
|
|
|
{ list: [1, 2, 3, 4, 5, 6] },
|
|
|
|
);
|
|
|
|
assertEquals(deepObjectMerge({ a: { b: 1 } }, { a: { c: 2 } }), {
|
|
|
|
a: { b: 1, c: 2 },
|
|
|
|
});
|
2024-07-06 21:07:40 +08:00
|
|
|
assertEquals(cleanupJSON({ "a.b": 1 }), { a: { b: 1 } });
|
|
|
|
assertEquals(cleanupJSON({ a: { "a.b": 1 } }), {
|
2024-02-29 22:25:28 +08:00
|
|
|
a: { a: { b: 1 } },
|
|
|
|
});
|
2024-07-06 21:07:40 +08:00
|
|
|
assertEquals(cleanupJSON({ a: [{ "a.b": 1 }] }), {
|
2024-02-29 22:25:28 +08:00
|
|
|
a: [{ a: { b: 1 } }],
|
|
|
|
});
|
2024-07-30 23:24:17 +08:00
|
|
|
assertEquals(
|
|
|
|
cleanupJSON(new Date("2023-05-13T12:30:00Z")),
|
|
|
|
"2023-05-13T12:30:00.000Z",
|
|
|
|
);
|
2024-07-07 03:52:03 +08:00
|
|
|
assertEquals(cleanupJSON(new Date("2023-05-03T00:00:00Z")), "2023-05-03");
|
2024-02-29 22:25:28 +08:00
|
|
|
});
|