mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
Co-authored-by: argszero <argszero@users.noreply.github.com> Co-authored-by: Tarquinen <78942835+Tarquinen@users.noreply.github.com>
20 lines
829 B
TypeScript
20 lines
829 B
TypeScript
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")
|
||
})
|