1/*
2 * Copyright (c) 2024 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
16class C  {
17  constructor() {}
18
19  constructor(a: int) {
20    this.x = a;
21  }
22
23  bar(): string {
24    return "Class C";
25  }
26
27  baz(): int {
28    return this.x;
29  }
30
31  private x: int = 7;
32}
33
34function foo(c: Object|null|undefined): string {
35  if (c instanceof string && (c.length == 11 || c == "Test"))  {
36    c = "Case 1";
37  } else if (c instanceof C && c.baz() == 7) {
38    assert(c.bar() == "Class C")
39    c = "Case 2";
40  } else if (c instanceof Int && c >= 0) {
41    assert(c >= 0);
42    c = "Case 3";
43  } else if (c instanceof null) {
44    assert(c == null);
45    c = "Case 4";
46  } else {
47    c = "Case 5";
48  }
49
50  assert(c.length == 6);
51  return c;
52}
53
54function main(): void {
55  assert(foo("Test string") == "Case 1");
56  assert(foo("Test") == "Case 1");
57  assert(foo("Test string 2") == "Case 5");
58  assert(foo("test") == "Case 5");
59
60  assert(foo(new Int(5)) == "Case 3");
61  assert(foo(new Int(0)) == "Case 3");
62  assert(foo(new Int(-5)) == "Case 5");
63
64  assert(foo(new C(7)) == "Case 2");
65  assert(foo(new C()) == "Case 2");
66  assert(foo(new C(17)) == "Case 5");
67
68  assert(foo(null) == "Case 4");
69
70  assert(foo(undefined) == "Case 5");
71  assert(foo(new Number(3.0)) == "Case 5");
72}
73