Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import {
3 enrichedLinkVariantPattern,
4 enrichedSkillLinkRegex,
5 ENRICHED_INLINE_FILE_LINK_REGEX,
6} from "./enrichedLinkPresentation";
7
8describe("Enriched link presentation", () => {
9 it("recognizes file-shaped code without turning commands or URLs into links", () => {
10 for (const path of [
11 "src/app.tsx",
12 "./README.md",
13 "/tmp/report.md",
14 "C:\\repo\\app.tsx",
15 "app.tsx:12:3",
16 ]) {
17 expect(ENRICHED_INLINE_FILE_LINK_REGEX.test(path), path).toBe(true);
18 }
19 for (const text of [
20 "npm run dev",
21 "port:3000",
22 "TODO:12",
23 "example.com",
24 "https://example.com/app.tsx",
25 "x + y",
26 "README.md",
27 "/app/settings",
28 ]) {
29 expect(ENRICHED_INLINE_FILE_LINK_REGEX.test(text), text).toBe(false);
30 }
31 });
32
33 it("only recognizes complete known skill names and escapes their punctuation", () => {
34 const regex = enrichedSkillLinkRegex([{ name: "check" }, { name: "check.mobile" }]);
35 expect(regex?.exec("Try $check.mobile next")?.[0]).toBe("$check.mobile");
36 expect(regex?.exec("Try $check-mobile next")).toBeNull();
37 expect(regex?.exec("Try $checkXmobile next")).toBeNull();
38 expect(regex?.exec("prefix$check next")).toBeNull();
39 expect(enrichedSkillLinkRegex([])).toBeNull();
40 });
41
42 it("matches only the complete URL, including literal regex metacharacters", () => {
43 const url = "file:///workspace/app[1].tsx?line=3+4";
44 const pattern = new RegExp(enrichedLinkVariantPattern(url));
45 expect(pattern.test(url)).toBe(true);
46 expect(pattern.test(`${url}/child`)).toBe(false);
47 expect(pattern.test("file:///workspace/app1Xtsx?line=34")).toBe(false);
48 });
49});