| 1 |
//===-- TestType.cpp ------------------------------------------------------===// |
| 2 |
// |
| 3 |
// |
| 4 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 |
// See https://llvm.org/LICENSE.txt for license information. |
| 6 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 |
// |
| 8 |
//===----------------------------------------------------------------------===// |
| 9 |
|
| 10 |
#include "gtest/gtest.h" |
| 11 |
|
| 12 |
#include "lldb/Symbol/Type.h" |
| 13 |
|
| 14 |
using namespace lldb; |
| 15 |
using namespace lldb_private; |
| 16 |
|
| 17 |
namespace { |
| 18 |
void TestGetTypeScopeAndBasenameHelper(const char *full_type, |
| 19 |
bool expected_is_scoped, |
| 20 |
const char *expected_scope, |
| 21 |
const char *expected_name) { |
| 22 |
llvm::StringRef scope, name; |
| 23 |
lldb::TypeClass type_class; |
| 24 |
bool is_scoped = |
| 25 |
Type::GetTypeScopeAndBasename(full_type, scope, name, type_class); |
| 26 |
EXPECT_EQ(is_scoped, expected_is_scoped); |
| 27 |
if (expected_is_scoped) { |
| 28 |
EXPECT_EQ(scope, expected_scope); |
| 29 |
EXPECT_EQ(name, expected_name); |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
TEST(Type, GetTypeScopeAndBasename) { |
| 35 |
TestGetTypeScopeAndBasenameHelper("int", false, "", ""); |
| 36 |
TestGetTypeScopeAndBasenameHelper("std::string", true, "std::", "string"); |
| 37 |
TestGetTypeScopeAndBasenameHelper("std::set<int>", true, "std::", "set<int>"); |
| 38 |
TestGetTypeScopeAndBasenameHelper("std::set<int, std::less<int>>", true, |
| 39 |
"std::", "set<int, std::less<int>>"); |
| 40 |
TestGetTypeScopeAndBasenameHelper("std::string::iterator", true, |
| 41 |
"std::string::", "iterator"); |
| 42 |
TestGetTypeScopeAndBasenameHelper("std::set<int>::iterator", true, |
| 43 |
"std::set<int>::", "iterator"); |
| 44 |
TestGetTypeScopeAndBasenameHelper( |
| 45 |
"std::set<int, std::less<int>>::iterator", true, |
| 46 |
"std::set<int, std::less<int>>::", "iterator"); |
| 47 |
TestGetTypeScopeAndBasenameHelper( |
| 48 |
"std::set<int, std::less<int>>::iterator<bool>", true, |
| 49 |
"std::set<int, std::less<int>>::", "iterator<bool>"); |
| 50 |
} |
| 51 |
|
| 52 |
TEST(Type, CompilerContextPattern) { |
| 53 |
std::vector<CompilerContext> mms = { |
| 54 |
{CompilerContextKind::Module, ConstString("A")}, |
| 55 |
{CompilerContextKind::Module, ConstString("B")}, |
| 56 |
{CompilerContextKind::Struct, ConstString("S")}}; |
| 57 |
EXPECT_TRUE(contextMatches(mms, mms)); |
| 58 |
std::vector<CompilerContext> mmc = { |
| 59 |
{CompilerContextKind::Module, ConstString("A")}, |
| 60 |
{CompilerContextKind::Module, ConstString("B")}, |
| 61 |
{CompilerContextKind::Class, ConstString("S")}}; |
| 62 |
EXPECT_FALSE(contextMatches(mms, mmc)); |
| 63 |
std::vector<CompilerContext> ms = { |
| 64 |
{CompilerContextKind::Module, ConstString("A")}, |
| 65 |
{CompilerContextKind::Struct, ConstString("S")}}; |
| 66 |
std::vector<CompilerContext> mas = { |
| 67 |
{CompilerContextKind::Module, ConstString("A")}, |
| 68 |
{CompilerContextKind::AnyModule, ConstString("*")}, |
| 69 |
{CompilerContextKind::Struct, ConstString("S")}}; |
| 70 |
EXPECT_TRUE(contextMatches(mms, mas)); |
| 71 |
EXPECT_TRUE(contextMatches(ms, mas)); |
| 72 |
EXPECT_FALSE(contextMatches(mas, ms)); |
| 73 |
std::vector<CompilerContext> mmms = { |
| 74 |
{CompilerContextKind::Module, ConstString("A")}, |
| 75 |
{CompilerContextKind::Module, ConstString("B")}, |
| 76 |
{CompilerContextKind::Module, ConstString("C")}, |
| 77 |
{CompilerContextKind::Struct, ConstString("S")}}; |
| 78 |
EXPECT_TRUE(contextMatches(mmms, mas)); |
| 79 |
std::vector<CompilerContext> mme = { |
| 80 |
{CompilerContextKind::Module, ConstString("A")}, |
| 81 |
{CompilerContextKind::Module, ConstString("B")}, |
| 82 |
{CompilerContextKind::Enum, ConstString("S")}}; |
| 83 |
std::vector<CompilerContext> mma = { |
| 84 |
{CompilerContextKind::Module, ConstString("A")}, |
| 85 |
{CompilerContextKind::Module, ConstString("B")}, |
| 86 |
{CompilerContextKind::AnyType, ConstString("S")}}; |
| 87 |
EXPECT_TRUE(contextMatches(mme, mma)); |
| 88 |
EXPECT_TRUE(contextMatches(mms, mma)); |
| 89 |
std::vector<CompilerContext> mme2 = { |
| 90 |
{CompilerContextKind::Module, ConstString("A")}, |
| 91 |
{CompilerContextKind::Module, ConstString("B")}, |
| 92 |
{CompilerContextKind::Enum, ConstString("S2")}}; |
| 93 |
EXPECT_FALSE(contextMatches(mme2, mma)); |
| 94 |
} |