@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 49 lines 2.28 KB
Raw
1 import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
2 import { describe, expect, it } from "vite-plus/test";
3
4 import { nativePullRequestMarkdown } from "./pullRequestAutolinks";
5
6 const github = changeRequestReferenceAutolinker({
7 provider: "github",
8 url: "https://github.com/team/repo/pull/8",
9 });
10
11 describe("nativePullRequestMarkdown", () => {
12 it("links the host's references in prose", () => {
13 expect(nativePullRequestMarkdown("Closes #123, see @julius", github, false).markdown).toBe(
14 "Closes [#123](https://github.com/team/repo/issues/123), see [@julius](https://github.com/julius)",
15 );
16 });
17
18 it("leaves code, links, images, escapes and definitions alone", () => {
19 const text =
20 "`#123 @person abc1234`\n\n```\n#123\n```\n\n[#123](https://example.com) ![#123](image.png) https://example.com/#123 user@example.com \\#123 1234567\n\n[ref]: https://example.com/#123";
21 expect(nativePullRequestMarkdown(text, github, false).markdown).toBe(text);
22 });
23
24 it("does not nest links inside HTML anchors or code", () => {
25 const text = 'See <a href="https://example.com">#12</a> and <code>#13</code>, then #14.';
26 expect(nativePullRequestMarkdown(text, github, false).markdown).toBe(
27 'See <a href="https://example.com">#12</a> and <code>#13</code>, then [#14](https://github.com/team/repo/issues/14).',
28 );
29 });
30
31 it("leaves markdown unchanged for a host that links nothing", () => {
32 const forgejo = changeRequestReferenceAutolinker({
33 provider: "forgejo",
34 url: "https://codeberg.org/acme/web/pulls/7",
35 });
36 expect(nativePullRequestMarkdown("Closes #123", forgejo, false).markdown).toBe("Closes #123");
37 });
38
39 it("expands GitHub emoji aliases in prose and link labels, mapping offsets back", () => {
40 const text =
41 "- [ ] Ship :tada: #1 `:tada:`\n- [ ] [:+1: docs](https://x.dev/:tada:) https://x.dev/:tada: :asterisk:";
42 const native = nativePullRequestMarkdown(text, github, true);
43 expect(native.markdown).toBe(
44 "- [ ] Ship 🎉 [#1](https://github.com/team/repo/issues/1) `:tada:`\n- [ ] [👍 docs](https://x.dev/:tada:) https://x.dev/:tada: \\*️⃣",
45 );
46 const marker = native.markdown.lastIndexOf("[ ]");
47 expect(native.sourceOffset(marker)).toBe(text.lastIndexOf("[ ]"));
48 });
49 });