Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(front-matter): simplify asserts #6475

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions front_matter/json_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,24 @@ don't break
{Also: "---json this shouldn't be a problem"}
`;

const content = extract<Record<string, unknown>>(input);
assertEquals(
content.frontMatter,
`{
const actual = extract(input);
const expected = {
frontMatter: `{
"title": "Three dashes followed by the format marks the spot",
"tags": [
"json",
"front-matter"
],
"expanded-description": "with some ---json 🙃 crazy stuff in it"
}`,
);
assertEquals(
content.body,
"don't break\n---\n{Also: \"---json this shouldn't be a problem\"}\n",
);
assertEquals(
content.attrs.title,
"Three dashes followed by the format marks the spot",
);
assertEquals(content.attrs.tags, ["json", "front-matter"]);
assertEquals(
content.attrs["expanded-description"],
"with some ---json 🙃 crazy stuff in it",
);
body: "don't break\n---\n{Also: \"---json this shouldn't be a problem\"}\n",
attrs: {
title: "Three dashes followed by the format marks the spot",
tags: ["json", "front-matter"],
"expanded-description": "with some ---json 🙃 crazy stuff in it",
},
};
assertEquals(actual, expected);
});

Deno.test("extractJson() allows whitespaces after the header", () => {
Expand Down
29 changes: 11 additions & 18 deletions front_matter/toml_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,19 @@ don't break
---
Also = '---toml this shouldn't be a problem'
`;
const content = extract<Record<string, unknown>>(input);
assertEquals(
content.frontMatter,
`title = 'Three dashes followed by the format marks the spot'
const actual = extract<Record<string, unknown>>(input);
const expected = {
frontMatter: `title = 'Three dashes followed by the format marks the spot'
tags = ['toml', 'front-matter']
'expanded-description' = 'with some ---toml 👌 crazy stuff in it'`,
);
assertEquals(
content.body,
"don't break\n---\nAlso = '---toml this shouldn't be a problem'\n",
);
assertEquals(
content.attrs.title,
"Three dashes followed by the format marks the spot",
);
assertEquals(content.attrs.tags, ["toml", "front-matter"]);
assertEquals(
content.attrs["expanded-description"],
"with some ---toml 👌 crazy stuff in it",
);
body: "don't break\n---\nAlso = '---toml this shouldn't be a problem'\n",
attrs: {
title: "Three dashes followed by the format marks the spot",
tags: ["toml", "front-matter"],
"expanded-description": "with some ---toml 👌 crazy stuff in it",
},
};
assertEquals(actual, expected);
});

Deno.test("toml() parses toml delineate by +++", () => {
Expand Down
60 changes: 28 additions & 32 deletions front_matter/yaml_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Deno.test("yaml() extracts type error on invalid input", () => {
assertThrows(() => extract("---\nasdasdasd"));
});

Deno.test("yaml() parses yaml delineate by `---`", () => {
Deno.test("yaml() parses yaml delineated by `---`", () => {
const input = `---
title: Three dashes marks the spot
tags:
Expand All @@ -29,29 +29,27 @@ don't break
---
Also this shouldn't be a problem
`;
const content = extract<Record<string, unknown>>(input);
assertEquals(
content.frontMatter,
`title: Three dashes marks the spot

const expected = {
frontMatter: `title: Three dashes marks the spot
tags:
- yaml
- front-matter
- dashes
expanded-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["expanded-description"],
"with some --- crazy stuff in it",
);
body: "don't break\n---\nAlso this shouldn't be a problem\n",
attrs: {
title: "Three dashes marks the spot",
tags: ["yaml", "front-matter", "dashes"],
"expanded-description": "with some --- crazy stuff in it",
},
};

const content = extract<Record<string, unknown>>(input);
assertEquals(content, expected);
});

Deno.test("yaml() parses yaml delineate by `---yaml`", () => {
Deno.test("yaml() parses yaml delineated by `---yaml`", () => {
const input = `---yaml
title: Three dashes marks the spot
tags:
Expand All @@ -64,26 +62,24 @@ don't break
---
Also this shouldn't be a problem
`;
const content = extract<Record<string, unknown>>(input);
assertEquals(
content.frontMatter,
`title: Three dashes marks the spot

const expected = {
frontMatter: `title: Three dashes marks the spot
tags:
- yaml
- front-matter
- dashes
expanded-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["expanded-description"],
"with some --- crazy stuff in it",
);
body: "don't break\n---\nAlso this shouldn't be a problem\n",
attrs: {
title: "Three dashes marks the spot",
tags: ["yaml", "front-matter", "dashes"],
"expanded-description": "with some --- crazy stuff in it",
},
};

const content = extract<Record<string, unknown>>(input);
assertEquals(content, expected);
});

Deno.test("extractYaml() allows whitespaces after the header", () => {
Expand Down
Loading