locale.test.ts 618 B

1234567891011121314
  1. import { expect, test } from "bun:test"
  2. import { Locale } from "../../src/util/locale"
  3. test("truncates text from the right by terminal width", () => {
  4. expect(Locale.truncateWidth("abcdefgh", 5)).toBe("abcd…")
  5. expect(Locale.truncateWidth("ab界cd", 5)).toBe("ab界…")
  6. expect(Locale.truncateWidth("abcdefgh", 1)).toBe("…")
  7. expect(Locale.truncateWidth("abcdefgh", 0)).toBe("")
  8. })
  9. test("takes whole graphemes within terminal width", () => {
  10. expect(Locale.takeWidth("ab界cd", 4)).toBe("ab界")
  11. expect(Locale.graphemes("a👨‍👩‍👧‍👦b")).toEqual(["a", "👨‍👩‍👧‍👦", "b"])
  12. })