mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
20 lines
943 B
JavaScript
20 lines
943 B
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { formatRelativeTime, interpolateMessage, translateMessage } from "./format.ts";
|
|
|
|
test("interpolates string and numeric parameters", () => {
|
|
assert.equal(interpolateMessage("Hello, {name} ({count})", { name: "Pi", count: 2 }), "Hello, Pi (2)");
|
|
});
|
|
|
|
test("falls back to English and returns the key when both are missing", () => {
|
|
assert.equal(translateMessage("zh-CN", "common.ok", { en: { "common.ok": "OK" }, "zh-CN": {} }), "OK");
|
|
assert.equal(translateMessage("zh-CN", "missing.key", { en: {}, "zh-CN": {} }), "missing.key");
|
|
});
|
|
|
|
test("formats relative time using the selected locale", () => {
|
|
const now = new Date("2026-01-01T00:00:00.000Z");
|
|
assert.equal(formatRelativeTime(new Date("2026-01-01T00:05:00.000Z"), "en", now), "in 5 minutes");
|
|
assert.equal(formatRelativeTime(new Date("2025-12-31T23:00:00.000Z"), "zh-CN", now), "1小时前");
|
|
});
|