1 | //===- TypeNameTest.cpp ---------------------------------------------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "llvm/Support/TypeName.h" |
10 | #include "llvm/Support/raw_ostream.h" |
11 | #include "gtest/gtest.h" |
12 | |
13 | using namespace llvm; |
14 | |
15 | namespace { |
16 | namespace N1 { |
17 | struct S1 {}; |
18 | class C1 {}; |
19 | union U1 {}; |
20 | } |
21 | |
22 | TEST(TypeNameTest, Names) { |
23 | struct S2 {}; |
24 | |
25 | StringRef S1Name = getTypeName<N1::S1>(); |
26 | StringRef C1Name = getTypeName<N1::C1>(); |
27 | StringRef U1Name = getTypeName<N1::U1>(); |
28 | StringRef S2Name = getTypeName<S2>(); |
29 | |
30 | #if defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER) || \ |
31 | defined(_MSC_VER) |
32 | EXPECT_TRUE(S1Name.ends_with("::N1::S1")) << S1Name.str(); |
33 | EXPECT_TRUE(C1Name.ends_with("::N1::C1")) << C1Name.str(); |
34 | EXPECT_TRUE(U1Name.ends_with("::N1::U1")) << U1Name.str(); |
35 | #ifdef __clang__ |
36 | EXPECT_TRUE(S2Name.ends_with("S2")) << S2Name.str(); |
37 | #else |
38 | EXPECT_TRUE(S2Name.ends_with("::S2")) << S2Name.str(); |
39 | #endif |
40 | #else |
41 | EXPECT_EQ("UNKNOWN_TYPE", S1Name); |
42 | EXPECT_EQ("UNKNOWN_TYPE", C1Name); |
43 | EXPECT_EQ("UNKNOWN_TYPE", U1Name); |
44 | EXPECT_EQ("UNKNOWN_TYPE", S2Name); |
45 | #endif |
46 | } |
47 | |
48 | } // end anonymous namespace |
49 |