opencode/packages/tui/test/util/locale.test.ts
2026-07-28 17:12:07 -04:00

14 lines
618 B
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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