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

textGenerationUtils.test.ts

33 lines1.4 KB

1import { describe, expect, it } from "vite-plus/test";
2โ€‹
3import { sanitizeCommitSubject } from "./textGenerationUtils.ts";
4โ€‹
5describe("sanitizeCommitSubject", () => {
6 it.each([
7 { name: "an emoji", prefixLength: 71, character: "๐Ÿš€" },
8 { name: "an accented character", prefixLength: 71, character: "e\u0301" },
9 { name: "an emoji with a skin tone", prefixLength: 70, character: "๐Ÿ‘๐Ÿฝ" },
10 { name: "a flag", prefixLength: 69, character: "๐Ÿ‡ฎ๐Ÿ‡น" },
11 { name: "a joined emoji", prefixLength: 65, character: "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ" },
12 ])("keeps $name intact at the subject limit", ({ prefixLength, character }) => {
13 const prefix = "a".repeat(prefixLength);
14โ€‹
15 expect(sanitizeCommitSubject(`${prefix}${character} more`)).toBe(prefix);
16 });
17โ€‹
18 it("keeps a complete character that ends exactly at the limit", () => {
19 const expected = `${"a".repeat(70)}๐Ÿš€`;
20โ€‹
21 expect(sanitizeCommitSubject(`${expected} more`)).toBe(expected);
22 });
23โ€‹
24 it("uses the existing fallback when a single character exceeds the limit", () => {
25 expect(sanitizeCommitSubject(`a${"\u0301".repeat(72)} more`)).toBe("Update project files");
26 });
27โ€‹
28 it("keeps the existing ASCII limit and subject normalization", () => {
29 expect(sanitizeCommitSubject("a".repeat(80))).toBe("a".repeat(72));
30 expect(sanitizeCommitSubject(" Fix tests...\nignored ")).toBe("Fix tests");
31 expect(sanitizeCommitSubject("...")).toBe("Update project files");
32 });
33});