The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { limitSection, sanitizeCommitSubject, sanitizeThreadTitle } from "./textGenerationUtils.ts"; |
| 4 | |
| 5 | describe("limitSection", () => { |
| 6 | it("cuts a long section without splitting an emoji", () => { |
| 7 | expect(limitSection(`${"a".repeat(9)}🚀 more`, 10)).toBe(`${"a".repeat(9)}\n\n[truncated]`); |
| 8 | }); |
| 9 | }); |
| 10 | |
| 11 | describe("sanitizeCommitSubject", () => { |
| 12 | // regression: #19181 truncation split grapheme clusters at the subject limit |
| 13 | it.each([ |
| 14 | { name: "an emoji", prefixLength: 71, character: "🚀" }, |
| 15 | { name: "an accented character", prefixLength: 71, character: "e\u0301" }, |
| 16 | { name: "a joined emoji", prefixLength: 65, character: "👨👩👧👦" }, |
| 17 | ])("keeps $name intact at the subject limit", ({ prefixLength, character }) => { |
| 18 | const prefix = "a".repeat(prefixLength); |
| 19 | |
| 20 | expect(sanitizeCommitSubject(`${prefix}${character} more`)).toBe(prefix); |
| 21 | }); |
| 22 | }); |
| 23 | |
| 24 | describe("sanitizeThreadTitle", () => { |
| 25 | it.each([ |
| 26 | { raw: '"Fix login redirect"', expected: "Fix login redirect" }, |
| 27 | { raw: `"Fix user's login"`, expected: "Fix user's login" }, |
| 28 | { raw: "Explain `vp check`", expected: "Explain `vp check`" }, |
| 29 | { raw: '"Open in" menu ignores Finder', expected: '"Open in" menu ignores Finder' }, |
| 30 | { raw: 'Rename "foo" to "bar"', expected: 'Rename "foo" to "bar"' }, |
| 31 | { raw: '"Open in" ignores "Finder"', expected: '"Open in" ignores "Finder"' }, |
| 32 | ])("unwraps only a quote pair around the whole title: $raw", ({ raw, expected }) => { |
| 33 | expect(sanitizeThreadTitle(raw)).toBe(expected); |
| 34 | }); |
| 35 | |
| 36 | it.each([ |
| 37 | { name: "a split surrogate pair", prefixLength: 116, character: "🚀", retained: "" }, |
| 38 | { name: "a complete surrogate pair", prefixLength: 115, character: "🚀", retained: "🚀" }, |
| 39 | { name: "a BMP character", prefixLength: 116, character: "界", retained: "界" }, |
| 40 | ])("truncates without splitting $name", ({ prefixLength, character, retained }) => { |
| 41 | const prefix = "a".repeat(prefixLength); |
| 42 | const title = `${prefix}${character} more`; |
| 43 | |
| 44 | expect(sanitizeThreadTitle(title)).toBe(`${prefix}${retained}...`); |
| 45 | }); |
| 46 | }); |