Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
5ff6bcbd
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
5ff6bcbd
编写于
9月 01, 2023
作者:
Y
yurj26
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(uts): ForLoop
上级
dfea25d3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
331 addition
and
42 deletion
+331
-42
pages/index/basicTest.uvue
pages/index/basicTest.uvue
+0
-1
uni_modules/uts-tests/utssdk/ForLoop.uts
uni_modules/uts-tests/utssdk/ForLoop.uts
+302
-0
uni_modules/uts-tests/utssdk/index.uts
uni_modules/uts-tests/utssdk/index.uts
+29
-41
未找到文件。
pages/index/basicTest.uvue
浏览文件 @
5ff6bcbd
...
@@ -49,7 +49,6 @@ export default {
...
@@ -49,7 +49,6 @@ export default {
<style>
<style>
@import '@/common/uni-uvue.css';
@import '@/common/uni-uvue.css';
.content {
.content {
min-height: 100%;
padding: 32rpx;
padding: 32rpx;
}
}
...
...
uni_modules/uts-tests/utssdk/ForLoop.uts
0 → 100644
浏览文件 @
5ff6bcbd
import { describe, test, expect, Result } from './tests.uts'
export function testForLoop(): Result {
return describe('ForLoop', () => {
test('syntax', () => {
const result: number[] = []
for (let i = 0; i < 5; i++) {
result.push(i)
}
expect(result).toEqual([0, 1, 2, 3, 4])
const result1: number[] = []
for (let i = 4; i >= 0; i--) {
result1.push(i)
}
expect(result1).toEqual([4, 3, 2, 1, 0])
const result2: number[] = []
let limit = 3
for (let i = 0; i < limit; i++) {
result2.push(i)
if (i === 2) {
limit = 5
}
}
expect(result2).toEqual([0, 1, 2, 3, 4])
const result3: number[] = []
const condition = true
for (let i = 0; condition; i++) {
if (i === 5) {
break
}
result3.push(i)
}
expect(result3).toEqual([0, 1, 2, 3, 4])
const result4: number[] = []
let i = 0
const fnCondition = (): boolean => i < 5
for (; fnCondition(); i++) {
result4.push(i)
}
expect(result4).toEqual([0, 1, 2, 3, 4])
const result5: number[] = []
let counter = 0
for (;;) {
result5.push(counter)
counter++
if (counter === 5) {
break
}
}
expect(result5).toEqual([0, 1, 2, 3, 4])
let result6 = 0
for (; result6 < 5; result6++);
expect(result6).toEqual(5)
})
test('break and continue', () => {
const result: number[] = []
for (let i = 0; i < 5; i++) {
if (i === 2) {
continue
}
if (i === 4) {
break
}
result.push(i)
}
expect(result).toEqual([0, 1, 3])
const result1: number[] = []
for (let i = 1; i <= 5; i++) {
result1.push(i)
if (i === 3) {
break
}
for (let j = 1; j <= 3; j++) {
result1.push(j)
if (j === 2) {
continue
}
}
}
expect(result1).toEqual([1, 1, 2, 3, 2, 1, 2, 3, 3])
const result2: string[] = []
for (let i = 1; i <= 3; i++) {
if (i === 2) {
continue
}
for (let j = 1; j <= 3; j++) {
if (j === 2) {
break
}
for (let k = 1; k <= 3; k++) {
if (k === 2) {
continue
}
for (let l = 1; l <= 3; l++) {
if (l === 2) {
continue
}
result2.push(`${i}${j}${k}${l}`)
if (i === 3 && j === 3 && k === 3 && l === 3) {
break
}
}
if (i === 3 && j === 3 && k === 3) {
break
}
}
}
}
expect(result2).toEqual([
'1111',
'1113',
'1131',
'1133',
'3111',
'3113',
'3131',
'3133'
])
// const result3 : string[] = []
// for (let i = 1; i <= 3; i++) {
// if (i === 2) {
// result3.push(`i=${i} (Continue)`)
// continue
// }
// for (let j = 1; j <= 2; j++) {
// if (j === 1) {
// result3.push(`i=${i}, j=${j}`)
// } else {
// result3.push(`i=${i}, j=${j} (Continue)`)
// continue
// }
// TODO 多个表达式
// for (let k = 1, l = 3; k <= 3 && l >= 1; k++, l--) {
// if (k === 2) {
// result3.push(`i=${i}, j=${j}, k=${k} (Continue)`)
// continue
// }
// if (l === 2) {
// result3.push(`i=${i}, j=${j}, k=${k}, l=${l} (Break)`)
// break
// }
// result3.push(`i=${i}, j=${j}, k=${k}, l=${l}`)
// }
// }
// }
// expect(result3).toEqual([
// "i=1, j=1",
// "i=1, j=1, k=1, l=3",
// "i=1, j=1, k=2 (Continue)",
// "i=1, j=1, k=3, l=1",
// "i=1, j=2 (Continue)",
// "i=2 (Continue)",
// "i=3, j=1",
// "i=3, j=1, k=1, l=3",
// "i=3, j=1, k=2 (Continue)",
// "i=3, j=1, k=3, l=1",
// "i=3, j=2 (Continue)"
// ])
const result4: string[] = []
for (let a = 1; a <= 2; a++) {
for (let b = 1; b <= 3; b++) {
for (let c = 1; c <= 2; c++) {
if (a === 2 && b === 2 && c === 1) {
result4.push(`a=${a}, b=${b}, c=${c} (Break)`)
break
} else {
result4.push(`a=${a}, b=${b}, c=${c}`)
}
for (let d = 1; d <= 3; d++) {
if (d === 2) {
result4.push(`a=${a}, b=${b}, c=${c}, d=${d} (Continue)`)
continue
}
for (let e = 1; e <= 2; e++) {
if (e === 2) {
result4.push(
`a=${a}, b=${b}, c=${c}, d=${d}, e=${e} (Continue)`
)
continue
}
for (let f = 1; f <= 3; f++) {
if (f === 2) {
result4.push(
`a=${a}, b=${b}, c=${c}, d=${d}, e=${e}, f=${f} (Continue)`
)
continue
}
}
}
}
}
}
}
expect(result4).toEqual([
'a=1, b=1, c=1',
'a=1, b=1, c=1, d=1, e=1, f=2 (Continue)',
'a=1, b=1, c=1, d=1, e=2 (Continue)',
'a=1, b=1, c=1, d=2 (Continue)',
'a=1, b=1, c=1, d=3, e=1, f=2 (Continue)',
'a=1, b=1, c=1, d=3, e=2 (Continue)',
'a=1, b=1, c=2',
'a=1, b=1, c=2, d=1, e=1, f=2 (Continue)',
'a=1, b=1, c=2, d=1, e=2 (Continue)',
'a=1, b=1, c=2, d=2 (Continue)',
'a=1, b=1, c=2, d=3, e=1, f=2 (Continue)',
'a=1, b=1, c=2, d=3, e=2 (Continue)',
'a=1, b=2, c=1',
'a=1, b=2, c=1, d=1, e=1, f=2 (Continue)',
'a=1, b=2, c=1, d=1, e=2 (Continue)',
'a=1, b=2, c=1, d=2 (Continue)',
'a=1, b=2, c=1, d=3, e=1, f=2 (Continue)',
'a=1, b=2, c=1, d=3, e=2 (Continue)',
'a=1, b=2, c=2',
'a=1, b=2, c=2, d=1, e=1, f=2 (Continue)',
'a=1, b=2, c=2, d=1, e=2 (Continue)',
'a=1, b=2, c=2, d=2 (Continue)',
'a=1, b=2, c=2, d=3, e=1, f=2 (Continue)',
'a=1, b=2, c=2, d=3, e=2 (Continue)',
'a=1, b=3, c=1',
'a=1, b=3, c=1, d=1, e=1, f=2 (Continue)',
'a=1, b=3, c=1, d=1, e=2 (Continue)',
'a=1, b=3, c=1, d=2 (Continue)',
'a=1, b=3, c=1, d=3, e=1, f=2 (Continue)',
'a=1, b=3, c=1, d=3, e=2 (Continue)',
'a=1, b=3, c=2',
'a=1, b=3, c=2, d=1, e=1, f=2 (Continue)',
'a=1, b=3, c=2, d=1, e=2 (Continue)',
'a=1, b=3, c=2, d=2 (Continue)',
'a=1, b=3, c=2, d=3, e=1, f=2 (Continue)',
'a=1, b=3, c=2, d=3, e=2 (Continue)',
'a=2, b=1, c=1',
'a=2, b=1, c=1, d=1, e=1, f=2 (Continue)',
'a=2, b=1, c=1, d=1, e=2 (Continue)',
'a=2, b=1, c=1, d=2 (Continue)',
'a=2, b=1, c=1, d=3, e=1, f=2 (Continue)',
'a=2, b=1, c=1, d=3, e=2 (Continue)',
'a=2, b=1, c=2',
'a=2, b=1, c=2, d=1, e=1, f=2 (Continue)',
'a=2, b=1, c=2, d=1, e=2 (Continue)',
'a=2, b=1, c=2, d=2 (Continue)',
'a=2, b=1, c=2, d=3, e=1, f=2 (Continue)',
'a=2, b=1, c=2, d=3, e=2 (Continue)',
'a=2, b=2, c=1 (Break)',
'a=2, b=3, c=1',
'a=2, b=3, c=1, d=1, e=1, f=2 (Continue)',
'a=2, b=3, c=1, d=1, e=2 (Continue)',
'a=2, b=3, c=1, d=2 (Continue)',
'a=2, b=3, c=1, d=3, e=1, f=2 (Continue)',
'a=2, b=3, c=1, d=3, e=2 (Continue)',
'a=2, b=3, c=2',
'a=2, b=3, c=2, d=1, e=1, f=2 (Continue)',
'a=2, b=3, c=2, d=1, e=2 (Continue)',
'a=2, b=3, c=2, d=2 (Continue)',
'a=2, b=3, c=2, d=3, e=1, f=2 (Continue)',
'a=2, b=3, c=2, d=3, e=2 (Continue)'
])
const result5: string[] = []
for (let i = 1; i <= 5; i++) {
let str = `${i}: `
if (i % 2 === 0) {
str += 'EVEN'
} else {
str += 'ODD'
}
if (i === 3) {
result5.push(str + ' (Loop Break)')
break
}
for (let j = 1; j <= 3; j++) {
if (j === 2) {
str += ' (Inner Continue)'
continue
}
str += ` - ${j}`
result5.push(str)
}
result5.push(str + ' (End of Outer)')
}
expect(result5).toEqual([
'1: ODD - 1',
'1: ODD - 1 (Inner Continue) - 3',
'1: ODD - 1 (Inner Continue) - 3 (End of Outer)',
'2: EVEN - 1',
'2: EVEN - 1 (Inner Continue) - 3',
'2: EVEN - 1 (Inner Continue) - 3 (End of Outer)',
'3: ODD (Loop Break)'
])
})
})
}
uni_modules/uts-tests/utssdk/index.uts
浏览文件 @
5ff6bcbd
...
@@ -10,50 +10,38 @@ import { testSet } from './Set.uts'
...
@@ -10,50 +10,38 @@ import { testSet } from './Set.uts'
import { testOperators } from './Operators.uts'
import { testOperators } from './Operators.uts'
import { testMath } from './Math.uts'
import { testMath } from './Math.uts'
import { testRegExp } from './RegExp.uts'
import { testRegExp } from './RegExp.uts'
// #ifdef APP-ANDROID
import { testForLoop } from './ForLoop.uts'
// import { testReactiveArray } from './reactiveArray.uts'
// import { testReactiveMap } from './ReactiveMap.uts'
// #endif
export { Result } from './tests.uts'
export { Result } from './tests.uts'
// Promise、Proxy、Reflect、Weakmap、WeakSet 不支持
// Promise、Proxy、Reflect、Weakmap、WeakSet 不支持
export function runTests() : UTSJSONObject {
export function runTests() : UTSJSONObject {
const ArrayRes = testArray();
const ArrayRes = testArray();
const DateRes = testDate();
const DateRes = testDate();
const StringRes = testString();
const StringRes = testString();
const ErrorRes = testError();
const ErrorRes = testError();
const JsonRes = testJSON();
const JsonRes = testJSON();
const NumberRes = testNumber();
const NumberRes = testNumber();
const MapRes = testMap();
const MapRes = testMap();
const SetRes = testSet();
const SetRes = testSet();
const OperatorsRes = testOperators();
const OperatorsRes = testOperators();
const MathRes = testMath();
const MathRes = testMath();
const RegExpRes = testRegExp();
const RegExpRes = testRegExp();
const KeyWordRes = testKeyWord();
const KeyWordRes = testKeyWord();
const ForLoopRes = testForLoop();
// #ifdef APP-ANDROID
// const ReactiveArrayRes = testReactiveArray();
// const ReactiveMapRes = testReactiveMap();
// #endif
return {
return {
Array: ArrayRes,
Array: ArrayRes,
// #ifdef APP-ANDROID
Date: DateRes,
// ReactiveArray: ReactiveArrayRes,
String: StringRes,
// #endif
Error: ErrorRes,
Date: DateRes,
Json: JsonRes,
String: StringRes,
Number: NumberRes,
Error: ErrorRes,
Map: MapRes,
Json: JsonRes,
Set: SetRes,
Number: NumberRes,
Operators: OperatorsRes,
Map: MapRes,
Math: MathRes,
// #ifdef APP-ANDROID
RegExp: RegExpRes,
// ReactiveMap: ReactiveMapRes,
KeyWord: KeyWordRes,
// #endif
ForLoop: ForLoopRes,
Set: SetRes,
}
Operators: OperatorsRes,
Math: MathRes,
RegExp: RegExpRes,
KeyWord:KeyWordRes
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录