deno.land / std@0.224.0 / front_matter / create_extractor_test.ts

create_extractor_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertThrows } from "../assert/mod.ts";import { parse as parseYAML } from "../yaml/parse.ts";import { parse as parseTOML } from "../toml/parse.ts";import { resolveTestDataPath, runExtractJSONTests, runExtractTOMLTests, runExtractTypeErrorTests, runExtractYAMLTests1, runExtractYAMLTests2,} from "./_test_utils.ts";import { createExtractor, type Parser } from "./create_extractor.ts";
const extractYAML = createExtractor({ "yaml": parseYAML as Parser });const extractTOML = createExtractor({ "toml": parseTOML as Parser });const extractJSON = createExtractor({ "json": JSON.parse as Parser });const extractYAMLOrJSON = createExtractor({ "yaml": parseYAML as Parser, "json": JSON.parse as Parser,});const extractAny = createExtractor({ "yaml": parseYAML as Parser, "json": JSON.parse as Parser, "toml": parseTOML as Parser,});
// YAML //
Deno.test("createExtractor() extracts yaml type error on invalid input", () => { runExtractTypeErrorTests("yaml", extractYAML);});
Deno.test("createExtractor() parses yaml delineate by `---`", async () => { await runExtractYAMLTests1(extractYAML);});
Deno.test("createExtractor() parses yaml delineate by `---yaml`", async () => { await runExtractYAMLTests2(extractYAML);});
Deno.test({ name: "createExtractor() handles text between horizontal rules should not be recognized", async fn() { const str = await Deno.readTextFile( resolveTestDataPath("./horizontal_rules.md"), );
assertThrows( () => { extractAny(str); }, TypeError, "Unsupported front matter format", ); },});
// JSON //
Deno.test("createExtractor() extracts json type error on invalid input", () => { runExtractTypeErrorTests("json", extractJSON);});
Deno.test("createExtractor() parses json delineate by ---json", async () => { await runExtractJSONTests(extractJSON);});
// TOML //
Deno.test("createExtractor() extracts toml type error on invalid input", () => { runExtractTypeErrorTests("toml", extractTOML);});
Deno.test("createExtractor() parses toml delineate by ---toml", async () => { await runExtractTOMLTests(extractTOML);});
// MULTIPLE FORMATS //
Deno.test("createExtractor() parses yaml or json input", async () => { await runExtractYAMLTests1(extractYAMLOrJSON); await runExtractYAMLTests2(extractYAMLOrJSON); await runExtractJSONTests(extractYAMLOrJSON);});
Deno.test("createExtractor() parses any input", async () => { await runExtractYAMLTests1(extractAny); await runExtractYAMLTests2(extractAny); await runExtractJSONTests(extractAny); await runExtractTOMLTests(extractAny);});
std

Version Info

Tagged at
3 weeks ago