• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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
16function f(b?: boolean | string | null | int | object): string {
17    return !b ? "not good" : "good";
18}
19
20function f1(b?: boolean | string | null | int | object): string {
21    return b ? "not good" : "good";
22}
23
24function f2(): void {
25    let result = (2 + 2 === 4) ? "Yes" : "No";
26    assertEQ(result, "Yes");
27    let result1 = (2 + 2 !== 4) ? "Yes" : "No";
28    assertEQ(result1, "No");
29    let result2 = (2 > 4) ? "Yes" : "No";
30    assertEQ(result2, "No");
31    let result3 = (2 < 4) ? "Yes" : "No";
32    assertEQ(result3, "Yes");
33}
34
35function f3(): void {
36    let result = true ? 1 : (false ? 2 : 3);
37    assertEQ(result, 1);
38    let result1 = false ? 1 : (false ? 2 : 3);
39    assertEQ(result1, 3);
40}
41
42function testF() {
43    assertEQ(f(true), "good");
44    assertEQ(f(false), "not good");
45    assertEQ(f("false"), "good");
46    assertEQ(f("true"), "good");
47    assertEQ(f(undefined), "not good");
48    assertEQ(f(null), "not good");
49    assertEQ(f(""), "not good");
50    assertEQ(f("Hello World"), "good");
51    assertEQ(f(0), "not good");
52    assertEQ(f(1), "good");
53    assertEQ(f({}), "good");
54    assertEQ(f(), "not good");
55}
56
57function testF1() {
58    assertEQ(f1(true), "not good");
59    assertEQ(f1(false), "good");
60    assertEQ(f1("false"), "not good");
61    assertEQ(f1("true"), "not good");
62    assertEQ(f1(undefined), "good");
63    assertEQ(f1(null), "good");
64    assertEQ(f1(""), "good");
65    assertEQ(f1("Hello World"), "not good");
66    assertEQ(f1(0), "good");
67    assertEQ(f1(1), "not good");
68    assertEQ(f1({}), "not good");
69    assertEQ(f1(), "good");
70}
71
72function main(): void {
73    testF();
74    testF1();
75    f2();
76    f3();
77}