Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { detectComposerTrigger, serializeComposerFileLink } from "./composerTrigger.ts";
4
5describe("detectComposerTrigger", () => {
6 it.each([
7 ["Run /tmp/build.sh", "Run /tmp/build.sh".length],
8 ["/etc/hosts", "/etc/hosts".length],
9 ["Use /etc/hosts now", "Use /et".length],
10 ])("keeps the path in %j out of the slash menu", (text, cursor) => {
11 expect(detectComposerTrigger(text, cursor)).toBeNull();
12 });
13
14 it("keeps a slash in the line-leading model picker query", () => {
15 expect(detectComposerTrigger("/model openai/gpt", 17)).toMatchObject({
16 kind: "slash-model",
17 query: "openai/gpt",
18 });
19 });
20
21 it.each(["Use /", "Use /review"])("detects the inline slash token in %j", (text) => {
22 expect(detectComposerTrigger(text, text.length)).toEqual({
23 kind: "slash-command",
24 query: text.slice(5),
25 rangeStart: 4,
26 rangeEnd: text.length,
27 });
28 });
29
30 it.each(["Use/review", "https://example.com/review", "Use /review "])(
31 "does not trigger for %j",
32 (text) => expect(detectComposerTrigger(text, text.length)).toBeNull(),
33 );
34
35 it.each(["$", "€", "𑿝"])("detects %s skill prefixes and their source range", (prefix) => {
36 const text = `Use ${prefix}review`;
37 expect(detectComposerTrigger(text, text.length)).toEqual({
38 kind: "skill",
39 query: "review",
40 rangeStart: 4,
41 rangeEnd: text.length,
42 });
43 });
44
45 it.each([
46 "It costs $5",
47 "budget $9.99",
48 "only $.99",
49 "about €20",
50 "raise $10k",
51 "$1,000",
52 "£2e6",
53 "raise $10k.",
54 "is it $5?",
55 "(about $9.99)",
56 ])("does not open the skill menu for the amount in %j", (text) =>
57 expect(detectComposerTrigger(text, text.length)).toBeNull(),
58 );
59
60 it.each(["$", "$1password", "$2fa"])("still detects the skill prefix %j", (text) => {
61 expect(detectComposerTrigger(text, text.length)).toMatchObject({
62 kind: "skill",
63 query: text.slice(1),
64 });
65 });
66});
67
68describe("serializeComposerFileLink", () => {
69 it("encodes markdown-sensitive destination characters", () => {
70 expect(serializeComposerFileLink("docs/My File (draft).md")).toBe(
71 "[My File (draft).md](docs/My%20File%20%28draft%29.md)",
72 );
73 });
74
75 it("supports windows paths", () => {
76 expect(serializeComposerFileLink("C:\\repo\\src\\index.ts")).toBe(
77 "[index.ts](C:%5Crepo%5Csrc%5Cindex.ts)",
78 );
79 });
80
81 it("preserves paths that legitimately start with an at sign", () => {
82 expect(serializeComposerFileLink("@scope/package.json")).toBe(
83 "[package.json](@scope/package.json)",
84 );
85 });
86});