1 /** 2 * Copyright (c) 2024-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 #ifndef ES2PANDA_TEST_UTILS_SCOPE_INIT_TEST_H 17 #define ES2PANDA_TEST_UTILS_SCOPE_INIT_TEST_H 18 19 #include "ir/expression.h" 20 #include "ir/statements/blockStatement.h" 21 #include "ir/statements/variableDeclarator.h" 22 #include "ir/statements/variableDeclaration.h" 23 #include "mem/pool_manager.h" 24 25 #include <gtest/gtest.h> 26 27 namespace ir_alias = ark::es2panda::ir; 28 29 namespace test::utils { 30 31 class ScopeInitTest : public testing::Test { 32 public: ScopeInitTest()33 ScopeInitTest() : allocator_(std::make_unique<ark::ArenaAllocator>(ark::SpaceType::SPACE_TYPE_COMPILER)) {} 34 35 /* 36 * Shortcut to convert single elemnt block expression body to it's name 37 * Example: { let x; } => x 38 */ 39 ir_alias::Identifier *BodyToFirstName(ir_alias::Statement *body); 40 SetUpTestCase()41 static void SetUpTestCase() 42 { 43 ark::mem::MemConfig::Initialize(0, 0, ark::es2panda::COMPILER_SIZE, 0, 0, 0); 44 ark::PoolManager::Initialize(); 45 } 46 Allocator()47 ark::ArenaAllocator *Allocator() 48 { 49 return allocator_.get(); 50 } 51 52 private: 53 std::unique_ptr<ark::ArenaAllocator> allocator_; 54 }; 55 56 } // namespace test::utils 57 58 #endif // ES2PANDA_TEST_UTILS_SCOPE_INIT_TEST_H 59