1 /**
2 * Copyright (c) 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
16 #include "cfg_test.h"
17
18 namespace ark::es2panda::compiler {
19
TEST_F(CFGTest,switch_statement_01)20 TEST_F(CFGTest, switch_statement_01)
21 {
22 char const *text = R"(
23 function getDayName(day: int): string {
24 let dayName: string;
25
26 switch (day) {
27 case 1:
28 case 2:
29 case 3:
30 case 4:
31 case 5:
32 dayName = "Weekday";
33 break;
34 case 6:
35 dayName = "Weekend";
36 break;
37 case 7:
38 dayName = "Weekend";
39 break;
40 default:
41 dayName = "Invalid day!";
42 }
43
44 return dayName;
45 }
46
47 let str: string = getDayName(1);
48 )";
49
50 CONTEXT(ES2PANDA_STATE_CHECKED, text)
51 {
52 CFG *cfg = GetCfg();
53 ASSERT_TRUE(cfg != nullptr);
54
55 const ArenaSet<compiler::CFG::BasicBlock *> basicBlocks = cfg->GetBasicBlocks();
56 ASSERT_EQ(basicBlocks.size(), EXPECTED_FIFTEEN);
57
58 auto bb2 = GetBBByID(basicBlocks, ID_02);
59 ASSERT_NE(bb2, nullptr);
60
61 ASSERT_EQ(bb2->GetSuccessors().size(), EXPECTED_ONE);
62 ASSERT_EQ(bb2->GetPredecessors().size(), 0);
63
64 auto bb13 = GetBBByID(basicBlocks, ID_13);
65 ASSERT_NE(bb13, nullptr);
66
67 ASSERT_EQ(bb13->GetSuccessors().size(), EXPECTED_ONE);
68 ASSERT_EQ(bb13->GetPredecessors().size(), EXPECTED_FIVE);
69 }
70 }
71
72 } // namespace ark::es2panda::compiler
73