提交 70c91cb7 编写于 作者: 雪洛's avatar 雪洛

fix: 修复语法及用法错误

上级 559e20aa
......@@ -300,8 +300,8 @@ export function testArray() : Result {
})
test("of-1", () => {
let a1 = Array.of('foo', 2, 'bar', true)
let a2 = Array.of()
let a1 = Array.of<any>('foo', 2, 'bar', true)
let a2 = Array.of<any>()
console.log(a1,a2)
type User = {
id:number
......@@ -311,7 +311,7 @@ export function testArray() : Result {
id:1001,
name:"张三"
} as User
let a3 = Array.of("aaa",false,u1)
let a3 = Array.of<any>("aaa",false,u1)
expect(a1).toEqual([ "foo", 2, "bar", true ]);
expect(a2).toEqual([]);
// #ifdef APP-ANDROID
......@@ -324,7 +324,12 @@ export function testArray() : Result {
let a1 = Array.from('foo')
let a2 = Array.from([1, 2, 3], function(x:any|null,index:number){
// #ifdef APP
return (x as Number).toInt() + (x as Number).toInt()
// #endif
// #ifndef APP
return (x as number) + (x as number)
// #endif
})
// #ifdef APP-ANDROID
expect(a1).toEqual(["f", "o", "o"]);
......@@ -360,13 +365,14 @@ export function testArray() : Result {
});
// #endif
// #ifdef APP
let s1 = new Set([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)])
Array.fromAsync(
s1
).then((array) => {
expect(array).toEqual([1, 2, 3]);
});
// #endif
// #ifdef APP-ANDROID
UTSAndroid.getDispatcher("io").async(function(_){
......
......@@ -107,7 +107,7 @@ export function testMath() : Result {
expect(difference(5, 3)).toEqual(2);
expect(difference(1.23456, 7.89012)).toEqual(6.6555599999999995);
let utsNumber1 = JSON.parse("-160")! as Number
let utsNumber1 = JSON.parse("-160")! as number
expect(Math.abs(utsNumber1)).toEqual(160);
let utsNumber2 = Math.abs(0) - 0.123456
......
......@@ -379,10 +379,10 @@ export function testNumber() : Result {
expect(a10 == b10).toEqual(true);
expect(a10 === b10).toEqual(true);
let num1:Any = 1.0
let num1:any = 1.0
let num2 = 1
console.log(num1 == num2)
let num3:Any = 112233
let num3:any = 112233
let num4 = 112233.0
console.log(num3 == num4)
......
......@@ -123,8 +123,8 @@ export function testOperators(): Result {
expect(divide(16788990015, 5)).toEqualNumber(3357798003);
expectNumber(divide(16788990015, 10088990000)).toEqualDouble(1.6640902622561822);
let utsNum1 = JSON.parse("0.123456")! as Number
let utsNum2 = JSON.parse("0.123456")! as Number
let utsNum1 = JSON.parse("0.123456")! as number
let utsNum2 = JSON.parse("0.123456")! as number
let utsNum3 = utsNum1 / utsNum2
expect(utsNum3).toEqualNumber(1);
......
......@@ -321,7 +321,7 @@ export function testPromise() : Result {
console.log(res);
let statusArr : string[] = []
res.forEach((item, index : number) => {
statusArr.add(item.status)
statusArr.push(item.status)
})
expect(statusArr).toEqual(["fulfilled", "fulfilled", "rejected", "rejected"])
})
......
......@@ -276,7 +276,7 @@ export function testUTSJSONObject() : Result {
}
}
//返回指定键对应的值,如果对象中不存在此键则返回 null。
let name : string = person["name"] as String
let name : string = person["name"] as string
//get 方法可以简化为使用下标运算符 `[]` 访问
name = person['name'] as string
//增加或更新指定键对应的值。
......
......@@ -54,9 +54,7 @@ export function runTests() : UTSJSONObject {
const TextDecoderRes = testDecoder();
// #endif
// #ifdef APP-IOS || APP-ANDROID
const IteratorRes = testIterator()
// #endif
return {
Array: ArrayRes,
......@@ -85,8 +83,6 @@ export function runTests() : UTSJSONObject {
NativeCode: NativeCodeRes,
Primise: PromiseRes,
// #ifdef APP-IOS || APP-ANDROID
Iterator: IteratorRes
// #endif
Iterator: IteratorRes
}
}
\ No newline at end of file
......@@ -14,14 +14,10 @@ import { describe, test, expect, Result } from './tests.uts'
class TestChild implements UTSValueIterable<any | null> {
a: string = ""
b: Int = 1
b: number = 1
c: boolean = false
holderArray: (any | null)[] = [11, 22, null, 33, 44, null];
constructor(){
super()
}
ignoredKeys(): string[] {
......@@ -33,8 +29,8 @@ class TestChild implements UTSValueIterable<any | null> {
valueIterator(): UTSIterator<any | null> {
let holderIndex = 0;
let obj: UTSIterator<any | null> = {
next(): UTSIteratorResult<any | null> {
return UTSIteratorResult<any | null>(holderIndex == this.holderArray.size - 1, this.holderArray[holderIndex++])
next: (): UTSIteratorResult<any | null> => {
return UTSIteratorResult<any | null>(holderIndex == this.holderArray.length - 1, this.holderArray[holderIndex++])
}
}
return obj
......@@ -44,14 +40,11 @@ class TestChild implements UTSValueIterable<any | null> {
class TestClass implements UTSValueIterable<any | null> {
holderArray: (any | null)[] = [null, null]
constructor(){
super()
}
valueIterator(): UTSIterator<any | null> {
let holderIndex = 0;
let obj: UTSIterator<any | null> = {
next(): UTSIteratorResult<any | null> {
next: (): UTSIteratorResult<any | null> => {
let currentVal = this.holderArray[holderIndex++]
while(currentVal == null ){
......@@ -73,14 +66,11 @@ class TestChild implements UTSValueIterable<any | null> {
class TestClass2 implements UTSValueIterable<any | null> {
holderArray: (any | null)[] = [11, 22, null, 33, 44, null]
constructor(){
super()
}
valueIterator(): UTSIterator<any | null> {
let holderIndex = 0;
let obj: UTSIterator<any | null> = {
next(): UTSIteratorResult<any | null> {
next: (): UTSIteratorResult<any | null> => {
let currentVal = this.holderArray[holderIndex++]
while(currentVal == null ){
......@@ -103,14 +93,10 @@ class TestChild implements UTSValueIterable<any | null> {
holderArray: (any | null)[] = [11, 22, null, 33, 44, null]
constructor(){
super()
}
valueIterator(): UTSIterator<any | null> {
let holderIndex = 0;
let obj: UTSIterator<any | null> = {
next(): UTSIteratorResult<any | null> {
next: (): UTSIteratorResult<any | null> => {
return UTSIteratorResult<any | null>(holderIndex == this.holderArray.length - 1, this.holderArray[holderIndex++])
}
}
......@@ -141,7 +127,7 @@ export function testIterator(): Result {
let arr = ["a", "b", "c", "d"]
let result1: string[] = []
for (let item of arr) {
result1.add(item)
result1.push(item)
}
expect(result1).toEqual(["a", "b", "c", "d"])
......@@ -153,7 +139,7 @@ export function testIterator(): Result {
//let result2: [any] = []
let result2: Array<any> = []
for (let item of dic) {
result2.add(item)
result2.push(item)
}
// #ifdef APP-ANDROID
expect(result2).toEqual(
......@@ -168,37 +154,37 @@ export function testIterator(): Result {
set.add("c")
var result3: any[] = []
for (let item of set) {
result3.add(item)
result3.push(item)
}
expect(result3).toEqual(["a", "b", "c"])
// test Class for UTSValueIterable
let test = new TestChild()
let result4: (any | null)[] = []
for (item of test) {
result4.add(item)
for (let item of test) {
result4.push(item)
}
expect(result4).toEqual([11, 22, null, 33, 44, null])
let test221 = new TestClass()
let forofRet:Array<Any|null> = []
for (item of test221) {
forofRet.add(item)
let forofRet:Array<any|null> = []
for (let item of test221) {
forofRet.push(item)
}
expect(forofRet).toEqual([11, 22, null, 33, 44, null])
let test222 = new TestClass2()
let forofRet2:Array<Any|null> = []
for (item of test222) {
forofRet2.add(item)
let forofRet2:Array<any|null> = []
for (let item of test222) {
forofRet2.push(item)
}
expect(forofRet2).toEqual([11, 22, 33, 44, ])
let test223 = new TestClass3()
let forofRet3:Array<Any|null> = []
for (item of test223) {
forofRet3.add(item)
let forofRet3:Array<any|null> = []
for (let item of test223) {
forofRet3.push(item)
}
expect(forofRet3).toEqual([11, 22, null, 33, 44, null])
......
......@@ -43,7 +43,7 @@ export function test(name: string, fn: () => void) {
result.passed.push(name)
// console.log('push....',result.passed.length)
} catch (e) {
result.failed.push(`${name}:\n${e.message}`)
result.failed.push(`${name}:\n${(e as Error).message}`)
}
result.total++
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册