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
16function testTypeConvert() {
17    let a = 0;
18    if (a == 0 && a == 0.0) {
19        print("good");
20    } else {
21        print("bad")
22    }
23    if (a == "0" || a === "0" || a == false || a === false) {
24        print("good1");
25    } else {
26        print("good2");
27    }
28    if (a <= "0" || a >= "0" || a <= false || a >= false) {
29        print("good3");
30    } else {
31        print("good4");
32    }
33    if (a < "0" || a > "0" || a < false || a > false) {
34        print("good5");
35    } else {
36        print("good6");
37    }
38}
39
40function testIntNumber() {
41    let init = 1;
42    let a = init;
43    if (false) {
44        a = 10;
45    }
46    if (a != 1 || a == 0 || a !== 1 || a === 0 || a < 0 || a > 1 || a <= 0 || a >= 2) {
47        print("bad");
48    } else {
49        print("good");
50    }
51}
52
53function testFloatNumber() {
54    let init = 0.1;
55    let a = init;
56    if (false) {
57        a = 10.0;
58    }
59    if (a != 0.1 || a == 1.1 || a !== 0.1 || a === 1.1 || a < 0.1 || a > 0.1 || a <= 0.01 || a >= 1.1) {
60        print("bad");
61    } else {
62        print("good");
63    }
64}
65
66
67function testBool() {
68    let init = false;
69    let a = init;
70    if (a) {
71        a = true;
72    }
73    if (a != false || a == true || a !== false || a === true || a < false || a > true) {
74        print("bad");
75    } else {
76        print("good");
77    }
78}
79
80function testString() {
81    let init = "0";
82    let a = init;
83    if (false) {
84        a = "1";
85    }
86    if (a != "0" || a == "1" || a !== "0" || a === "1") {
87        print("bad");
88    } else {
89        print("good");
90    }
91    // not folding </<=/>/>= for strings
92    if (a <= "0" || a >= "1" || a < "0" || a > "1") {
93        print("good2");
94    } else {
95        print("good3");
96    }
97}
98
99function testBBStruct() {
100    if (false || true) {
101        print("good");
102    }
103    if (false && true) {
104        print("bad");
105    }
106    if (true && false) {
107        print("bad");
108    }
109    if (false) {
110        if (true) {
111            print("bad");
112        }
113    }
114    if (true) {
115        if (false) {
116            print("bad");
117        }
118    }
119    while (false) {
120        print("bad");
121    }
122}
123
124testTypeConvert();
125testIntNumber();
126testFloatNumber();
127testBool();
128testString();
129testBBStruct();