opencode/packages/tui/test/util/locale.test.ts
argszero 2e7ac8c8ea
fix(tui): roll the compact form over to M at the rounding boundary (#55871)
Co-authored-by: argszero <argszero@users.noreply.github.com>
Co-authored-by: Tarquinen <78942835+Tarquinen@users.noreply.github.com>
2026-10-15 19:34:22 -04:00

20 lines
829 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"])
})
test("rolls the compact form over at the rounding boundary", () => {
expect(Locale.number(999949)).toBe("999.9K")
expect(Locale.number(999950)).toBe("1.0M")
expect(Locale.number(1000000)).toBe("1.0M")
})