2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-10-28 08:07:56 +00:00
|
|
|
|
2023-12-12 03:51:35 +00:00
|
|
|
import { extract } from "./yaml.ts";
|
2022-10-28 08:07:56 +00:00
|
|
|
import {
|
|
|
|
runExtractTypeErrorTests,
|
2024-05-28 01:14:52 +00:00
|
|
|
runExtractYamlTests1,
|
|
|
|
runExtractYamlTests2,
|
2022-10-28 08:07:56 +00:00
|
|
|
} from "./_test_utils.ts";
|
2024-08-16 09:29:36 +00:00
|
|
|
import { assertEquals } from "@std/assert/equals";
|
2022-10-28 08:07:56 +00:00
|
|
|
|
2024-02-27 08:35:41 +00:00
|
|
|
Deno.test("yaml() extracts type error on invalid input", () => {
|
2023-12-12 03:51:35 +00:00
|
|
|
runExtractTypeErrorTests("yaml", extract);
|
2022-10-28 08:07:56 +00:00
|
|
|
});
|
|
|
|
|
2024-02-27 08:35:41 +00:00
|
|
|
Deno.test("yaml() parses yaml delineate by `---`", async () => {
|
2024-05-28 01:14:52 +00:00
|
|
|
await runExtractYamlTests1(extract);
|
2022-10-28 08:07:56 +00:00
|
|
|
});
|
|
|
|
|
2024-02-27 08:35:41 +00:00
|
|
|
Deno.test("yaml() parses yaml delineate by `---yaml`", async () => {
|
2024-05-28 01:14:52 +00:00
|
|
|
await runExtractYamlTests2(extract);
|
2022-10-28 08:07:56 +00:00
|
|
|
});
|
2024-08-16 09:29:36 +00:00
|
|
|
|
|
|
|
Deno.test("extractYaml() allows whitespaces after the header", () => {
|
|
|
|
assertEquals(extract("--- \nfoo: 0\n---\n").attrs, { foo: 0 });
|
|
|
|
assertEquals(extract("---yaml \nfoo: 0\n--- \n").attrs, { foo: 0 });
|
|
|
|
assertEquals(extract("= yaml = \nfoo: 0\n---\n").attrs, { foo: 0 });
|
|
|
|
});
|
2024-08-21 06:41:53 +00:00
|
|
|
|
|
|
|
Deno.test("extractYaml() parses with schema options", () => {
|
|
|
|
assertEquals(
|
|
|
|
extract("---\ndate: 2024-08-20\n---\n", { schema: "json" }).attrs,
|
|
|
|
{
|
|
|
|
date: "2024-08-20",
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|