Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2โ
3import { truncate } from "./String.ts";
4โ
5describe("truncate", () => {
6 it("cuts by Unicode code point so emoji stay whole", () => {
7 expect(truncate("๐๐๐", 5)).toBe("๐๐๐");
8 expect(truncate("๐๐๐๐", 3)).toBe("๐๐๐...");
9 });
10โ
11 it("trims before measuring", () => {
12 expect(truncate(" hello ", 5)).toBe("hello");
13 });
14โ
15 it("drops whitespace at the cut before the ellipsis", () => {
16 expect(truncate("hello world", 6)).toBe("hello...");
17 });
18โ
19 it("moves the cut back so combining marks stay with their base", () => {
20 expect(truncate("cafe\u0301!", 4)).toBe("caf...");
21 expect(truncate("เคจเคฎเคธเฅเคคเฅ", 3)).toBe("เคจเคฎ...");
22 expect(truncate("เธเนเธฒเธเธเธตเน", 6)).toBe("เธเนเธฒเธ...");
23 expect(truncate("\u26A0\uFE0F\u26A0\uFE0F", 3)).toBe("\u26A0\uFE0F...");
24 });
25});