Skip to content

Commit 886bcff

Browse files
test(shared): focus token rollover regression coverage
1 parent 48ec278 commit 886bcff

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

‎packages/shared/src/usageFormat.test.ts‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@ import {
1212
} from "./usageFormat.ts";
1313

1414
describe("formatTokens", () => {
15-
it.each([
16-
[999, "999"],
17-
[999.6, "1K"],
18-
[1_234, "1.23K"],
19-
[999_499, "999K"],
20-
[999_600, "1M"],
21-
[12_345_678, "12.3M"],
22-
[999_600_000, "1B"],
23-
[-999_600, "-1M"],
24-
[Number.NaN, "NaN"],
25-
])("formats %s as %s", (value, expected) => {
26-
expect(formatTokens(value)).toBe(expected);
15+
it("promotes units when three-significant-figure rounding reaches the next unit", () => {
16+
expect(formatTokens(999.6)).toBe("1K");
17+
expect(formatTokens(999_600)).toBe("1M");
18+
expect(formatTokens(999_600_000)).toBe("1B");
19+
expect(formatTokens(999_600_000_000)).toBe("1T");
20+
});
21+
22+
it("preserves ordinary counts below the rollover boundary", () => {
23+
expect(formatTokens(0)).toBe("0");
24+
expect(formatTokens(999.4)).toBe("999");
25+
expect(formatTokens(1_234)).toBe("1.23K");
26+
expect(formatTokens(999_499)).toBe("999K");
27+
expect(formatTokens(12_345_678)).toBe("12.3M");
28+
});
29+
30+
it("preserves negative signs and NaN", () => {
31+
expect(formatTokens(-999_600)).toBe("-1M");
32+
expect(formatTokens(Number.NaN)).toBe("NaN");
2733
});
2834
});
2935

0 commit comments

Comments
 (0)