• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 main() {
17    let x0 : int | String | boolean = 2;
18    assert (x0 as int) * 2 == 4: "Error! Must be 4";
19    x0 = -2;
20    assert (x0 as int) * 3 == -6: "Error! Must be -6";
21    x0 = true
22    assert (x0 as boolean) == true: "Error! Must be true";
23    x0 = "STR1"
24    assert ((x0 as String) + "STR2").equals("STR1STR2"): "Error! Must be `STR1STR2`";
25    let x1 : String | boolean = "AAA";
26    if (x1 instanceof String) {
27        assert (x1 as String).equals("AAA"): "Error! Must be `AAA`";
28    }
29    let x2 : String | boolean | int | double = true;
30    assert (x2 as boolean) == true: "Error! Must be `true`";
31    let x3 : String | boolean | int | double = 3.14;
32    // assert (x3 as double) == 3.14: "Error! Must be `3.14`"; // #15576
33    assert (x3 as Double) == 3.14: "Error! Must be `3.14`";
34}
35