-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(bin): add tests for extracting keys and values from expressions …
…like t.t(key, text)
- Loading branch information
Showing
3 changed files
with
200 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { initI18n } from '../../src/lib' | ||
const { t } = initI18n({ namespace: 'text' }) | ||
const foo = 'foo' | ||
const key = 'key' | ||
const fooFunc = (x: string) => x | ||
const keyFunc = (x: string) => x | ||
|
||
// 不能记录的错误信息的错误 | ||
t.t(key, foo) | ||
t.t(keyFunc(key), fooFunc(foo)) | ||
t.t('xxx' + key, 'xxx' + foo) | ||
t.t( | ||
`中间有 | ||
换行`, | ||
`中间有 | ||
换行`, | ||
) | ||
|
||
// 能记录到错误信息的错误 | ||
t.t(`${key}`, `${foo}`) | ||
t.t('key\n中间', '你好\n啊') | ||
t.t('key\t中间', '你好\t啊') | ||
t.t(' key前面有空格', ' 前面有空格') | ||
t.t('key后面空格 ', '后面空格 ') | ||
|
||
// 正常解析的示例 | ||
t.t('中间 有空格的key', '中间 有空格') | ||
t.t('普通文本key', '普通文本') | ||
t.t('普通文本', '普通文本{0}', foo) | ||
t.t('test', '普通文案') | ||
t.t('test', 'a', t('b')) | ||
t.t('key2', '自定义key') | ||
t.t('key3', '自定义key') |