1 //===-- TestType.cpp --------------------------------------------*- C++ -*-===//
2 //
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 #include "gtest/gtest.h"
12 
13 #include "lldb/Symbol/Type.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 namespace {
19 void TestGetTypeScopeAndBasenameHelper(const char *full_type,
20                                        bool expected_is_scoped,
21                                        const char *expected_scope,
22                                        const char *expected_name) {
23   llvm::StringRef scope, name;
24   lldb::TypeClass type_class;
25   bool is_scoped =
26       Type::GetTypeScopeAndBasename(full_type, scope, name, type_class);
27   EXPECT_EQ(is_scoped, expected_is_scoped);
28   if (expected_is_scoped) {
29     EXPECT_EQ(scope, expected_scope);
30     EXPECT_EQ(name, expected_name);
31   }
32 }
33 }
34 
35 TEST(Type, GetTypeScopeAndBasename) {
36   TestGetTypeScopeAndBasenameHelper("int", false, "", "");
37   TestGetTypeScopeAndBasenameHelper("std::string", true, "std::", "string");
38   TestGetTypeScopeAndBasenameHelper("std::set<int>", true, "std::", "set<int>");
39   TestGetTypeScopeAndBasenameHelper("std::set<int, std::less<int>>", true,
40                                     "std::", "set<int, std::less<int>>");
41   TestGetTypeScopeAndBasenameHelper("std::string::iterator", true,
42                                     "std::string::", "iterator");
43   TestGetTypeScopeAndBasenameHelper("std::set<int>::iterator", true,
44                                     "std::set<int>::", "iterator");
45   TestGetTypeScopeAndBasenameHelper(
46       "std::set<int, std::less<int>>::iterator", true,
47       "std::set<int, std::less<int>>::", "iterator");
48   TestGetTypeScopeAndBasenameHelper(
49       "std::set<int, std::less<int>>::iterator<bool>", true,
50       "std::set<int, std::less<int>>::", "iterator<bool>");
51 }
52