TypeNameTest.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "llvm/Support/TypeName.h"
  9. #include "llvm/Support/raw_ostream.h"
  10. #include "gtest/gtest.h"
  11. using namespace llvm;
  12. namespace {
  13. namespace N1 {
  14. struct S1 {};
  15. class C1 {};
  16. union U1 {};
  17. }
  18. TEST(TypeNameTest, Names) {
  19. struct S2 {};
  20. StringRef S1Name = getTypeName<N1::S1>();
  21. StringRef C1Name = getTypeName<N1::C1>();
  22. StringRef U1Name = getTypeName<N1::U1>();
  23. StringRef S2Name = getTypeName<S2>();
  24. #if defined(__clang__) || defined(__GNUC__) || defined(__INTEL_COMPILER) || \
  25. defined(_MSC_VER)
  26. EXPECT_TRUE(S1Name.endswith("::N1::S1")) << S1Name.str();
  27. EXPECT_TRUE(C1Name.endswith("::N1::C1")) << C1Name.str();
  28. EXPECT_TRUE(U1Name.endswith("::N1::U1")) << U1Name.str();
  29. #ifdef __clang__
  30. EXPECT_TRUE(S2Name.endswith("S2")) << S2Name.str();
  31. #else
  32. EXPECT_TRUE(S2Name.endswith("::S2")) << S2Name.str();
  33. #endif
  34. #else
  35. EXPECT_EQ("UNKNOWN_TYPE", S1Name);
  36. EXPECT_EQ("UNKNOWN_TYPE", C1Name);
  37. EXPECT_EQ("UNKNOWN_TYPE", U1Name);
  38. EXPECT_EQ("UNKNOWN_TYPE", S2Name);
  39. #endif
  40. }
  41. } // end anonymous namespace