mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
8b9a139472
* refactor(dotenv): add parse function and test * refactor(dotenv): escape single quotes in stringify function * refactor(dotenv): fix stringify function to correctly escape single quotes * refactor(dotenv): fix stringify function to correctly escape single quotes * tweak --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
87 lines
1.8 KiB
TypeScript
87 lines
1.8 KiB
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assertEquals } from "@std/assert";
|
|
import { stringify } from "./stringify.ts";
|
|
|
|
Deno.test("stringify()", async (t) => {
|
|
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=`,
|
|
),
|
|
);
|
|
await t.step("handles single-quote characters", () =>
|
|
assertEquals(
|
|
stringify({ PARSE: "par'se" }),
|
|
`PARSE="par'se"`,
|
|
));
|
|
});
|