mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
- 实现配置架构解析器,支持对象、数组和标量类型的递归解析 - 添加 YAML 配置文件解析和注释提取功能 - 实现配置验证诊断系统,支持多种数据类型的校验 - 添加表单更新应用功能,支持标量和数组值的批量编辑 - 实现配置示例生成功能,包含架构描述作为 YAML 注释 - 添加国际化支持,提供中英文验证消息本地化 - 实现精确十进制运算,确保数值约束验证的准确性 - 添加批处理数组值解析和枚举值标准化功能
60 lines
2.6 KiB
JavaScript
60 lines
2.6 KiB
JavaScript
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const {createLocalizer} = require("../src/localization");
|
|
const {ValidationMessageKeys} = require("../src/localizationKeys");
|
|
|
|
test("createLocalizer should default to English strings", () => {
|
|
const localizer = createLocalizer("en");
|
|
|
|
assert.equal(localizer.languageTag, "en");
|
|
assert.equal(localizer.isChinese, false);
|
|
assert.equal(localizer.t("webview.button.save"), "Save Form");
|
|
assert.equal(
|
|
localizer.t("message.batchEditUpdated", {count: 2, domain: "monster"}),
|
|
"Batch updated 2 config file(s) in 'monster'.");
|
|
});
|
|
|
|
test("createLocalizer should switch to Simplified Chinese for zh languages", () => {
|
|
const localizer = createLocalizer("zh-cn");
|
|
|
|
assert.equal(localizer.languageTag, "zh-CN");
|
|
assert.equal(localizer.isChinese, true);
|
|
assert.equal(localizer.t("webview.button.save"), "保存表单");
|
|
assert.equal(
|
|
localizer.t("message.batchEditUpdated", {count: 2, domain: "monster"}),
|
|
"已在“monster”中批量更新 2 个配置文件。");
|
|
});
|
|
|
|
test("createLocalizer should fall back to English for Traditional Chinese locales", () => {
|
|
const localizer = createLocalizer("zh-TW");
|
|
|
|
assert.equal(localizer.languageTag, "zh-tw");
|
|
assert.equal(localizer.isChinese, false);
|
|
assert.equal(localizer.t("webview.button.save"), "Save Form");
|
|
assert.equal(
|
|
localizer.t("message.batchEditUpdated", {count: 2, domain: "monster"}),
|
|
"Batch updated 2 config file(s) in 'monster'.");
|
|
});
|
|
|
|
test("createLocalizer should expose object property-count validation keys in English", () => {
|
|
const localizer = createLocalizer("en");
|
|
|
|
assert.equal(
|
|
localizer.t(ValidationMessageKeys.minPropertiesViolation, {displayPath: "reward", value: 2}),
|
|
"Property 'reward' must contain at least 2 properties.");
|
|
assert.equal(
|
|
localizer.t(ValidationMessageKeys.maxPropertiesViolation, {displayPath: "reward", value: 3}),
|
|
"Property 'reward' must contain at most 3 properties.");
|
|
});
|
|
|
|
test("createLocalizer should expose object property-count validation keys in Simplified Chinese", () => {
|
|
const localizer = createLocalizer("zh-cn");
|
|
|
|
assert.equal(
|
|
localizer.t(ValidationMessageKeys.minPropertiesViolation, {displayPath: "reward", value: 2}),
|
|
"对象属性“reward”至少需要包含 2 个子属性。");
|
|
assert.equal(
|
|
localizer.t(ValidationMessageKeys.maxPropertiesViolation, {displayPath: "reward", value: 3}),
|
|
"对象属性“reward”最多只能包含 3 个子属性。");
|
|
});
|