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

fix: 修复语法及用法错误

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