Make English the repository working language (#5)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,30 +17,30 @@ import {
|
||||
} from "../src/lib/format";
|
||||
|
||||
describe("humanizeTokens", () => {
|
||||
it("小于 1000 原样输出", () => {
|
||||
it("below 1000 unchanged", () => {
|
||||
expect(humanizeTokens(0)).toBe("0");
|
||||
expect(humanizeTokens(999)).toBe("999");
|
||||
});
|
||||
|
||||
it("千位缩写并去掉多余的 .0", () => {
|
||||
it("thousands abbreviated, dropping a trailing .0", () => {
|
||||
expect(humanizeTokens(1000)).toBe("1k");
|
||||
expect(humanizeTokens(1234)).toBe("1.2k");
|
||||
expect(humanizeTokens(4000)).toBe("4k");
|
||||
});
|
||||
|
||||
it("百万缩写", () => {
|
||||
it("millions abbreviated", () => {
|
||||
expect(humanizeTokens(1_500_000)).toBe("1.5M");
|
||||
expect(humanizeTokens(2_000_000)).toBe("2M");
|
||||
});
|
||||
|
||||
it("负数保留符号(上下文回落)", () => {
|
||||
it("negatives keep the sign (context shrink)", () => {
|
||||
expect(humanizeTokens(-1200)).toBe("-1.2k");
|
||||
expect(humanizeTokens(-500)).toBe("-500");
|
||||
});
|
||||
});
|
||||
|
||||
describe("humanizeDuration", () => {
|
||||
it("毫秒/秒/分钟折算", () => {
|
||||
it("ms/s/min conversion", () => {
|
||||
expect(humanizeDuration(820)).toBe("820ms");
|
||||
expect(humanizeDuration(2300)).toBe("2.3s");
|
||||
expect(humanizeDuration(5100)).toBe("5.1s");
|
||||
@@ -50,7 +50,7 @@ describe("humanizeDuration", () => {
|
||||
});
|
||||
|
||||
describe("signedDelta", () => {
|
||||
it("非负补 +,负数自带 -", () => {
|
||||
it("non-negative gets +, negative already has -", () => {
|
||||
expect(signedDelta("1k")).toBe("+1k");
|
||||
expect(signedDelta("-1k")).toBe("-1k");
|
||||
expect(signedDelta("0")).toBe("+0");
|
||||
@@ -58,19 +58,19 @@ describe("signedDelta", () => {
|
||||
});
|
||||
|
||||
describe("formatMoney", () => {
|
||||
it("无 pricing 显示 —", () => {
|
||||
it("no pricing shows —", () => {
|
||||
expect(formatMoney(null)).toBe("—");
|
||||
expect(formatMoney(undefined)).toBe("—");
|
||||
});
|
||||
|
||||
it("缺省按美元、按量级取小数位", () => {
|
||||
it("defaults to USD, decimal places scale with magnitude", () => {
|
||||
expect(formatMoney(0)).toBe("$0");
|
||||
expect(formatMoney(0.1234)).toBe("$0.1234");
|
||||
expect(formatMoney(1.5)).toBe("$1.50");
|
||||
expect(formatMoney(150)).toBe("$150");
|
||||
});
|
||||
|
||||
it("人民币按 1:7 折算", () => {
|
||||
it("CNY converted at 1:7", () => {
|
||||
expect(formatMoney(0, "CNY")).toBe("¥0");
|
||||
expect(formatMoney(1, "CNY")).toBe("¥7.00");
|
||||
expect(formatMoney(0.01, "CNY")).toBe("¥0.0700");
|
||||
@@ -78,14 +78,14 @@ describe("formatMoney", () => {
|
||||
});
|
||||
|
||||
describe("formatPercent", () => {
|
||||
it("四舍五入到整数百分比(缓存命中率)", () => {
|
||||
it("rounds to a whole percent (cache hit rate)", () => {
|
||||
expect(formatPercent(0)).toBe("0%");
|
||||
expect(formatPercent(0.714)).toBe("71%");
|
||||
expect(formatPercent(0.716)).toBe("72%");
|
||||
expect(formatPercent(1)).toBe("100%");
|
||||
});
|
||||
|
||||
it("null / 非有限值(输入为 0,命中率无从谈起)显示 —", () => {
|
||||
it("null / non-finite (zero input, hit rate undefined) shows —", () => {
|
||||
expect(formatPercent(null)).toBe("—");
|
||||
expect(formatPercent(undefined)).toBe("—");
|
||||
expect(formatPercent(Number.NaN)).toBe("—");
|
||||
@@ -94,7 +94,7 @@ describe("formatPercent", () => {
|
||||
});
|
||||
|
||||
describe("formatBytes", () => {
|
||||
it("字节缩写", () => {
|
||||
it("byte abbreviation", () => {
|
||||
expect(formatBytes(812)).toBe("812B");
|
||||
expect(formatBytes(3481)).toBe("3.4KB");
|
||||
expect(formatBytes(2 * 1024 * 1024)).toBe("2MB");
|
||||
@@ -102,32 +102,32 @@ describe("formatBytes", () => {
|
||||
});
|
||||
|
||||
describe("computeTps", () => {
|
||||
it("输出 token ÷ LLM 秒数(已知量核对)", () => {
|
||||
it("output tokens ÷ LLM seconds (known-value check)", () => {
|
||||
expect(computeTps(900, 3000)).toBe(300); // 900 / 3s
|
||||
expect(computeTps(1500, 2000)).toBe(750); // 1500 / 2s
|
||||
});
|
||||
|
||||
it("llmMs ≤ 0(无计时)返回 null,避免除零", () => {
|
||||
it("llmMs ≤ 0 (no timing) returns null, avoiding division by zero", () => {
|
||||
expect(computeTps(900, 0)).toBeNull();
|
||||
expect(computeTps(900, -5)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatTps", () => {
|
||||
it("小于 1000 保留一位小数(去掉多余的 .0)", () => {
|
||||
it("below 1000 keeps one decimal place (dropping a trailing .0)", () => {
|
||||
expect(formatTps(42.53)).toBe("42.5 tok/s");
|
||||
expect(formatTps(120)).toBe("120 tok/s");
|
||||
expect(formatTps(300)).toBe("300 tok/s");
|
||||
expect(formatTps(999.9)).toBe("999.9 tok/s");
|
||||
});
|
||||
|
||||
it("不小于 1000 按 k / M 量级缩写(与 humanizeTokens 同口径)", () => {
|
||||
it("1000 and above abbreviates by k / M magnitude (same convention as humanizeTokens)", () => {
|
||||
expect(formatTps(1000)).toBe("1k tok/s");
|
||||
expect(formatTps(37_783.4)).toBe("37.8k tok/s");
|
||||
expect(formatTps(1_200_000)).toBe("1.2M tok/s");
|
||||
});
|
||||
|
||||
it("null / 非有限值显示 —", () => {
|
||||
it("null / non-finite shows —", () => {
|
||||
expect(formatTps(null)).toBe("—");
|
||||
expect(formatTps(undefined)).toBe("—");
|
||||
expect(formatTps(Number.NaN)).toBe("—");
|
||||
@@ -145,30 +145,30 @@ describe("formatRelativeDays", () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("同日「今天」,与当天几点无关", () => {
|
||||
it("same day is today, regardless of the hour", () => {
|
||||
expect(formatRelativeDays(new Date(2026, 6, 15, 0, 5).toISOString(), "zh")).toBe("今天");
|
||||
expect(formatRelativeDays(new Date(2026, 6, 15, 23, 59).toISOString(), "en")).toBe("today");
|
||||
});
|
||||
|
||||
it("隔日「昨天」,更早按日历日差「n 天前」(含跨月)", () => {
|
||||
it("one day back is yesterday, earlier by calendar-day difference as n days ago (across months)", () => {
|
||||
expect(formatRelativeDays(new Date(2026, 6, 14, 23, 0).toISOString(), "zh")).toBe("昨天");
|
||||
expect(formatRelativeDays(new Date(2026, 6, 14, 1, 0).toISOString(), "en")).toBe("yesterday");
|
||||
expect(formatRelativeDays(new Date(2026, 6, 10, 8, 0).toISOString(), "zh")).toBe("5 天前");
|
||||
expect(formatRelativeDays(new Date(2026, 5, 5, 8, 0).toISOString(), "en")).toBe("40 days ago");
|
||||
});
|
||||
|
||||
it("未来时间(时钟偏差)回落到绝对时间", () => {
|
||||
it("future time (clock skew) falls back to the absolute time", () => {
|
||||
const future = new Date(2026, 6, 20, 8, 5).toISOString();
|
||||
expect(formatRelativeDays(future, "zh")).toBe(formatDateTime(future));
|
||||
expect(formatRelativeDays(future, "zh")).toBe("2026-07-20 08:05");
|
||||
});
|
||||
|
||||
it("解析失败原样返回", () => {
|
||||
it("parse failure returns the input unchanged", () => {
|
||||
expect(formatRelativeDays("not-a-date", "zh")).toBe("not-a-date");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatRelativeDate(技能卡片的语义化更新时间)", () => {
|
||||
describe("formatRelativeDate (semantic update time on Skill cards)", () => {
|
||||
// Fix "now" to local 2026-07-15 12:00 (same convention as formatRelativeDays).
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
@@ -178,14 +178,14 @@ describe("formatRelativeDate(技能卡片的语义化更新时间)", () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("同日「今天更新 / updated today」,与当天几点无关", () => {
|
||||
it("same day is updated today, regardless of the hour", () => {
|
||||
expect(formatRelativeDate(new Date(2026, 6, 15, 0, 5).toISOString(), "zh")).toBe("今天更新");
|
||||
expect(formatRelativeDate(new Date(2026, 6, 15, 23, 59).toISOString(), "en")).toBe(
|
||||
"updated today",
|
||||
);
|
||||
});
|
||||
|
||||
it("隔日「昨天更新」,更早按日历日差「n 天前更新」(含跨月)", () => {
|
||||
it("one day back is updated yesterday, earlier as updated n days ago by calendar-day difference (across months)", () => {
|
||||
expect(formatRelativeDate(new Date(2026, 6, 14, 23, 0).toISOString(), "zh")).toBe("昨天更新");
|
||||
expect(formatRelativeDate(new Date(2026, 6, 14, 1, 0).toISOString(), "en")).toBe(
|
||||
"updated yesterday",
|
||||
@@ -196,11 +196,11 @@ describe("formatRelativeDate(技能卡片的语义化更新时间)", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("未来时间(时钟偏差)回落到日期本身(不加「更新」措辞)", () => {
|
||||
it("future time (clock skew) falls back to the date itself (without the updated wording)", () => {
|
||||
expect(formatRelativeDate("2026-07-20", "zh")).toBe("2026-07-20");
|
||||
});
|
||||
|
||||
it("解析失败原样返回", () => {
|
||||
it("parse failure returns the input unchanged", () => {
|
||||
expect(formatRelativeDate("not-a-date", "zh")).toBe("not-a-date");
|
||||
expect(formatRelativeDate("", "en")).toBe("");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user