• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
99for (const unit of units) {
100	const expected = unit in exceptions
101		? [exceptions[unit]["1"], exceptions[unit]["0"], exceptions[unit]["0"], exceptions[unit]["-1"]]
102	  	: [`in 1 ${unit}`, `in 0 ${unit}s`, `0 ${unit}s ago`, `1 ${unit} ago`];
103
104	print(expected);
105}
106
107Object.defineProperty(Array.prototype, '0', {
108	value: 42,
109});
110let arr = [, 2, 3];
111arr.pop();
112print(arr[1]);