|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
2 | 2 |
|
3 | | -import { collectComposerInlineTokens } from "./composerInlineTokens.ts"; |
| 3 | +import { collectComposerInlineTokens, composerMathRanges } from "./composerInlineTokens.ts"; |
| 4 | +import { serializeComposerFileLink } from "./composerTrigger.ts"; |
4 | 5 |
|
5 | 6 | describe("collectComposerInlineTokens", () => { |
6 | 7 | it("collects file links, mentions, and skills with source ranges", () => { |
@@ -217,4 +218,46 @@ describe("collectComposerInlineTokens", () => { |
217 | 218 | "$real-skill", |
218 | 219 | ]); |
219 | 220 | }); |
| 221 | + |
| 222 | + it.each([ |
| 223 | + "app/routes/posts.$postId.tsx", |
| 224 | + "src/routes/_chat.$environmentId.$threadId.tsx", |
| 225 | + "pages/posts/[id].tsx", |
| 226 | + "app/blog/[...slug].tsx", |
| 227 | + ])("keeps a file link whose name looks like TeX as one mention: %s", (path) => { |
| 228 | + const link = serializeComposerFileLink(path); |
| 229 | + expect(collectComposerInlineTokens(`fix ${link} please`)).toMatchObject([ |
| 230 | + { type: "mention", value: path, source: link }, |
| 231 | + ]); |
| 232 | + }); |
| 233 | + |
| 234 | + it.each(["app/routes/posts.$postId.tsx", "pages/posts/[id].tsx"])( |
| 235 | + "preserves a confirmed TeX-like pill when its trailing delimiter is removed: %s", |
| 236 | + (path) => { |
| 237 | + const link = serializeComposerFileLink(path); |
| 238 | + const confirmed = collectComposerInlineTokens(`fix ${link} `); |
| 239 | + |
| 240 | + expect(confirmed).toMatchObject([{ type: "mention", value: path, source: link }]); |
| 241 | + expect( |
| 242 | + collectComposerInlineTokens(`fix ${link}`, { preserveTrailingFrom: confirmed }), |
| 243 | + ).toEqual(confirmed); |
| 244 | + expect(collectComposerInlineTokens(`fix ${link}`)).toEqual([]); |
| 245 | + }, |
| 246 | + ); |
| 247 | + |
| 248 | + it.each([ |
| 249 | + "before $x + @README.md$ after", |
| 250 | + "before \\(x + @README.md\\) after", |
| 251 | + "\\[x + @README.md\\] after", |
| 252 | + "\\[\\text{use @README.md}\\] then go ", |
| 253 | + ])("keeps a mention that ends a formula inside the formula: %s", (source) => { |
| 254 | + expect(collectComposerInlineTokens(source)).toEqual([]); |
| 255 | + }); |
| 256 | + |
| 257 | + it("still finds a formula after a mention that starts the line", () => { |
| 258 | + const link = serializeComposerFileLink("app/routes/posts.$postId.tsx"); |
| 259 | + expect(composerMathRanges(`${link} sets $x_i$`).map((formula) => formula.source)).toEqual([ |
| 260 | + "$x_i$", |
| 261 | + ]); |
| 262 | + }); |
220 | 263 | }); |
0 commit comments