|
1 | 1 | import { workspaceRelativeFilePath } from "./path.ts"; |
2 | 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | +import { serializeComposerFileLink } from "./composerTrigger.ts"; |
3 | 4 | import { extractMarkdownLinkHrefs, resolveMarkdownFileLinkTarget } from "./markdownLinks.ts"; |
4 | 5 |
|
5 | 6 | import { |
@@ -38,16 +39,38 @@ describe("parseMarkdownFileLink", () => { |
38 | 39 | ["C:%5Crepo%5Cimage.png", "C:\\repo\\image.png"], |
39 | 40 | ["</D:/Programme/t3code/ChatMarkdown.tsx:1>", "D:/Programme/t3code/ChatMarkdown.tsx"], |
40 | 41 | ["file://localhost/home/me/notes.md", "/home/me/notes.md"], |
| 42 | + ["app/routes/posts.$postId.tsx", "app/routes/posts.$postId.tsx"], |
| 43 | + ["src/routes/+page.svelte", "src/routes/+page.svelte"], |
| 44 | + ["app/(marketing)/page.tsx:12", "app/(marketing)/page.tsx"], |
| 45 | + ["pages/posts/%5Bid%5D.tsx", "pages/posts/[id].tsx"], |
| 46 | + ["+page.svelte", "+page.svelte"], |
| 47 | + ["[id].tsx", "[id].tsx"], |
41 | 48 | ])("recognizes %s as a file", (href, path) => { |
42 | 49 | expect(parseMarkdownFileLink(href)?.path).toBe(path); |
43 | 50 | }); |
44 | 51 |
|
45 | | - it.each(["https://example.com/docs", "/chat/settings#L3", "TODO:12", "patches"])( |
46 | | - "does not treat %s as a file", |
47 | | - (href) => { |
48 | | - expect(parseMarkdownFileLink(href)).toBeNull(); |
49 | | - }, |
50 | | - ); |
| 52 | + it.each([ |
| 53 | + "app/routes/posts.$postId.tsx", |
| 54 | + "pages/posts/[id].tsx", |
| 55 | + "docs/My File (draft).md", |
| 56 | + "@scope/package.json", |
| 57 | + "$postId.tsx", |
| 58 | + ])("reads back the composer's link to %s", (path) => { |
| 59 | + const destination = /\]\((.*)\)$/.exec(serializeComposerFileLink(path))?.[1]; |
| 60 | + expect(parseMarkdownFileLink(destination ?? "")?.path).toBe(path); |
| 61 | + }); |
| 62 | + |
| 63 | + it.each([ |
| 64 | + "https://example.com/docs", |
| 65 | + "/chat/settings#L3", |
| 66 | + "TODO:12", |
| 67 | + "patches", |
| 68 | + |
| 69 | + "foo(bar)", |
| 70 | + "$HOME", |
| 71 | + ])("does not treat %s as a file", (href) => { |
| 72 | + expect(parseMarkdownFileLink(href)).toBeNull(); |
| 73 | + }); |
51 | 74 |
|
52 | 75 | it("recognizes a relative folder that ends in a slash", () => { |
53 | 76 | expect(parseMarkdownFileLink("patches/")).toEqual({ path: "patches/" }); |
|
0 commit comments