• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ES2PANDA_TEST_UNIT_PLUGIN_UTIL_H
17 #define ES2PANDA_TEST_UNIT_PLUGIN_UTIL_H
18 
19 #include <functional>
20 #include <iostream>
21 #include <string_view>
22 #include <map>
23 #include <vector>
24 
25 #include "os/library_loader.h"
26 
27 #include "public/es2panda_lib.h"
28 
29 constexpr int MIN_ARGC = 3;
30 
31 // error code number
32 constexpr int NULLPTR_IMPL_ERROR_CODE = 2;
33 constexpr int PROCEED_ERROR_CODE = 3;
34 constexpr int TEST_ERROR_CODE = 4;
35 constexpr int INVALID_ARGC_ERROR_CODE = 5;
36 constexpr int NULLPTR_CONTEXT_ERROR_CODE = 6;
37 
38 es2panda_Impl *GetImpl();
39 
40 struct ProccedToStatePluginTestData {
41     int argc;
42     char **argv;
43     es2panda_Impl **impl;
44     std::map<es2panda_ContextState, std::vector<std::function<bool(es2panda_Context *)>>> testFunctions;
45     bool fromSource;
46     std::string source;
47     es2panda_ContextState exitAfterState = ES2PANDA_STATE_ERROR;
48 };
49 
50 void CheckForErrors(const std::string &stateName, es2panda_Context *context);
51 bool IsAssertCall(es2panda_AstNode *ast);
52 es2panda_AstNode *CreateAssertStatement(es2panda_Context *context, es2panda_AstNode *test, es2panda_AstNode *second);
53 es2panda_AstNode *AssertStatementTest(es2panda_Context *context, es2panda_AstNode *classInstance);
54 int RunAllStagesWithTestFunction(ProccedToStatePluginTestData &data);
55 
56 es2panda_AstNode *CreateIdentifierFromString(es2panda_Context *context, const std::string_view &name);
57 
58 void AppendStatementToProgram(es2panda_Context *context, es2panda_AstNode *program, es2panda_AstNode *newStatement);
59 
60 void PrependStatementToProgram(es2panda_Context *context, es2panda_AstNode *program, es2panda_AstNode *newStatement);
61 
62 int Test(es2panda_Context *context, es2panda_Impl *impl, int stage,
63          const std::function<bool(es2panda_Context *, es2panda_AstNode *)> &handle);
64 
65 #endif
66