1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16declare function print(str:any):string; 17var a : any[] = [ ["ok"], [1, 2, 3] ]; 18print(a[0][0]); 19print(a[1][0]); 20print(a[1][1]); 21print(a[1][2]); 22 23var b = { 24 1 : ["yes", "no"], 25 "100" : [4, 5], 26} 27print(b[1][0]); 28print(b[1][1]); 29print(b["100"][0]); 30print(b["100"][1]); 31 32class Attrs { 33 constructor(a : number, b : number, c : number) { 34 this.x = a; 35 this.y = b; 36 this.z = c; 37 } 38 x : number; 39 y : number; 40 z : number; 41} 42function test() : void { 43 for (let j = 0; j < 5; ++j) { 44 var _attrs : Attrs[] = [ 45 new Attrs(1, 1, 1), 46 new Attrs(2, 2, 2), 47 new Attrs(3, 3, 3), 48 new Attrs(4, 4, 4), 49 new Attrs(5, 5, 5), 50 ]; 51 print(_attrs[j].x); 52 } 53} 54test(); 55 56const tests = [ 57 [ 58 99.99, 59 "ark" 60 ], 61 [ 62 -88.48, 63 "brk" 64 ], 65 [ 66 -1024, 67 "crk" 68 ], 69 [ 70 6666, 71 "drk" 72 ], 73]; 74 75for (const [number, strData] of tests) { 76 print(number); 77 print(strData); 78} 79 80const units = [ 81 "second", 82 "minute", 83]; 84 85const exceptions = { 86 "minute": { 87 "-1": "1 minute ago", 88 '0': 'this minute', 89 "1": "in 1 minute", 90 }, 91 "second": { 92 "-1": "1 second ago", 93 "0": "now", 94 "1": "in 1 second", 95 }, 96}; 97 98{ 99 const v1 = new SendableInt8Array(SendableInt8Array, SendableInt8Array, SendableInt8Array); 100 let a = v1[Symbol.toStringTag]; 101 let c = [a]; 102} 103 104for (const unit of units) { 105 const expected = unit in exceptions 106 ? [exceptions[unit]["1"], exceptions[unit]["0"], exceptions[unit]["0"], exceptions[unit]["-1"]] 107 : [`in 1 ${unit}`, `in 0 ${unit}s`, `0 ${unit}s ago`, `1 ${unit} ago`]; 108 109 print(expected); 110} 111 112Object.defineProperty(Array.prototype, '0', { 113 value: 42, 114}); 115let arr = [, 2, 3]; 116arr.pop(); 117print(arr[1]); 118 119// TestTypedArrayFindLast 120{ 121 const LOOP_TIME = 20; 122 123 function func(element, Last, array) { 124 return element <= 0; 125 } 126 127 function TestTypedArrayFindLast(e) { 128 let arr = new e([-5, 10, 20, 30, -40, 50.5, -60.6]); 129 let result = arr.findLast(func); 130 } 131 132 for (let i = 0; i < LOOP_TIME; i++) { 133 TestTypedArrayFindLast(Int8Array); 134 } 135 136 for (let i = 0; i < LOOP_TIME; i++) { 137 TestTypedArrayFindLast(Uint8Array); 138 } 139 140 for (let i = 0; i < LOOP_TIME; i++) { 141 TestTypedArrayFindLast(Uint8ClampedArray); 142 } 143 144 for (let i = 0; i < LOOP_TIME; i++) { 145 TestTypedArrayFindLast(Int16Array); 146 } 147 148 for (let i = 0; i < LOOP_TIME; i++) { 149 TestTypedArrayFindLast(Uint16Array); 150 } 151 152 for (let i = 0; i < LOOP_TIME; i++) { 153 TestTypedArrayFindLast(Int32Array); 154 } 155 156 for (let i = 0; i < LOOP_TIME; i++) { 157 TestTypedArrayFindLast(Uint32Array); 158 } 159 160 for (let i = 0; i < LOOP_TIME; i++) { 161 TestTypedArrayFindLast(Float32Array); 162 } 163 164 for (let i = 0; i < LOOP_TIME; i++) { 165 TestTypedArrayFindLast(Float64Array); 166 } 167} 168