|
| 1 | +import { describe, expect, it } from "vite-plus/test"; |
| 2 | + |
| 3 | +import { sanitizeCommitSubject } from "./textGenerationUtils.ts"; |
| 4 | + |
| 5 | +describe("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 | +}); |
0 commit comments