• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 <gtest/gtest.h>
17 #include "mangling.h"
18 #include "assembly-function.h"
19 #include "extensions/extensions.h"
20 
21 using namespace panda::pandasm;
22 
TEST(mangling_tests,MangleFunctionName)23 TEST(mangling_tests, MangleFunctionName)
24 {
25     std::vector<Function::Parameter> params;
26     panda::panda_file::SourceLang language {panda::panda_file::SourceLang::PANDA_ASSEMBLY};
27     params.emplace_back(Type {"type1", 0}, language);
28     params.emplace_back(Type {"type2", 0}, language);
29     params.emplace_back(Type {"type3", 0}, language);
30 
31     auto return_type = Type("type4", 0);
32 
33     std::string name = "Asm.main";
34     ASSERT_EQ(MangleFunctionName(name, std::move(params), return_type), "Asm.main:type1;type2;type3;type4;");
35 }
36 
TEST(mangling_tests,DeMangleFunctionName)37 TEST(mangling_tests, DeMangleFunctionName)
38 {
39     std::string name = "Asm.main:type1;type2;type3;type4;";
40     ASSERT_EQ(DeMangleName(name), "Asm.main");
41 }
42 
TEST(mangling_tests,GetFunctionSignatureFromName)43 TEST(mangling_tests, GetFunctionSignatureFromName)
44 {
45     std::vector<Function::Parameter> params;
46     panda::panda_file::SourceLang language {panda::panda_file::SourceLang::PANDA_ASSEMBLY};
47     params.emplace_back(Type {"type1", 0}, language);
48     params.emplace_back(Type {"type2", 0}, language);
49     params.emplace_back(Type {"type3", 0}, language);
50 
51     std::string name = "Asm.main";
52     ASSERT_EQ(GetFunctionSignatureFromName(name, std::move(params)), "Asm.main:(type1,type2,type3)");
53 }
54 
TEST(mangling_tests,GetFunctionNameFromSignature)55 TEST(mangling_tests, GetFunctionNameFromSignature)
56 {
57     std::string name = "Asm.main:(type1,type2,type3,type4)";
58     ASSERT_EQ(GetFunctionNameFromSignature(name), "Asm.main");
59 }