diff --git a/changelog/changelog_test.ts b/changelog/changelog_test.ts index 480d9de..b51a997 100644 --- a/changelog/changelog_test.ts +++ b/changelog/changelog_test.ts @@ -1,14 +1,12 @@ import { assertEquals } from "$std/assert/assert_equals.ts" -import { outdent } from "$dax/src/deps.ts" import { getSections, parseCommits } from "./mod.ts" -import { renderBBCode } from "./render_bbcode.ts" export const exampleCommits = parseCommits([ "feat: asdf (#1234)", "feat!: test (#123)", "fix(L10n): `language` stuff (#415)", ]) -const exampleSections = getSections(exampleCommits) +export const exampleSections = getSections(exampleCommits) Deno.test("parseCommits() correctly parse commits", () => { assertEquals(exampleCommits, [ @@ -35,27 +33,3 @@ Deno.test("parseCommits() correctly parse commits", () => { }, ]) }) - -Deno.test("renderBBCode() outputs identical text", () => - assertEquals( - renderBBCode({ version: "v1.0.0", date: "2024-03-12", sections: exampleSections }), - outdent` - [h1]v1.0.0 (2024-03-12)[/h1] - - [h2]Breaking Changes[/h2] - [list] - [*] test ([url=https://github.com/scarf005/marisa/pull/123]#123[/url]) - [/list] - - [h2]New Features[/h2] - [list] - [*] asdf ([url=https://github.com/scarf005/marisa/pull/1234]#1234[/url]) - [*] test ([url=https://github.com/scarf005/marisa/pull/123]#123[/url]) - [/list] - - [h2]Fixes[/h2] - [list] - [*] [i]language[/i] stuff ([url=https://github.com/scarf005/marisa/pull/415]#415[/url]) - [/list] - `, - )) diff --git a/changelog/render_bbcode_test.ts b/changelog/render_bbcode_test.ts new file mode 100644 index 0000000..c4792f9 --- /dev/null +++ b/changelog/render_bbcode_test.ts @@ -0,0 +1,28 @@ +import { assertEquals } from "$std/assert/assert_equals.ts" +import { outdent } from "$dax/src/deps.ts" +import { renderBBCode } from "./render_bbcode.ts" +import { exampleSections } from "./changelog_test.ts" + +Deno.test("renderBBCode() outputs identical text", () => + assertEquals( + renderBBCode({ version: "v1.0.0", date: "2024-03-12", sections: exampleSections }), + outdent` + [h1]v1.0.0 (2024-03-12)[/h1] + + [h2]Breaking Changes[/h2] + [list] + [*] test ([url=https://github.com/scarf005/marisa/pull/123]#123[/url]) + [/list] + + [h2]New Features[/h2] + [list] + [*] asdf ([url=https://github.com/scarf005/marisa/pull/1234]#1234[/url]) + [*] test ([url=https://github.com/scarf005/marisa/pull/123]#123[/url]) + [/list] + + [h2]Fixes[/h2] + [list] + [*] [i]language[/i] stuff ([url=https://github.com/scarf005/marisa/pull/415]#415[/url]) + [/list] + `, + )) diff --git a/changelog/render_sts.ts b/changelog/render_sts.ts index 13f31bc..de6f269 100644 --- a/changelog/render_sts.ts +++ b/changelog/render_sts.ts @@ -2,10 +2,11 @@ import { outdent } from "$dax/src/deps.ts" import { Commit } from "./mod.ts" import { ChangelogRenderer, renderSections, SectionFormatter } from "./render.ts" -const fmtCommit = (x: Commit) => +export const fmtCommit = (x: Commit) => `- ${x.subject}` - .replace(/`([^`]+)`/g, "[i]$1[/i]") + .replace(/`([^`]+)`/g, "[$1]") .replace(/\(#(\d+)\)/g, "") + .trim() const fmtSection: SectionFormatter = ([section, commits]) => `* ${section}\n\n` + commits.map(fmtCommit).join("\n") diff --git a/changelog/render_sts_test.ts b/changelog/render_sts_test.ts new file mode 100644 index 0000000..07a9aa6 --- /dev/null +++ b/changelog/render_sts_test.ts @@ -0,0 +1,8 @@ +import { assertEquals } from "$std/assert/assert_equals.ts" +import { Commit } from "./mod.ts" +import { fmtCommit } from "./render_sts.ts" + +Deno.test( + "fmtCommit() strips invalid characters", + () => assertEquals(fmtCommit({ subject: "`foo` (#123)" } as unknown as Commit), "- [foo]"), +)