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