tang-ui-x 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1003 -0
- package/components/TActionSheet/index.uvue +15 -2
- package/components/TCollapse/index.uvue +1 -1
- package/components/TCollapse/type.uts +3 -1
- package/components/TCollapseItem/index.uvue +22 -26
- package/components/TDialog/index.uvue +19 -4
- package/components/TEmpty/index.uvue +28 -14
- package/components/TForm/index.uvue +60 -26
- package/components/TForm/type.uts +4 -0
- package/components/TInput/index.uvue +24 -5
- package/components/TInput/type.uts +10 -0
- package/components/TPicker/index.uvue +26 -6
- package/components/TRadioButton/README.md +117 -0
- package/components/TRadioButton/index.uvue +69 -64
- package/components/TSearchBar/index.uvue +19 -4
- package/composables/i18n/error.uts +82 -0
- package/composables/i18n/index.uts +188 -0
- package/composables/i18n/manager-demo.uts +104 -0
- package/composables/i18n/manager.test.uts +182 -0
- package/composables/i18n/manager.uts +336 -0
- package/composables/i18n/register-demo.uts +125 -0
- package/composables/i18n/task22-verification.uts +198 -0
- package/composables/i18n/task23-verification.uts +343 -0
- package/composables/i18n/task8-demo.uts +93 -0
- package/composables/i18n/task8-verification.uts +98 -0
- package/composables/i18n/test-task23.uts +9 -0
- package/composables/i18n/types.uts +46 -0
- package/composables/i18n/useI18n-verification.uts +105 -0
- package/composables/i18n/validation-demo.uts +45 -0
- package/composables/i18n/validation-test.uts +106 -0
- package/composables/useI18n.uts +77 -0
- package/index.uts +23 -0
- package/locales/cross-platform-verification.uts +510 -0
- package/locales/en-US/actionSheet.json +3 -0
- package/locales/en-US/common.json +10 -0
- package/locales/en-US/dialog.json +5 -0
- package/locales/en-US/empty.json +5 -0
- package/locales/en-US/errorState.json +5 -0
- package/locales/en-US/examplePages.json +1236 -0
- package/locales/en-US/examples.json +218 -0
- package/locales/en-US/form.json +11 -0
- package/locales/en-US/input.json +3 -0
- package/locales/en-US/list.json +5 -0
- package/locales/en-US/loading.json +3 -0
- package/locales/en-US/navBar.json +4 -0
- package/locales/en-US/noticeBar.json +3 -0
- package/locales/en-US/picker.json +5 -0
- package/locales/en-US/searchBar.json +4 -0
- package/locales/en-US/textarea.json +3 -0
- package/locales/en-US/toast.json +6 -0
- package/locales/index.uts +79 -0
- package/locales/init-verification.uts +101 -0
- package/locales/loader.uts +251 -0
- package/locales/run-verification.uts +16 -0
- package/locales/zh-CN/actionSheet.json +3 -0
- package/locales/zh-CN/common.json +10 -0
- package/locales/zh-CN/dialog.json +5 -0
- package/locales/zh-CN/empty.json +5 -0
- package/locales/zh-CN/errorState.json +5 -0
- package/locales/zh-CN/examplePages.json +1236 -0
- package/locales/zh-CN/examples.json +218 -0
- package/locales/zh-CN/form.json +11 -0
- package/locales/zh-CN/input.json +3 -0
- package/locales/zh-CN/list.json +5 -0
- package/locales/zh-CN/loading.json +3 -0
- package/locales/zh-CN/navBar.json +4 -0
- package/locales/zh-CN/noticeBar.json +3 -0
- package/locales/zh-CN/picker.json +5 -0
- package/locales/zh-CN/searchBar.json +4 -0
- package/locales/zh-CN/textarea.json +3 -0
- package/locales/zh-CN/toast.json +6 -0
- package/locales/zh-TW/actionSheet.json +3 -0
- package/locales/zh-TW/common.json +8 -0
- package/locales/zh-TW/dialog.json +5 -0
- package/locales/zh-TW/empty.json +5 -0
- package/locales/zh-TW/errorState.json +5 -0
- package/locales/zh-TW/examplePages.json +705 -0
- package/locales/zh-TW/examples.json +218 -0
- package/locales/zh-TW/form.json +11 -0
- package/locales/zh-TW/input.json +3 -0
- package/locales/zh-TW/list.json +5 -0
- package/locales/zh-TW/loading.json +3 -0
- package/locales/zh-TW/navBar.json +4 -0
- package/locales/zh-TW/noticeBar.json +3 -0
- package/locales/zh-TW/picker.json +5 -0
- package/locales/zh-TW/searchBar.json +4 -0
- package/locales/zh-TW/textarea.json +3 -0
- package/locales/zh-TW/toast.json +6 -0
- package/package.json +49 -47
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 跨平台兼容性验证脚本
|
|
3
|
+
* 验证 i18n 系统在不同平台上的功能
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { initI18n, isI18nInitialized, resetI18nInitialization } from './index.uts'
|
|
7
|
+
import { I18nManager } from '../composables/i18n/manager.uts'
|
|
8
|
+
import { LocaleLoader } from './loader.uts'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 验证结果类型
|
|
12
|
+
*/
|
|
13
|
+
type VerificationResult = {
|
|
14
|
+
testName: string
|
|
15
|
+
passed: boolean
|
|
16
|
+
message: string
|
|
17
|
+
error?: any
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 验证测试套件
|
|
22
|
+
*/
|
|
23
|
+
class CrossPlatformVerification {
|
|
24
|
+
private results: VerificationResult[] = []
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 运行所有验证测试
|
|
28
|
+
*/
|
|
29
|
+
runAll(): void {
|
|
30
|
+
console.log('='.repeat(60))
|
|
31
|
+
console.log('开始跨平台兼容性验证')
|
|
32
|
+
console.log('='.repeat(60))
|
|
33
|
+
console.log('')
|
|
34
|
+
|
|
35
|
+
// 重置初始化状态
|
|
36
|
+
resetI18nInitialization()
|
|
37
|
+
|
|
38
|
+
// 运行测试
|
|
39
|
+
this.testStaticImports()
|
|
40
|
+
this.testLoaderSynchronous()
|
|
41
|
+
this.testInitialization()
|
|
42
|
+
this.testBasicTranslation()
|
|
43
|
+
this.testLanguageSwitching()
|
|
44
|
+
this.testFallbackMechanism()
|
|
45
|
+
this.testParameterInterpolation()
|
|
46
|
+
this.testLanguageRegistration()
|
|
47
|
+
this.testAvailableLocales()
|
|
48
|
+
this.testErrorHandling()
|
|
49
|
+
|
|
50
|
+
// 输出结果
|
|
51
|
+
this.printResults()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 测试静态导入是否正常工作
|
|
56
|
+
*/
|
|
57
|
+
private testStaticImports(): void {
|
|
58
|
+
try {
|
|
59
|
+
const loader = LocaleLoader
|
|
60
|
+
const zhCN = loader.loadLocale('zh-CN')
|
|
61
|
+
const enUS = loader.loadLocale('en-US')
|
|
62
|
+
const zhTW = loader.loadLocale('zh-TW')
|
|
63
|
+
|
|
64
|
+
// 验证语言包不为空
|
|
65
|
+
const zhCNValid = Object.keys(zhCN).length > 0
|
|
66
|
+
const enUSValid = Object.keys(enUS).length > 0
|
|
67
|
+
const zhTWValid = Object.keys(zhTW).length > 0
|
|
68
|
+
|
|
69
|
+
if (zhCNValid && enUSValid && zhTWValid) {
|
|
70
|
+
this.addResult({
|
|
71
|
+
testName: '静态导入验证',
|
|
72
|
+
passed: true,
|
|
73
|
+
message: '所有内置语言包静态导入成功'
|
|
74
|
+
})
|
|
75
|
+
} else {
|
|
76
|
+
this.addResult({
|
|
77
|
+
testName: '静态导入验证',
|
|
78
|
+
passed: false,
|
|
79
|
+
message: `语言包导入失败: zh-CN=${zhCNValid}, en-US=${enUSValid}, zh-TW=${zhTWValid}`
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
this.addResult({
|
|
84
|
+
testName: '静态导入验证',
|
|
85
|
+
passed: false,
|
|
86
|
+
message: '静态导入失败',
|
|
87
|
+
error: error
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 测试加载器是否为同步方法
|
|
94
|
+
*/
|
|
95
|
+
private testLoaderSynchronous(): void {
|
|
96
|
+
try {
|
|
97
|
+
// 调用 loadLocale 应该立即返回结果,不是 Promise
|
|
98
|
+
const result = LocaleLoader.loadLocale('zh-CN')
|
|
99
|
+
const isSync = typeof result === 'object' && result !== null
|
|
100
|
+
|
|
101
|
+
if (isSync) {
|
|
102
|
+
this.addResult({
|
|
103
|
+
testName: '加载器同步性验证',
|
|
104
|
+
passed: true,
|
|
105
|
+
message: 'LocaleLoader.loadLocale() 是同步方法'
|
|
106
|
+
})
|
|
107
|
+
} else {
|
|
108
|
+
this.addResult({
|
|
109
|
+
testName: '加载器同步性验证',
|
|
110
|
+
passed: false,
|
|
111
|
+
message: 'LocaleLoader.loadLocale() 不是同步方法'
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
this.addResult({
|
|
116
|
+
testName: '加载器同步性验证',
|
|
117
|
+
passed: false,
|
|
118
|
+
message: '加载器同步性测试失败',
|
|
119
|
+
error: error
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 测试初始化功能
|
|
126
|
+
*/
|
|
127
|
+
private testInitialization(): void {
|
|
128
|
+
try {
|
|
129
|
+
// 初始化应该是同步的
|
|
130
|
+
initI18n()
|
|
131
|
+
|
|
132
|
+
const initialized = isI18nInitialized()
|
|
133
|
+
const manager = I18nManager.getInstance()
|
|
134
|
+
const currentLocale = manager.getCurrentLocale()
|
|
135
|
+
|
|
136
|
+
if (initialized && currentLocale === 'zh-CN') {
|
|
137
|
+
this.addResult({
|
|
138
|
+
testName: '初始化验证',
|
|
139
|
+
passed: true,
|
|
140
|
+
message: 'I18n 系统初始化成功,默认语言为 zh-CN'
|
|
141
|
+
})
|
|
142
|
+
} else {
|
|
143
|
+
this.addResult({
|
|
144
|
+
testName: '初始化验证',
|
|
145
|
+
passed: false,
|
|
146
|
+
message: `初始化状态异常: initialized=${initialized}, locale=${currentLocale}`
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
this.addResult({
|
|
151
|
+
testName: '初始化验证',
|
|
152
|
+
passed: false,
|
|
153
|
+
message: '初始化失败',
|
|
154
|
+
error: error
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 测试基本翻译功能
|
|
161
|
+
*/
|
|
162
|
+
private testBasicTranslation(): void {
|
|
163
|
+
try {
|
|
164
|
+
const manager = I18nManager.getInstance()
|
|
165
|
+
|
|
166
|
+
// 测试简体中文翻译
|
|
167
|
+
const confirm = manager.translate('common.confirm')
|
|
168
|
+
const cancel = manager.translate('common.cancel')
|
|
169
|
+
const emptyTitle = manager.translate('empty.title')
|
|
170
|
+
|
|
171
|
+
if (confirm === '确定' && cancel === '取消' && emptyTitle === '暂无数据') {
|
|
172
|
+
this.addResult({
|
|
173
|
+
testName: '基本翻译功能',
|
|
174
|
+
passed: true,
|
|
175
|
+
message: '翻译功能正常工作'
|
|
176
|
+
})
|
|
177
|
+
} else {
|
|
178
|
+
this.addResult({
|
|
179
|
+
testName: '基本翻译功能',
|
|
180
|
+
passed: false,
|
|
181
|
+
message: `翻译结果不正确: confirm=${confirm}, cancel=${cancel}, emptyTitle=${emptyTitle}`
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
} catch (error) {
|
|
185
|
+
this.addResult({
|
|
186
|
+
testName: '基本翻译功能',
|
|
187
|
+
passed: false,
|
|
188
|
+
message: '翻译功能测试失败',
|
|
189
|
+
error: error
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 测试语言切换功能
|
|
196
|
+
*/
|
|
197
|
+
private testLanguageSwitching(): void {
|
|
198
|
+
try {
|
|
199
|
+
const manager = I18nManager.getInstance()
|
|
200
|
+
|
|
201
|
+
// 切换到英语
|
|
202
|
+
const switchSuccess = manager.setLocale('en-US')
|
|
203
|
+
const confirm = manager.translate('common.confirm')
|
|
204
|
+
const cancel = manager.translate('common.cancel')
|
|
205
|
+
|
|
206
|
+
// 切换回中文
|
|
207
|
+
manager.setLocale('zh-CN')
|
|
208
|
+
|
|
209
|
+
if (switchSuccess && confirm === 'Confirm' && cancel === 'Cancel') {
|
|
210
|
+
this.addResult({
|
|
211
|
+
testName: '语言切换功能',
|
|
212
|
+
passed: true,
|
|
213
|
+
message: '语言切换功能正常工作'
|
|
214
|
+
})
|
|
215
|
+
} else {
|
|
216
|
+
this.addResult({
|
|
217
|
+
testName: '语言切换功能',
|
|
218
|
+
passed: false,
|
|
219
|
+
message: `语言切换失败: success=${switchSuccess}, confirm=${confirm}, cancel=${cancel}`
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
this.addResult({
|
|
224
|
+
testName: '语言切换功能',
|
|
225
|
+
passed: false,
|
|
226
|
+
message: '语言切换测试失败',
|
|
227
|
+
error: error
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 测试回退机制
|
|
234
|
+
*/
|
|
235
|
+
private testFallbackMechanism(): void {
|
|
236
|
+
try {
|
|
237
|
+
const manager = I18nManager.getInstance()
|
|
238
|
+
|
|
239
|
+
// 注册一个不完整的语言包
|
|
240
|
+
manager.registerMessages('test-locale', {
|
|
241
|
+
common: {
|
|
242
|
+
confirm: 'Test Confirm'
|
|
243
|
+
// 缺少 cancel 键
|
|
244
|
+
}
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
manager.setLocale('test-locale')
|
|
248
|
+
|
|
249
|
+
const confirm = manager.translate('common.confirm')
|
|
250
|
+
const cancel = manager.translate('common.cancel') // 应该回退到 zh-CN
|
|
251
|
+
|
|
252
|
+
// 切换回中文
|
|
253
|
+
manager.setLocale('zh-CN')
|
|
254
|
+
|
|
255
|
+
if (confirm === 'Test Confirm' && cancel === '取消') {
|
|
256
|
+
this.addResult({
|
|
257
|
+
testName: '回退机制验证',
|
|
258
|
+
passed: true,
|
|
259
|
+
message: '回退机制正常工作'
|
|
260
|
+
})
|
|
261
|
+
} else {
|
|
262
|
+
this.addResult({
|
|
263
|
+
testName: '回退机制验证',
|
|
264
|
+
passed: false,
|
|
265
|
+
message: `回退机制异常: confirm=${confirm}, cancel=${cancel}`
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
} catch (error) {
|
|
269
|
+
this.addResult({
|
|
270
|
+
testName: '回退机制验证',
|
|
271
|
+
passed: false,
|
|
272
|
+
message: '回退机制测试失败',
|
|
273
|
+
error: error
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 测试参数插值功能
|
|
280
|
+
*/
|
|
281
|
+
private testParameterInterpolation(): void {
|
|
282
|
+
try {
|
|
283
|
+
const manager = I18nManager.getInstance()
|
|
284
|
+
|
|
285
|
+
// 注册带参数的翻译
|
|
286
|
+
manager.registerMessages('zh-CN', {
|
|
287
|
+
test: {
|
|
288
|
+
greeting: '你好,{name}!',
|
|
289
|
+
count: '共有 {count} 个项目'
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
const greeting = manager.translate('test.greeting', { name: '张三' })
|
|
294
|
+
const count = manager.translate('test.count', { count: 5 })
|
|
295
|
+
|
|
296
|
+
if (greeting === '你好,张三!' && count === '共有 5 个项目') {
|
|
297
|
+
this.addResult({
|
|
298
|
+
testName: '参数插值功能',
|
|
299
|
+
passed: true,
|
|
300
|
+
message: '参数插值功能正常工作'
|
|
301
|
+
})
|
|
302
|
+
} else {
|
|
303
|
+
this.addResult({
|
|
304
|
+
testName: '参数插值功能',
|
|
305
|
+
passed: false,
|
|
306
|
+
message: `参数插值异常: greeting=${greeting}, count=${count}`
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
} catch (error) {
|
|
310
|
+
this.addResult({
|
|
311
|
+
testName: '参数插值功能',
|
|
312
|
+
passed: false,
|
|
313
|
+
message: '参数插值测试失败',
|
|
314
|
+
error: error
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 测试语言包注册功能
|
|
321
|
+
*/
|
|
322
|
+
private testLanguageRegistration(): void {
|
|
323
|
+
try {
|
|
324
|
+
const manager = I18nManager.getInstance()
|
|
325
|
+
|
|
326
|
+
// 注册新语言包
|
|
327
|
+
manager.registerMessages('ja-JP', {
|
|
328
|
+
common: {
|
|
329
|
+
confirm: '確認',
|
|
330
|
+
cancel: 'キャンセル'
|
|
331
|
+
}
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
const hasJapanese = manager.hasLocale('ja-JP')
|
|
335
|
+
|
|
336
|
+
if (hasJapanese) {
|
|
337
|
+
manager.setLocale('ja-JP')
|
|
338
|
+
const confirm = manager.translate('common.confirm')
|
|
339
|
+
manager.setLocale('zh-CN')
|
|
340
|
+
|
|
341
|
+
if (confirm === '確認') {
|
|
342
|
+
this.addResult({
|
|
343
|
+
testName: '语言包注册功能',
|
|
344
|
+
passed: true,
|
|
345
|
+
message: '语言包注册功能正常工作'
|
|
346
|
+
})
|
|
347
|
+
} else {
|
|
348
|
+
this.addResult({
|
|
349
|
+
testName: '语言包注册功能',
|
|
350
|
+
passed: false,
|
|
351
|
+
message: `注册的语言包翻译异常: confirm=${confirm}`
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
this.addResult({
|
|
356
|
+
testName: '语言包注册功能',
|
|
357
|
+
passed: false,
|
|
358
|
+
message: '语言包注册失败'
|
|
359
|
+
})
|
|
360
|
+
}
|
|
361
|
+
} catch (error) {
|
|
362
|
+
this.addResult({
|
|
363
|
+
testName: '语言包注册功能',
|
|
364
|
+
passed: false,
|
|
365
|
+
message: '语言包注册测试失败',
|
|
366
|
+
error: error
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 测试可用语言列表
|
|
373
|
+
*/
|
|
374
|
+
private testAvailableLocales(): void {
|
|
375
|
+
try {
|
|
376
|
+
const manager = I18nManager.getInstance()
|
|
377
|
+
const availableLocales = manager.getAvailableLocales()
|
|
378
|
+
const locales = availableLocales.value
|
|
379
|
+
|
|
380
|
+
const hasZhCN = locales.includes('zh-CN')
|
|
381
|
+
const hasEnUS = locales.includes('en-US')
|
|
382
|
+
const hasZhTW = locales.includes('zh-TW')
|
|
383
|
+
|
|
384
|
+
if (hasZhCN && hasEnUS && hasZhTW && locales.length >= 3) {
|
|
385
|
+
this.addResult({
|
|
386
|
+
testName: '可用语言列表',
|
|
387
|
+
passed: true,
|
|
388
|
+
message: `可用语言列表正常: ${locales.join(', ')}`
|
|
389
|
+
})
|
|
390
|
+
} else {
|
|
391
|
+
this.addResult({
|
|
392
|
+
testName: '可用语言列表',
|
|
393
|
+
passed: false,
|
|
394
|
+
message: `可用语言列表异常: ${locales.join(', ')}`
|
|
395
|
+
})
|
|
396
|
+
}
|
|
397
|
+
} catch (error) {
|
|
398
|
+
this.addResult({
|
|
399
|
+
testName: '可用语言列表',
|
|
400
|
+
passed: false,
|
|
401
|
+
message: '可用语言列表测试失败',
|
|
402
|
+
error: error
|
|
403
|
+
})
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* 测试错误处理
|
|
409
|
+
*/
|
|
410
|
+
private testErrorHandling(): void {
|
|
411
|
+
try {
|
|
412
|
+
const manager = I18nManager.getInstance()
|
|
413
|
+
|
|
414
|
+
// 测试无效语言代码
|
|
415
|
+
const invalidSwitch = manager.setLocale('invalid-locale')
|
|
416
|
+
|
|
417
|
+
// 测试不存在的翻译键
|
|
418
|
+
const missingKey = manager.translate('nonexistent.key')
|
|
419
|
+
|
|
420
|
+
if (!invalidSwitch && missingKey === 'nonexistent.key') {
|
|
421
|
+
this.addResult({
|
|
422
|
+
testName: '错误处理',
|
|
423
|
+
passed: true,
|
|
424
|
+
message: '错误处理机制正常工作'
|
|
425
|
+
})
|
|
426
|
+
} else {
|
|
427
|
+
this.addResult({
|
|
428
|
+
testName: '错误处理',
|
|
429
|
+
passed: false,
|
|
430
|
+
message: `错误处理异常: invalidSwitch=${invalidSwitch}, missingKey=${missingKey}`
|
|
431
|
+
})
|
|
432
|
+
}
|
|
433
|
+
} catch (error) {
|
|
434
|
+
this.addResult({
|
|
435
|
+
testName: '错误处理',
|
|
436
|
+
passed: false,
|
|
437
|
+
message: '错误处理测试失败',
|
|
438
|
+
error: error
|
|
439
|
+
})
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* 添加测试结果
|
|
445
|
+
*/
|
|
446
|
+
private addResult(result: VerificationResult): void {
|
|
447
|
+
this.results.push(result)
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* 打印测试结果
|
|
452
|
+
*/
|
|
453
|
+
private printResults(): void {
|
|
454
|
+
console.log('')
|
|
455
|
+
console.log('='.repeat(60))
|
|
456
|
+
console.log('验证结果汇总')
|
|
457
|
+
console.log('='.repeat(60))
|
|
458
|
+
console.log('')
|
|
459
|
+
|
|
460
|
+
let passedCount = 0
|
|
461
|
+
let failedCount = 0
|
|
462
|
+
|
|
463
|
+
for (const result of this.results) {
|
|
464
|
+
const status = result.passed ? '✓ 通过' : '✗ 失败'
|
|
465
|
+
const icon = result.passed ? '✓' : '✗'
|
|
466
|
+
|
|
467
|
+
console.log(`${icon} ${result.testName}`)
|
|
468
|
+
console.log(` ${result.message}`)
|
|
469
|
+
|
|
470
|
+
if (result.error) {
|
|
471
|
+
console.log(` 错误: ${result.error}`)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
console.log('')
|
|
475
|
+
|
|
476
|
+
if (result.passed) {
|
|
477
|
+
passedCount++
|
|
478
|
+
} else {
|
|
479
|
+
failedCount++
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
console.log('='.repeat(60))
|
|
484
|
+
console.log(`总计: ${this.results.length} 个测试`)
|
|
485
|
+
console.log(`通过: ${passedCount} 个`)
|
|
486
|
+
console.log(`失败: ${failedCount} 个`)
|
|
487
|
+
console.log('='.repeat(60))
|
|
488
|
+
|
|
489
|
+
if (failedCount === 0) {
|
|
490
|
+
console.log('')
|
|
491
|
+
console.log('🎉 所有测试通过!跨平台兼容性验证成功!')
|
|
492
|
+
console.log('')
|
|
493
|
+
} else {
|
|
494
|
+
console.log('')
|
|
495
|
+
console.log('⚠️ 存在失败的测试,请检查上述错误信息')
|
|
496
|
+
console.log('')
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* 导出验证函数
|
|
503
|
+
*/
|
|
504
|
+
export function runCrossPlatformVerification(): void {
|
|
505
|
+
const verification = new CrossPlatformVerification()
|
|
506
|
+
verification.runAll()
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// 如果直接运行此文件,执行验证
|
|
510
|
+
// runCrossPlatformVerification()
|