tdesign-mobile-vue
Version:
tdesign-mobile-vue
180 lines (177 loc) • 8.4 kB
JavaScript
/**
* tdesign v1.13.2
* (c) 2026 TDesign Group
* @license MIT
*/
import { t } from '../../../js/global-config/t.js';
import { d as describe, i as it, g as globalExpect } from '../../../../_chunks/dep-6804b57a.js';
import '@babel/runtime/helpers/slicedToArray';
import '@babel/runtime/helpers/typeof';
import 'lodash-es';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/construct';
import '@babel/runtime/helpers/assertThisInitialized';
import '@babel/runtime/helpers/possibleConstructorReturn';
import '@babel/runtime/helpers/getPrototypeOf';
import '@babel/runtime/helpers/inherits';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/defineProperty';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '@babel/runtime/helpers/wrapNativeSuper';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/get';
describe("\u56FD\u9645\u5316\u51FD\u6570 t", function () {
describe("\u57FA\u672C\u53D8\u91CF\u66FF\u6362", function () {
it("\u5E94\u8BE5\u6B63\u786E\u66FF\u6362\u5355\u4E2A\u53D8\u91CF", function () {
globalExpect(t("Hello {name}", {
name: "World"
})).toBe("Hello World");
});
it("\u5E94\u8BE5\u6B63\u786E\u66FF\u6362\u591A\u4E2A\u53D8\u91CF", function () {
globalExpect(t("User {id}: {username}", {
id: 123,
username: "alice"
})).toBe("User 123: alice");
});
it("\u5E94\u8BE5\u6B63\u786E\u5904\u7406\u53D8\u91CF\u540D\u5305\u542B\u8FDE\u5B57\u7B26", function () {
globalExpect(t("Hello {user-name}", {
"user-name": "John"
})).toBe("Hello John");
});
it("\u5E94\u8BE5\u6B63\u786E\u5904\u7406\u53D8\u91CF\u5468\u56F4\u6709\u7A7A\u683C", function () {
globalExpect(t("Hello { name }", {
name: "World"
})).toBe("Hello World");
});
it("\u5F53\u53D8\u91CF\u4E0D\u5B58\u5728\u65F6\u5E94\u8BE5\u4FDD\u7559\u539F\u59CB\u5360\u4F4D\u7B26", function () {
globalExpect(t("text with {missing} variable", {})).toBe("text with {missing} variable");
});
it("\u5F53\u6CA1\u6709\u4F20\u5165\u6570\u636E\u65F6\u5E94\u8BE5\u4FDD\u7559\u539F\u59CB\u5360\u4F4D\u7B26", function () {
globalExpect(t("Hello {name}")).toBe("Hello {name}");
});
it("\u5E94\u8BE5\u5C06\u53D8\u91CF\u503C\u8F6C\u6362\u4E3A\u5B57\u7B26\u4E32", function () {
globalExpect(t("Number: {num}", {
num: 42
})).toBe("Number: 42");
globalExpect(t("Boolean: {flag}", {
flag: true
})).toBe("Boolean: true");
});
});
describe("\u590D\u6570\u5904\u7406", function () {
it("\u5F53 count = 0 \u65F6\u5E94\u8BE5\u4F7F\u7528\u7B2C\u4E00\u4E2A\u9009\u9879", function () {
globalExpect(t("no apples | one apple | {count} apples", 0)).toBe("no apples");
});
it("\u5F53 count = 1 \u65F6\u5E94\u8BE5\u4F7F\u7528\u7B2C\u4E8C\u4E2A\u9009\u9879", function () {
globalExpect(t("no apples | one apple | {count} apples", 1)).toBe("one apple");
});
it("\u5F53 count > 1 \u65F6\u5E94\u8BE5\u4F7F\u7528\u7B2C\u4E09\u4E2A\u9009\u9879", function () {
globalExpect(t("no apples | one apple | {count} apples", 5)).toBe("5 apples");
globalExpect(t("no apples | one apple | {count} apples", 100)).toBe("100 apples");
});
it("\u5F53\u6CA1\u6709 count \u5B57\u6BB5\u65F6\u5E94\u8BE5\u4F7F\u7528\u7B2C\u4E00\u4E2A\u9009\u9879", function () {
globalExpect(t("no data | one item | many items")).toBe("no data");
globalExpect(t("no data | one item | many items", {})).toBe("no data");
});
it("\u5F53\u590D\u6570\u9009\u9879\u6570\u91CF\u4E0D\u8DB3\u65F6\u5E94\u8BE5\u4F7F\u7528\u6700\u540E\u4E00\u4E2A\u9009\u9879", function () {
globalExpect(t("zero | many", 0)).toBe("zero");
globalExpect(t("zero | many", 1)).toBe("many");
globalExpect(t("zero | many", 5)).toBe("many");
});
it("\u5E94\u8BE5\u6B63\u786E\u5904\u7406\u590D\u6570\u9009\u9879\u524D\u540E\u7684\u7A7A\u683C", function () {
globalExpect(t(" no items | one item | many items ", 0)).toBe("no items");
globalExpect(t(" no items | one item | many items ", 1)).toBe("one item");
globalExpect(t(" no items | one item | many items ", 5)).toBe("many items");
});
});
describe("\u590D\u5408\u4F7F\u7528\uFF08\u590D\u6570 + \u53D8\u91CF\u66FF\u6362\uFF09", function () {
it("\u5E94\u8BE5\u6B63\u786E\u5904\u7406\u590D\u6570\u9009\u62E9\u548C\u53D8\u91CF\u66FF\u6362\u7684\u7EC4\u5408", function () {
globalExpect(t("no items found | found {count} item | found {count} items", 0)).toBe("no items found");
globalExpect(t("no items found | found {count} item | found {count} items", 1, {
count: 1
})).toBe("found 1 item");
globalExpect(t("no items found | found {count} item | found {count} items", 3, {
count: 3
})).toBe("found 3 items");
});
it("\u5E94\u8BE5\u6B63\u786E\u5904\u7406\u53EA\u4F20\u5165 count \u7684\u60C5\u51B5", function () {
globalExpect(t("no items | one item | {count} items", 0)).toBe("no items");
globalExpect(t("no items | one item | {count} items", 1)).toBe("one item");
globalExpect(t("no items | one item | {count} items", 5)).toBe("5 items");
globalExpect(t("no items | one item | items", 5)).toBe("items");
});
it("\u5E94\u8BE5\u6B63\u786E\u5904\u7406\u5305\u542B\u5176\u4ED6\u53D8\u91CF\u7684\u590D\u6570\u6587\u672C", function () {
globalExpect(t("no {type} | one {type} ({count}) | {count} {type}s", 0, {
type: "file"
})).toBe("no file");
globalExpect(t("no {type} | one {type} ({count}) | {count} {type}s", 1, {
count: 1,
type: "file"
})).toBe("one file (1)");
globalExpect(t("no {type} | one {type} ({count}) | {count} {type}s", 5, {
count: 5,
type: "file"
})).toBe("5 files");
});
});
describe("\u7EAF\u6587\u672C\u5904\u7406", function () {
it("\u5E94\u8BE5\u76F4\u63A5\u8FD4\u56DE\u7EAF\u6587\u672C", function () {
globalExpect(t("simple text")).toBe("simple text");
globalExpect(t("Hello World")).toBe("Hello World");
});
it("\u5E94\u8BE5\u5904\u7406\u7A7A\u5B57\u7B26\u4E32", function () {
globalExpect(t("")).toBe("");
});
});
describe("\u8FB9\u754C\u60C5\u51B5\u548C\u9519\u8BEF\u5904\u7406", function () {
it("\u5E94\u8BE5\u5904\u7406 null \u548C undefined", function () {
globalExpect(t(null)).toBe("");
globalExpect(t(void 0)).toBe("");
});
it("\u5E94\u8BE5\u5904\u7406\u6570\u5B57\u7C7B\u578B", function () {
globalExpect(t(123)).toBe("");
});
it("\u5E94\u8BE5\u5904\u7406\u5E03\u5C14\u7C7B\u578B", function () {
globalExpect(t(true)).toBe("");
globalExpect(t(false)).toBe("");
});
it("\u5E94\u8BE5\u5904\u7406\u5BF9\u8C61\u7C7B\u578B", function () {
globalExpect(t({})).toBe("");
globalExpect(t({
key: "value"
})).toBe("");
});
it("\u5E94\u8BE5\u5904\u7406\u6570\u7EC4\u7C7B\u578B", function () {
globalExpect(t([])).toBe("");
globalExpect(t(["item"])).toBe("");
});
it("\u5E94\u8BE5\u5904\u7406\u590D\u6742\u7684\u53D8\u91CF\u540D", function () {
globalExpect(t("Hello {user_name}", {
user_name: "John"
})).toBe("Hello John");
globalExpect(t("Hello {user-name}", {
"user-name": "John"
})).toBe("Hello John");
globalExpect(t("Hello {userName}", {
userName: "John"
})).toBe("Hello John");
});
});
describe("\u5B9E\u9645\u5E94\u7528\u573A\u666F", function () {
it("\u641C\u7D22\u7ED3\u679C\u573A\u666F", function () {
var pattern = 'Search "{result}". Found no items. | Search "{result}". Found 1 item. | Search "{result}". Found {count} items.';
var getSearchResultText = function getSearchResultText(count, result) {
return t(pattern, count, {
count: count,
result: result
});
};
globalExpect(getSearchResultText(0, "apple")).toBe('Search "apple". Found no items.');
globalExpect(getSearchResultText(1, "apple")).toBe('Search "apple". Found 1 item.');
globalExpect(getSearchResultText(5, "apple")).toBe('Search "apple". Found 5 items.');
});
});
});
//# sourceMappingURL=locale.test.js.map