Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composerTrigger.test.ts

44 lines1.3 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { detectComposerTrigger, serializeComposerFileLink } from "./composerTrigger.ts";
4​
5describe("detectComposerTrigger", () => {
6 it.each(["$", "€", "£", "¥", "₹", "₩", "₿", "𑿝"])(
7 "detects %s skill prefixes and their source range",
8 (prefix) => {
9 const text = `Use ${prefix}review`;
10 expect(detectComposerTrigger(text, text.length)).toEqual({
11 kind: "skill",
12 query: "review",
13 rangeStart: 4,
14 rangeEnd: text.length,
15 });
16 },
17 );
18});
19​
20describe("serializeComposerFileLink", () => {
21 it("uses the basename as the markdown label", () => {
22 expect(serializeComposerFileLink("path/to/package.json")).toBe(
23 "[package.json](path/to/package.json)",
24 );
25 });
26​
27 it("encodes markdown-sensitive destination characters", () => {
28 expect(serializeComposerFileLink("docs/My File (draft).md")).toBe(
29 "[My File (draft).md](docs/My%20File%20%28draft%29.md)",
30 );
31 });
32​
33 it("supports windows paths", () => {
34 expect(serializeComposerFileLink("C:\\repo\\src\\index.ts")).toBe(
35 "[index.ts](C:%5Crepo%5Csrc%5Cindex.ts)",
36 );
37 });
38​
39 it("preserves paths that legitimately start with an at sign", () => {
40 expect(serializeComposerFileLink("@scope/package.json")).toBe(
41 "[package.json](@scope/package.json)",
42 );
43 });
44});