1/*
2 * Copyright (c) 2022-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
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  assert red == Color.Red;
32  assert colorToInt(red) == 0;
33
34  let red2: Color = red;
35  assert red == red2;
36  assert Color.Red == red2;
37
38  let red_int: int = red as int;
39  assert red_int == 0;
40  assert red_int == Color.Red as int;
41
42  let a: A = new A(red);
43  assert a.c == Color.Red;
44
45  switch(red) {
46    case Color.Green:
47      assert false;
48      break;
49    case Color.Red:
50      assert true;
51      break;
52    default:
53      assert false;
54  }
55
56  switch(Color.Blue) {
57    case Color.Green:
58    case Color.Red:
59      assert false;
60      break;
61    case Color.Blue:
62      assert true;
63      break;
64    default:
65      assert false;
66  }
67}
68