Changeset View
Changeset View
Standalone View
Standalone View
llvm/unittests/Demangle/ItaniumDemangleTest.cpp
//===------------------ ItaniumDemangleTest.cpp ---------------------------===// | //===------------------ ItaniumDemangleTest.cpp ---------------------------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "llvm/Demangle/ItaniumDemangle.h" | #include "llvm/Demangle/ItaniumDemangle.h" | ||||
#include "ItaniumDemangleTestUtils.h" | |||||
#include "llvm/IR/Argument.h" | |||||
#include "llvm/Support/Allocator.h" | #include "llvm/Support/Allocator.h" | ||||
#include "gmock/gmock.h" | #include "gmock/gmock.h" | ||||
#include "gtest/gtest.h" | #include "gtest/gtest.h" | ||||
#include <algorithm> | |||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <iterator> | |||||
#include <vector> | #include <vector> | ||||
using namespace llvm; | using namespace llvm; | ||||
using namespace llvm::itanium_demangle; | using namespace llvm::itanium_demangle; | ||||
using namespace llvm::itanium_demangle::test_utils; | |||||
namespace { | |||||
class TestAllocator { | |||||
BumpPtrAllocator Alloc; | |||||
public: | |||||
void reset() { Alloc.Reset(); } | |||||
template <typename T, typename... Args> T *makeNode(Args &&... args) { | |||||
return new (Alloc.Allocate(sizeof(T), alignof(T))) | |||||
T(std::forward<Args>(args)...); | |||||
} | |||||
void *allocateNodeArray(size_t sz) { | |||||
return Alloc.Allocate(sizeof(Node *) * sz, alignof(Node *)); | |||||
} | |||||
}; | |||||
} // namespace | |||||
namespace NodeMatcher { | namespace NodeMatcher { | ||||
// Make sure the node matchers provide constructor parameters. This is a | // Make sure the node matchers provide constructor parameters. This is a | ||||
// compilation test. | // compilation test. | ||||
template <typename NT> struct Ctor { | template <typename NT> struct Ctor { | ||||
template <typename... Args> void operator()(Args &&...args) { | template <typename... Args> void operator()(Args &&...args) { | ||||
auto _ = NT(std::forward<Args>(args)...); | auto _ = NT(std::forward<Args>(args)...); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | struct TestParser : AbstractManglingParser<TestParser, TestAllocator> { | ||||
} | } | ||||
}; | }; | ||||
// void f(A<_Float16>, _Float16); | // void f(A<_Float16>, _Float16); | ||||
TestParser Parser("_Z1f1AIDF16_EDF16_"); | TestParser Parser("_Z1f1AIDF16_EDF16_"); | ||||
ASSERT_NE(nullptr, Parser.parse()); | ASSERT_NE(nullptr, Parser.parse()); | ||||
EXPECT_THAT(Parser.Types, testing::ElementsAre("_Float16", "A", "_Float16")); | EXPECT_THAT(Parser.Types, testing::ElementsAre("_Float16", "A", "_Float16")); | ||||
} | } | ||||
TEST(ItaniumDemangle, Equality_NodeArray) { | |||||
ManglingNodeCreator Creator; | |||||
// Test empty NodeArray equality | |||||
std::vector<Node *> LHS; | |||||
std::vector<Node *> RHS; | |||||
// Empty == Empty | |||||
ASSERT_EQ(Creator.makeNodeArray(LHS.cbegin(), LHS.cend()), | |||||
Creator.makeNodeArray(RHS.cbegin(), RHS.cend())); | |||||
RHS.push_back(Creator.makeReferenceType(Qualifiers::QualNone, "test", | |||||
ReferenceKind::RValue)); | |||||
// Empty vs. non-empty | |||||
ASSERT_NE(Creator.makeNodeArray(LHS.cbegin(), LHS.cend()), | |||||
Creator.makeNodeArray(RHS.cbegin(), RHS.cend())); | |||||
LHS.push_back(Creator.makeReferenceType(Qualifiers::QualNone, "test", | |||||
ReferenceKind::RValue)); | |||||
// Equal single nodes | |||||
ASSERT_EQ(Creator.makeNodeArray(LHS.cbegin(), LHS.cend()), | |||||
Creator.makeNodeArray(RHS.cbegin(), RHS.cend())); | |||||
LHS.push_back(Creator.makeReferenceType(Qualifiers::QualNone, "test", | |||||
ReferenceKind::LValue)); | |||||
RHS.push_back(Creator.makeReferenceType(Qualifiers::QualRestrict, "test", | |||||
ReferenceKind::RValue)); | |||||
// Non-equal second node | |||||
ASSERT_NE(Creator.makeNodeArray(LHS.cbegin(), LHS.cend()), | |||||
Creator.makeNodeArray(RHS.cbegin(), RHS.cend())); | |||||
} | |||||
TEST(ItaniumDemangle, Equality_Node) { | |||||
ManglingNodeCreator Creator; | |||||
// Comparison of nodes with mismatching kinds should fail | |||||
ASSERT_FALSE(test_utils::compareNodes(Creator.make<NameType>("Foo"), | |||||
Creator.make<FloatLiteral>("1.0"))); | |||||
} | |||||
TEST(ItaniumDemangle, Equality_QualType) { | |||||
ManglingNodeCreator Creator; | |||||
{ | |||||
// Same qualifiers and name | |||||
Node const *Q1 = Creator.makeQualType("Test", Qualifiers::QualVolatile); | |||||
Node const *Q2 = Creator.makeQualType("Test", Qualifiers::QualVolatile); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Different qualifiers | |||||
Node const *Q1 = Creator.makeQualType("Test", Qualifiers::QualNone); | |||||
Node const *Q2 = Creator.makeQualType("Test", Qualifiers::QualRestrict); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *Q1 = Creator.makeQualType("Test", Qualifiers::QualNone); | |||||
Node const *Q2 = Creator.makeQualType("", Qualifiers::QualNone); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_NameType) { | |||||
ManglingNodeCreator Creator; | |||||
{ | |||||
// Both empty | |||||
Node const *Q1 = Creator.make<NameType>(""); | |||||
Node const *Q2 = Creator.make<NameType>(""); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Both non-empty | |||||
Node const *Q1 = Creator.make<NameType>("test"); | |||||
Node const *Q2 = Creator.make<NameType>("test"); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Not equal | |||||
Node const *Q1 = Creator.make<NameType>("test"); | |||||
Node const *Q2 = Creator.make<NameType>("tes"); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_ReferenceType) { | |||||
ManglingNodeCreator Creator; | |||||
{ | |||||
// Same type | |||||
Node const *Q1 = Creator.makeReferenceType(Qualifiers::QualVolatile, "Test", | |||||
ReferenceKind::LValue); | |||||
Node const *Q2 = Creator.makeReferenceType(Qualifiers::QualVolatile, "Test", | |||||
ReferenceKind::LValue); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *Q1 = Creator.makeReferenceType(Qualifiers::QualVolatile, "Test", | |||||
ReferenceKind::LValue); | |||||
Node const *Q2 = Creator.makeReferenceType(Qualifiers::QualVolatile, "Tes", | |||||
ReferenceKind::LValue); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Different CV-qualifiers | |||||
Node const *Q1 = Creator.makeReferenceType(Qualifiers::QualVolatile, "Test", | |||||
ReferenceKind::LValue); | |||||
Node const *Q2 = Creator.makeReferenceType(Qualifiers::QualRestrict, "Test", | |||||
ReferenceKind::LValue); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Different ref-qualifiers | |||||
Node const *Q1 = Creator.makeReferenceType(Qualifiers::QualVolatile, "Test", | |||||
ReferenceKind::LValue); | |||||
Node const *Q2 = Creator.makeReferenceType(Qualifiers::QualVolatile, "Test", | |||||
ReferenceKind::RValue); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_TemplateArgs) { | |||||
ManglingNodeCreator Creator; | |||||
std::vector<Node *> LHS; | |||||
std::vector<Node *> RHS; | |||||
{ | |||||
// Both empty | |||||
Node const *Q1 = Creator.makeTemplateArgs(LHS); | |||||
Node const *Q2 = Creator.makeTemplateArgs(RHS); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
LHS.push_back(Creator.make<NameType>("test")); | |||||
RHS.push_back(Creator.make<NameType>("test")); | |||||
{ | |||||
// Both equal | |||||
Node const *Q1 = Creator.makeTemplateArgs(LHS); | |||||
Node const *Q2 = Creator.makeTemplateArgs(RHS); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
LHS.push_back(Creator.make<NameType>("foo")); | |||||
RHS.push_back(Creator.make<NameType>("bar")); | |||||
{ | |||||
// Not equal anymore | |||||
Node const *Q1 = Creator.makeTemplateArgs(LHS); | |||||
Node const *Q2 = Creator.makeTemplateArgs(RHS); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_NameWithTemplateArgs) { | |||||
ManglingNodeCreator Creator; | |||||
{ | |||||
// No args | |||||
Node const *Q1 = Creator.makeNameWithTemplateArgs("Foo", {}); | |||||
Node const *Q2 = Creator.makeNameWithTemplateArgs("Foo", {}); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Equal | |||||
Node const *Q1 = Creator.makeNameWithTemplateArgs( | |||||
"Foo", {Creator.make<NameType>("foo")}); | |||||
Node const *Q2 = Creator.makeNameWithTemplateArgs( | |||||
"Foo", {Creator.make<NameType>("foo")}); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *Q1 = Creator.makeNameWithTemplateArgs( | |||||
"Foo", {Creator.make<NameType>("foo")}); | |||||
Node const *Q2 = Creator.makeNameWithTemplateArgs( | |||||
"Bar", {Creator.make<NameType>("foo")}); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
{ | |||||
// Different args | |||||
Node const *Q1 = Creator.makeNameWithTemplateArgs( | |||||
"Foo", {Creator.make<NameType>("foo"), Creator.make<NameType>("bar")}); | |||||
Node const *Q2 = Creator.makeNameWithTemplateArgs( | |||||
"Foo", {Creator.make<NameType>("bar"), Creator.make<NameType>("foo")}); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_NodeArrayNode) { | |||||
ManglingNodeCreator Creator; | |||||
std::vector<Node *> LHS; | |||||
std::vector<Node *> RHS; | |||||
{ | |||||
Node const *Q1 = Creator.make<NodeArrayNode>( | |||||
Creator.makeNodeArray(LHS.cbegin(), LHS.cend())); | |||||
Node const *Q2 = Creator.make<NodeArrayNode>( | |||||
Creator.makeNodeArray(RHS.cbegin(), RHS.cend())); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
LHS.push_back(Creator.make<NameType>("Foo")); | |||||
RHS.push_back(Creator.make<NameType>("Foo")); | |||||
{ | |||||
// Equal | |||||
Node const *Q1 = Creator.make<NodeArrayNode>( | |||||
Creator.makeNodeArray(LHS.cbegin(), LHS.cend())); | |||||
Node const *Q2 = Creator.make<NodeArrayNode>( | |||||
Creator.makeNodeArray(RHS.cbegin(), RHS.cend())); | |||||
ASSERT_TRUE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
LHS.push_back(Creator.make<NameType>("Bar")); | |||||
RHS.push_back(Creator.make<NameType>("Qux")); | |||||
{ | |||||
// Not equal | |||||
Node const *Q1 = Creator.make<NodeArrayNode>( | |||||
Creator.makeNodeArray(LHS.cbegin(), LHS.cend())); | |||||
Node const *Q2 = Creator.make<NodeArrayNode>( | |||||
Creator.makeNodeArray(RHS.cbegin(), RHS.cend())); | |||||
ASSERT_FALSE(test_utils::compareNodes(Q1, Q2)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_DotSuffix) { | |||||
ManglingNodeCreator Creator; | |||||
std::vector<Node *> ParamNodes{ | |||||
Creator.makeReferenceType(Qualifiers::QualVolatile, "Foo", | |||||
ReferenceKind::LValue), | |||||
Creator.makeReferenceType(Qualifiers::QualRestrict, "Bar", | |||||
ReferenceKind::RValue)}; | |||||
Node const *Func1 = Creator.makeFunctionEncoding("Baz", ParamNodes, {}, {}); | |||||
Node const *Func2 = Creator.makeFunctionEncoding("Qux", ParamNodes, {}, {}); | |||||
ASSERT_FALSE(test_utils::compareNodes(Func1, Func2)); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<DotSuffix>(Func1, "foo"); | |||||
Node const *RHS = Creator.make<DotSuffix>(Func1, "foo"); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different suffix | |||||
Node const *LHS = Creator.make<DotSuffix>(Func1, "foo"); | |||||
Node const *RHS = Creator.make<DotSuffix>(Func1, "bar"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different prefix | |||||
Node const *LHS = Creator.make<DotSuffix>(Func1, "foo"); | |||||
Node const *RHS = Creator.make<DotSuffix>(Func2, "foo"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_NestedName) { | |||||
ManglingNodeCreator Creator; | |||||
auto *Scope1 = Creator.make<NameType>("S1"); | |||||
auto *Scope2 = Creator.make<NameType>("S2"); | |||||
auto *Name1 = Creator.make<NameType>("Foo"); | |||||
auto *Name2 = Creator.make<NameType>("Bar"); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<NestedName>(Scope1, Name1); | |||||
Node const *RHS = Creator.make<NestedName>(Scope1, Name1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different scope | |||||
Node const *LHS = Creator.make<NestedName>(Scope1, Name1); | |||||
Node const *RHS = Creator.make<NestedName>(Scope2, Name1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<NestedName>(Scope1, Name1); | |||||
Node const *RHS = Creator.make<NestedName>(Scope1, Name2); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_ModuleName) { | |||||
ManglingNodeCreator Creator; | |||||
auto *Name1 = Creator.make<NameType>("Foo"); | |||||
auto *Name2 = Creator.make<NameType>("Bar"); | |||||
ModuleName *Parent1 = | |||||
static_cast<ModuleName *>(Creator.make<ModuleName>(nullptr, Name1, true)); | |||||
ModuleName *Parent2 = static_cast<ModuleName *>( | |||||
Creator.make<ModuleName>(Parent1, Name2, false)); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<ModuleName>(Parent1, Name1, true); | |||||
Node const *RHS = Creator.make<ModuleName>(Parent1, Name1, true); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different parents | |||||
Node const *LHS = Creator.make<ModuleName>(Parent1, Name1, true); | |||||
Node const *RHS = Creator.make<ModuleName>(Parent2, Name1, true); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<ModuleName>(Parent2, Name1, true); | |||||
Node const *RHS = Creator.make<ModuleName>(Parent2, Name2, true); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different partition type | |||||
Node const *LHS = Creator.make<ModuleName>(Parent2, Name1, true); | |||||
Node const *RHS = Creator.make<ModuleName>(Parent2, Name1, false); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_LocalName) { | |||||
ManglingNodeCreator Creator; | |||||
std::vector<Node *> ParamNodes{ | |||||
Creator.makeReferenceType(Qualifiers::QualVolatile, "Foo", | |||||
ReferenceKind::LValue), | |||||
Creator.makeReferenceType(Qualifiers::QualRestrict, "Bar", | |||||
ReferenceKind::RValue)}; | |||||
Node *Func1 = Creator.makeFunctionEncoding("Baz", ParamNodes, {}, {}); | |||||
Node *Func2 = Creator.makeFunctionEncoding("Qux", ParamNodes, {}, {}); | |||||
ASSERT_FALSE(test_utils::compareNodes(Func1, Func2)); | |||||
Node *Name1 = Creator.make<NestedName>(Creator.make<NameType>("Scope1"), | |||||
Creator.make<NameType>("Name1")); | |||||
Node *Name2 = Creator.make<NestedName>(Creator.make<NameType>("Scope2"), | |||||
Creator.make<NameType>("Name2")); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<LocalName>(Func1, Name1); | |||||
Node const *RHS = Creator.make<LocalName>(Func1, Name1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different encoding | |||||
Node const *LHS = Creator.make<LocalName>(Func1, Name1); | |||||
Node const *RHS = Creator.make<LocalName>(Func2, Name1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<LocalName>(Func1, Name2); | |||||
Node const *RHS = Creator.make<LocalName>(Func1, Name1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_QualifiedName) { | |||||
ManglingNodeCreator Creator; | |||||
auto *Scope1 = Creator.make<NameType>("Foo"); | |||||
auto *Scope2 = Creator.make<NameType>("Bar"); | |||||
auto *Name1 = Creator.make<NameType>("foo"); | |||||
auto *Name2 = Creator.make<NameType>("bar"); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<QualifiedName>(Scope1, Name1); | |||||
Node const *RHS = Creator.make<QualifiedName>(Scope1, Name1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different scope | |||||
Node const *LHS = Creator.make<QualifiedName>(Scope1, Name1); | |||||
Node const *RHS = Creator.make<QualifiedName>(Scope2, Name1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<QualifiedName>(Scope1, Name2); | |||||
Node const *RHS = Creator.make<QualifiedName>(Scope1, Name1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_CtorDtorName) { | |||||
ManglingNodeCreator Creator; | |||||
auto *Name1 = Creator.make<NameType>("Foo"); | |||||
auto *Name2 = Creator.make<NameType>("Bar"); | |||||
int Variant1 = '5' - '0'; | |||||
int Variant2 = '4' - '0'; | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<CtorDtorName>(Name1, true, Variant1); | |||||
Node const *RHS = Creator.make<CtorDtorName>(Name1, true, Variant1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<CtorDtorName>(Name1, true, Variant1); | |||||
Node const *RHS = Creator.make<CtorDtorName>(Name2, true, Variant1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Constructor vs. Destructor | |||||
Node const *LHS = Creator.make<CtorDtorName>(Name1, true, Variant1); | |||||
Node const *RHS = Creator.make<CtorDtorName>(Name1, false, Variant1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different variant | |||||
Node const *LHS = Creator.make<CtorDtorName>(Name1, false, Variant2); | |||||
Node const *RHS = Creator.make<CtorDtorName>(Name1, false, Variant1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_DtorName) { | |||||
ManglingNodeCreator Creator; | |||||
auto *Name1 = Creator.make<NameType>("Foo"); | |||||
auto *Name2 = Creator.make<NameType>("Bar"); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<DtorName>(Name1); | |||||
Node const *RHS = Creator.make<DtorName>(Name1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<DtorName>(Name1); | |||||
Node const *RHS = Creator.make<DtorName>(Name2); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_UnnamedTypename) { | |||||
ManglingNodeCreator Creator; | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<UnnamedTypeName>("Foo"); | |||||
Node const *RHS = Creator.make<UnnamedTypeName>("Foo"); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<UnnamedTypeName>("Foo"); | |||||
Node const *RHS = Creator.make<UnnamedTypeName>("Bar"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_ClosureTypeName) { | |||||
ManglingNodeCreator Creator; | |||||
std::vector<Node *> Params1{Creator.make<NameType>("double"), | |||||
Creator.make<NameType>("int")}; | |||||
std::vector<Node *> Params2{Creator.make<NameType>("double"), | |||||
Creator.make<NameType>("std::string")}; | |||||
std::vector<Node *> TemplateParams1{Creator.make<NameType>("Foo"), | |||||
Creator.make<NameType>("Bar")}; | |||||
std::vector<Node *> TemplateParams2{Creator.make<NameType>("Bar"), | |||||
Creator.make<NameType>("Foo")}; | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<ClosureTypeName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend()), | |||||
Creator.makeNodeArray(TemplateParams1.cbegin(), TemplateParams1.cend()), | |||||
"Foo"); | |||||
Node const *RHS = Creator.make<ClosureTypeName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend()), | |||||
Creator.makeNodeArray(TemplateParams1.cbegin(), TemplateParams1.cend()), | |||||
"Foo"); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<ClosureTypeName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend()), | |||||
Creator.makeNodeArray(TemplateParams1.cbegin(), TemplateParams1.cend()), | |||||
"Foo"); | |||||
Node const *RHS = Creator.make<ClosureTypeName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend()), | |||||
Creator.makeNodeArray(TemplateParams1.cbegin(), TemplateParams1.cend()), | |||||
"Bar"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different params | |||||
Node const *LHS = Creator.make<ClosureTypeName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend()), | |||||
Creator.makeNodeArray(TemplateParams1.cbegin(), TemplateParams1.cend()), | |||||
"Foo"); | |||||
Node const *RHS = Creator.make<ClosureTypeName>( | |||||
Creator.makeNodeArray(Params2.cbegin(), Params2.cend()), | |||||
Creator.makeNodeArray(TemplateParams1.cbegin(), TemplateParams1.cend()), | |||||
"Foo"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different template params | |||||
Node const *LHS = Creator.make<ClosureTypeName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend()), | |||||
Creator.makeNodeArray(TemplateParams1.cbegin(), TemplateParams1.cend()), | |||||
"Foo"); | |||||
Node const *RHS = Creator.make<ClosureTypeName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend()), | |||||
Creator.makeNodeArray(TemplateParams2.cbegin(), TemplateParams2.cend()), | |||||
"Foo"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_StructuredBindingName) { | |||||
ManglingNodeCreator Creator; | |||||
std::vector<Node *> Params1{Creator.make<NameType>("Foo"), | |||||
Creator.make<NameType>("Bar")}; | |||||
std::vector<Node *> Params2{Creator.make<NameType>("Bar"), | |||||
Creator.make<NameType>("Foo")}; | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<StructuredBindingName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend())); | |||||
Node const *RHS = Creator.make<StructuredBindingName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend())); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different bindings | |||||
Node const *LHS = Creator.make<StructuredBindingName>( | |||||
Creator.makeNodeArray(Params1.cbegin(), Params1.cend())); | |||||
Node const *RHS = Creator.make<StructuredBindingName>( | |||||
Creator.makeNodeArray(Params2.cbegin(), Params2.cend())); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_LiteralOperator) { | |||||
ManglingNodeCreator Creator; | |||||
auto *Name1 = Creator.make<NameType>("=="); | |||||
auto *Name2 = Creator.make<NameType>("+"); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<LiteralOperator>(Name1); | |||||
Node const *RHS = Creator.make<LiteralOperator>(Name1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different name | |||||
Node const *LHS = Creator.make<LiteralOperator>(Name1); | |||||
Node const *RHS = Creator.make<LiteralOperator>(Name2); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_SpecialName) { | |||||
ManglingNodeCreator Creator; | |||||
auto *Name1 = Creator.make<NameType>("Foo"); | |||||
auto *Name2 = Creator.make<NameType>("Bar"); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<SpecialName>("vtable for ", Name1); | |||||
Node const *RHS = Creator.make<SpecialName>("vtable for ", Name1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different prefix | |||||
Node const *LHS = Creator.make<SpecialName>("VTT for ", Name1); | |||||
Node const *RHS = Creator.make<SpecialName>("vtable for ", Name1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different child | |||||
Node const *LHS = Creator.make<SpecialName>("vtable for ", Name1); | |||||
Node const *RHS = Creator.make<SpecialName>("vtable for ", Name2); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_CtorVtableSpecialName) { | |||||
ManglingNodeCreator Creator; | |||||
auto *FstType1 = Creator.make<NameType>("Foo"); | |||||
auto *FstType2 = Creator.make<NameType>("Bar"); | |||||
auto *SndType1 = Creator.make<NameType>("Baz"); | |||||
auto *SndType2 = Creator.make<NameType>("Quz"); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<CtorVtableSpecialName>(FstType1, SndType1); | |||||
Node const *RHS = Creator.make<CtorVtableSpecialName>(FstType1, SndType1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different first type | |||||
Node const *LHS = Creator.make<CtorVtableSpecialName>(FstType1, SndType1); | |||||
Node const *RHS = Creator.make<CtorVtableSpecialName>(FstType2, SndType1); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different second type | |||||
Node const *LHS = Creator.make<CtorVtableSpecialName>(FstType1, SndType1); | |||||
Node const *RHS = Creator.make<CtorVtableSpecialName>(FstType1, SndType2); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_StringLiteral) { | |||||
ManglingNodeCreator Creator; | |||||
auto *Type1 = Creator.make<NameType>("std::string"); | |||||
auto *Type2 = Creator.make<NameType>("char const*"); | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<itanium_demangle::StringLiteral>(Type1); | |||||
Node const *RHS = Creator.make<itanium_demangle::StringLiteral>(Type1); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different type | |||||
Node const *LHS = Creator.make<itanium_demangle::StringLiteral>(Type1); | |||||
Node const *RHS = Creator.make<itanium_demangle::StringLiteral>(Type2); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_EnumLiteral) { | |||||
ManglingNodeCreator Creator; | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<IntegerLiteral>("Enum1", "100"); | |||||
Node const *RHS = Creator.make<IntegerLiteral>("Enum1", "100"); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different type | |||||
Node const *LHS = Creator.make<IntegerLiteral>("Enum1", "100"); | |||||
Node const *RHS = Creator.make<IntegerLiteral>("Enum2", "100"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different value | |||||
Node const *LHS = Creator.make<IntegerLiteral>("Enum1", "100"); | |||||
Node const *RHS = Creator.make<IntegerLiteral>("Enum1", "50"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} | |||||
TEST(ItaniumDemangle, Equality_FloatLiteral) { | |||||
ManglingNodeCreator Creator; | |||||
{ | |||||
// Equal | |||||
Node const *LHS = Creator.make<FloatLiteral>("1.0"); | |||||
Node const *RHS = Creator.make<FloatLiteral>("1.0"); | |||||
ASSERT_TRUE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
{ | |||||
// Different value | |||||
Node const *LHS = Creator.make<FloatLiteral>("1.0"); | |||||
Node const *RHS = Creator.make<FloatLiteral>("2.0"); | |||||
ASSERT_FALSE(test_utils::compareNodes(LHS, RHS)); | |||||
} | |||||
} |