|
| 1 | +import { describe, expect, test } from "vitest"; |
| 2 | +import { remark } from "remark"; |
| 3 | +import type { Compatible } from "vfile"; |
| 4 | +import remarkCapitalizeTitles from "../index.ts"; |
| 5 | + |
| 6 | +const processMarkdown = async (value: Compatible) => { |
| 7 | + const file = await remark().use(remarkCapitalizeTitles).process(value); |
| 8 | + return file.toString().slice(0, -1); |
| 9 | +}; |
| 10 | + |
| 11 | +describe("Handles the basics", () => { |
| 12 | + test("title-cases a simple heading", async () => { |
| 13 | + expect( |
| 14 | + await processMarkdown("# cloning: not just for mad scientists"), |
| 15 | + ).toBe("# Cloning: Not Just for Mad Scientists"); |
| 16 | + }); |
| 17 | + |
| 18 | + test("leaves non-heading text untouched", async () => { |
| 19 | + expect( |
| 20 | + await processMarkdown( |
| 21 | + "git mindwiped: fully discarding changes\n\n# git mindwiped: fully discarding changes", |
| 22 | + ), |
| 23 | + ).toBe( |
| 24 | + "git mindwiped: fully discarding changes\n\n# Git Mindwiped: Fully Discarding Changes", |
| 25 | + ); |
| 26 | + }); |
| 27 | +}); |
| 28 | + |
| 29 | +describe("Preserves special cases", () => { |
| 30 | + test("preserves GitHub, FujoCoded, LLC, and NPM", async () => { |
| 31 | + expect( |
| 32 | + await processMarkdown( |
| 33 | + "## merging with github's interface: pull requests", |
| 34 | + ), |
| 35 | + ).toBe("## Merging with GitHub's Interface: Pull Requests"); |
| 36 | + expect(await processMarkdown("### an intro to fujocoded llc")).toBe( |
| 37 | + "### An Intro to FujoCoded LLC", |
| 38 | + ); |
| 39 | + expect(await processMarkdown("## next up: building with npm")).toBe( |
| 40 | + "## Next Up: Building with NPM", |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + test("preserves SHA", async () => { |
| 45 | + expect(await processMarkdown("#### sha: your commit's unique name")).toBe( |
| 46 | + "#### SHA: Your Commit's Unique Name", |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + test("preserves TL;DR", async () => { |
| 51 | + expect(await processMarkdown("# tl;dr: why this matters")).toBe( |
| 52 | + "# TL;DR: Why This Matters", |
| 53 | + ); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +describe("Respects tricky punctuations", () => { |
| 58 | + test("handles curly quotes (as produced by smartypants)", async () => { |
| 59 | + expect( |
| 60 | + await processMarkdown( |
| 61 | + "#### “answer me, darling~”: git & github’s connection check!", |
| 62 | + ), |
| 63 | + ).toBe("#### “Answer Me, Darling~”: Git & GitHub’s Connection Check!"); |
| 64 | + }); |
| 65 | + |
| 66 | + test("handles apostrophes inside a word", async () => { |
| 67 | + expect( |
| 68 | + await processMarkdown("## git'ing good: more commit scenarios"), |
| 69 | + ).toBe("## Git'ing Good: More Commit Scenarios"); |
| 70 | + }); |
| 71 | + |
| 72 | + test("handles a trailing question mark with an inner apostrophe", async () => { |
| 73 | + expect(await processMarkdown("## i'm ready to practice, now what?")).toBe( |
| 74 | + "## I'm Ready to Practice, Now What?", |
| 75 | + ); |
| 76 | + }); |
| 77 | + |
| 78 | + test("handles repeated punctuation (???)", async () => { |
| 79 | + expect(await processMarkdown("### step ???: git advanced")).toBe( |
| 80 | + "### Step ???: Git Advanced", |
| 81 | + ); |
| 82 | + }); |
| 83 | + |
| 84 | + test("handles a leading ellipsis", async () => { |
| 85 | + expect(await processMarkdown("### ...and more!")).toBe("### ...and More!"); |
| 86 | + }); |
| 87 | + |
| 88 | + test("handles parenthesized possessives", async () => { |
| 89 | + expect( |
| 90 | + await processMarkdown("### traveling through (your code's) history"), |
| 91 | + ).toBe("### Traveling Through (Your Code's) History"); |
| 92 | + }); |
| 93 | +}); |
| 94 | + |
| 95 | +describe("Handles inline code spans", () => { |
| 96 | + test("handles an inline code span inside a heading", async () => { |
| 97 | + expect( |
| 98 | + await processMarkdown( |
| 99 | + "### the flavors of `git reset`: soft, hard, or mixed", |
| 100 | + ), |
| 101 | + ).toBe("### The Flavors of `git reset`: Soft, Hard, or Mixed"); |
| 102 | + }); |
| 103 | + |
| 104 | + test("handles multiple inline code spans with separators", async () => { |
| 105 | + expect(await processMarkdown("## git & github's `push`/`pull` dance")).toBe( |
| 106 | + "## Git & GitHub's `push`/`pull` Dance", |
| 107 | + ); |
| 108 | + }); |
| 109 | + |
| 110 | + test("handles punctuation immediately following an inline code span", async () => { |
| 111 | + expect( |
| 112 | + await processMarkdown("## multiverse collapse: prepare to `merge`!"), |
| 113 | + ).toBe("## Multiverse Collapse: Prepare to `merge`!"); |
| 114 | + }); |
| 115 | + |
| 116 | + test("handles a comma-separated list of inline code spans with a hyphenated term", async () => { |
| 117 | + expect( |
| 118 | + await processMarkdown( |
| 119 | + "#### the jokes write themselves: `ours`, `theirs`, and three-way merges", |
| 120 | + ), |
| 121 | + ).toBe( |
| 122 | + "#### The Jokes Write Themselves: `ours`, `theirs`, and Three-way Merges", |
| 123 | + ); |
| 124 | + }); |
| 125 | +}); |
| 126 | + |
| 127 | +describe("Handles hyphenated compound words", () => { |
| 128 | + test("keeps the second word lowercase in a hyphenated name with a possessive", async () => { |
| 129 | + expect( |
| 130 | + await processMarkdown("### our toy project: boba-tan's sexyman shrine"), |
| 131 | + ).toBe("### Our Toy Project: Boba-tan's Sexyman Shrine"); |
| 132 | + }); |
| 133 | + |
| 134 | + test("handles hyphenated words alongside a slash separator", async () => { |
| 135 | + expect(await processMarkdown("## push/pull: git's memory-sync dance")).toBe( |
| 136 | + "## Push/pull: Git's Memory-sync Dance", |
| 137 | + ); |
| 138 | + }); |
| 139 | + |
| 140 | + test("handles common hyphenated prefixes", async () => { |
| 141 | + expect( |
| 142 | + await processMarkdown("### pre-commit hooks for post-merge cleanups"), |
| 143 | + ).toBe("### Pre-commit Hooks for Post-merge Cleanups"); |
| 144 | + }); |
| 145 | + |
| 146 | + test("handles hyphenated phrases with small words inside", async () => { |
| 147 | + expect(await processMarkdown("## up-to-date and ready-to-merge")).toBe( |
| 148 | + "## Up-to-date and Ready-to-merge", |
| 149 | + ); |
| 150 | + }); |
| 151 | +}); |
0 commit comments