Skip to content

g1t/apps/web/app/lib/inline-markdown.test.ts

37 lines1,653 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { inlineParts, inlinePlain } from "./inline-markdown.ts";
5
6test("bold, italic, code and links read as marks", () => {
7 assert.deepEqual(inlineParts("**Conflict resolved.** The conflict was in `module.exports`."), [
8 { kind: "strong", text: "Conflict resolved." },
9 { kind: "text", text: " The conflict was in " },
10 { kind: "code", text: "module.exports" },
11 { kind: "text", text: "." },
12 ]);
13 assert.deepEqual(inlineParts("in sudo (**Platform → Incidents**, `https://sudo.g1t.sh/incidents`)"), [
14 { kind: "text", text: "in sudo (" },
15 { kind: "strong", text: "Platform → Incidents" },
16 { kind: "text", text: ", " },
17 { kind: "code", text: "https://sudo.g1t.sh/incidents" },
18 { kind: "text", text: ")" },
19 ]);
20 assert.deepEqual(inlineParts("an *important* step, see [the docs](https://docs.g1t.sh/)"), [
21 { kind: "text", text: "an " },
22 { kind: "em", text: "important" },
23 { kind: "text", text: " step, see the docs" },
24 ]);
25});
26
27test("what is not a mark stays as written", () => {
28 assert.deepEqual(inlineParts("snake_case_name and 2 * 3 * 4"), [{ kind: "text", text: "snake_case_name and 2 * 3 * 4" }]);
29 assert.deepEqual(inlineParts("**Conflicts resolved:**"), [{ kind: "strong", text: "Conflicts resolved:" }]);
30 assert.deepEqual(inlineParts(""), []);
31 // Inside code, nothing else is read.
32 assert.deepEqual(inlineParts("`a **b** c`"), [{ kind: "code", text: "a **b** c" }]);
33});
34
35test("the plain words, for a tooltip", () => {
36 assert.equal(inlinePlain("**Done.** Wrote `math.js`."), "Done. Wrote math.js.");
37});