deno.land / std@0.158.0 / encoding / front_matter_test.ts

front_matter_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
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { extract, test } from "./front_matter.ts";import { assert, assertEquals, assertThrows } from "../testing/asserts.ts";
Deno.test("test valid input true", () => { [ "---\nname: deno\n---\n", "= yaml =\nname: deno\n= yaml =\n", "= yaml =\nname: deno\n= yaml =\ndeno is awesome\n", ].forEach((str) => { assert(test(str)); });});
Deno.test("test invalid input false", () => { [ "", "---", "= yaml =", "---\n", "= yaml =\n", "---\nasdasdasd", ].forEach((str) => { assert(!test(str)); });});
Deno.test("extract type error on invalid input", () => { [ "", "---", "= yaml =", "---\n", "= yaml =\n", "---\nasdasdasd", ].forEach((str) => { assertThrows(() => extract(str), TypeError); });});
Deno.test("parse yaml delinetead by `---`", () => { const content = extract< { title: string; tags: string[]; "expaned-description": string } >(`---title: Three dashes marks the spottags: - yaml - front-matter - dashesexpaned-description: with some --- crazy stuff in it---don't break---Also this shouldn't be a problem`); assert(content !== undefined); assertEquals( content.frontMatter, `title: Three dashes marks the spottags: - yaml - front-matter - dashesexpaned-description: with some --- crazy stuff in it`, ); assertEquals( content.body, "don't break\n---\nAlso this shouldn't be a problem\n", ); assertEquals(content.attrs.title, "Three dashes marks the spot"); assertEquals(content.attrs.tags, ["yaml", "front-matter", "dashes"]); assertEquals( content.attrs["expaned-description"], "with some --- crazy stuff in it", );});
std

Version Info

Tagged at
a year ago