2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-11-29 04:34:25 +00:00
|
|
|
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2023-11-29 04:34:25 +00:00
|
|
|
import { stringify } from "./stringify.ts";
|
|
|
|
|
2023-12-20 10:01:13 +00:00
|
|
|
Deno.test("stringify()", async (t) => {
|
2023-11-29 04:34:25 +00:00
|
|
|
await t.step(
|
|
|
|
"basic",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ "BASIC": "basic" }),
|
|
|
|
`BASIC=basic`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await t.step(
|
|
|
|
"comment",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ "#COMMENT": "comment" }),
|
|
|
|
``,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await t.step(
|
|
|
|
"single quote",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ "QUOTED_SINGLE": "single quoted" }),
|
|
|
|
`QUOTED_SINGLE='single quoted'`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await t.step(
|
|
|
|
"multiline",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ "MULTILINE": "hello\nworld" }),
|
|
|
|
`MULTILINE="hello\\nworld"`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await t.step(
|
|
|
|
"whitespace",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ "WHITESPACE": " whitespace " }),
|
|
|
|
`WHITESPACE=' whitespace '`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await t.step(
|
|
|
|
"equals",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ "EQUALS": "equ==als" }),
|
|
|
|
`EQUALS='equ==als'`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await t.step(
|
|
|
|
"number",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ "THE_ANSWER": "42" }),
|
|
|
|
`THE_ANSWER=42`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await t.step(
|
|
|
|
"undefined",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify(
|
|
|
|
{ "UNDEFINED": undefined } as unknown as Record<string, string>,
|
|
|
|
),
|
|
|
|
`UNDEFINED=`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await t.step(
|
|
|
|
"null",
|
|
|
|
() =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ "NULL": null } as unknown as Record<string, string>),
|
|
|
|
`NULL=`,
|
|
|
|
),
|
|
|
|
);
|
2024-08-29 00:32:39 +00:00
|
|
|
await t.step("handles single-quote characters", () =>
|
|
|
|
assertEquals(
|
|
|
|
stringify({ PARSE: "par'se" }),
|
|
|
|
`PARSE="par'se"`,
|
|
|
|
));
|
2023-11-29 04:34:25 +00:00
|
|
|
});
|