• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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
16enum Color { Red, Green, Blue }
17
18class A {
19  public c: Color;
20  public constructor(c_: Color) {
21    this.c = c_;
22  }
23}
24
25function colorToInt(c: Color): int {
26  return c as int;
27}
28
29function main(): void {
30  let red: Color = Color.Red;
31  assertEQ(red, Color.Red)
32  assertEQ(colorToInt(red), 0)
33
34  let red2: Color = red;
35  assertEQ(red, red2)
36  assertEQ(Color.Red, red2)
37
38  let red_int: int = red as int;
39  assertEQ(red_int, 0)
40  assertEQ(red_int, Color.Red as int)
41
42  let a: A = new A(red);
43  assertEQ(a.c, Color.Red)
44
45  switch(red) {
46    case Color.Green:
47      assertTrue(false)
48      break;
49    case Color.Red:
50      assertTrue(true)
51      break;
52    default:
53      assertTrue(false)
54  }
55
56  switch(Color.Blue) {
57    case Color.Green:
58    case Color.Red:
59      assertTrue(false)
60      break;
61    case Color.Blue:
62      assertTrue(true)
63      break;
64    default:
65      assertTrue(false)
66  }
67}
68