1/* 2 * Copyright (c) Huawei Device Co., Ltd. 2021 - 2024. All rights reserved. 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 <gtest/gtest.h> 17#include "macros.h" 18#include "public/es2panda_lib.h" 19 20#include "test/utils/panda_executable_path_getter.h" 21 22class CheckerTest : public testing::Test { 23public: 24 CheckerTest() 25 { 26 impl_ = es2panda_GetImpl(ES2PANDA_LIB_VERSION); 27 auto es2pandaPath = test::utils::PandaExecutablePathGetter {}.Get(); 28 // NOLINTNEXTLINE(modernize-avoid-c-arrays) 29 char const *argv[] = {es2pandaPath.c_str()}; 30 cfg_ = impl_->CreateConfig(1, argv); 31 } 32 33 ~CheckerTest() override 34 { 35 impl_->DestroyConfig(cfg_); 36 } 37 38 NO_COPY_SEMANTIC(CheckerTest); 39 NO_MOVE_SEMANTIC(CheckerTest); 40 41protected: 42 // NOLINTBEGIN(misc-non-private-member-variables-in-classes) 43 es2panda_Impl const *impl_; 44 es2panda_Config *cfg_; 45 // NOLINTEND(misc-non-private-member-variables-in-classes) 46}; 47 48TEST_F(CheckerTest, ExtendedConditionalExpressionFunctor) 49{ 50 char const *text = R"XXX( 51class A { 52 m() {} 53 m2() { this.m ? "a": "b" } 54} 55)XXX"; 56 es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "dummy.sts"); 57 ctx = impl_->ProceedToState(ctx, ES2PANDA_STATE_CHECKED); 58 ASSERT_EQ(std::string(impl_->ContextErrorMessage(ctx)), 59 "TypeError: Condition must be of possible condition type[dummy.sts:4,12]"); 60 61 impl_->DestroyContext(ctx); 62} 63