Skip to content

Commit

Permalink
test: update render result checks
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Mar 13, 2024
1 parent 127f34b commit f751441
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
28 changes: 1 addition & 27 deletions 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, [
Expand All @@ -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]
`,
))
28 changes: 28 additions & 0 deletions 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]
`,
))
5 changes: 3 additions & 2 deletions changelog/render_sts.ts
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions 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]"),
)

0 comments on commit f751441

Please sign in to comment.