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