add more test
This commit is contained in:
parent
89cafe2797
commit
2de92d9504
1 changed files with 281 additions and 111 deletions
392
test/test.cpp
392
test/test.cpp
|
@ -50,7 +50,7 @@ template <typename T>
|
|||
class SomeClass {
|
||||
public:
|
||||
void SomeMethod5() const {
|
||||
std::cout << nameof::NameofType<T>() << std::endl;
|
||||
std::cout << NAMEOF_TYPE_T(T) << std::endl;
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
|
@ -70,36 +70,50 @@ struct Long {
|
|||
|
||||
enum class Color { RED, GREEN, BLUE };
|
||||
|
||||
SomeStruct somevar;
|
||||
SomeStruct structvar;
|
||||
Long othervar;
|
||||
SomeStruct& refvar = somevar;
|
||||
SomeStruct* ptrvar = &somevar;
|
||||
SomeStruct * ptrvar = &structvar;
|
||||
SomeStruct & refvar = structvar;
|
||||
const SomeClass<int> volatile * classvar;
|
||||
|
||||
#if NAMEOF_HAS_CONSTEXPR
|
||||
// Compile-time nameof supported by C++14.
|
||||
TEST_CASE("constexpr") {
|
||||
SECTION("NAMEOF") {
|
||||
// variable
|
||||
constexpr auto cx1 = NAMEOF(somevar);
|
||||
static_assert(cx1 == "somevar", "");
|
||||
constexpr auto cx1 = NAMEOF(structvar);
|
||||
static_assert(cx1 == "structvar", "");
|
||||
// member
|
||||
constexpr auto cx2 = NAMEOF((&somevar)->somefield);
|
||||
constexpr auto cx2 = NAMEOF((&structvar)->somefield);
|
||||
static_assert(cx2 == "somefield", "");
|
||||
// function
|
||||
constexpr auto cx3 = NAMEOF(&SomeStruct::SomeMethod2);
|
||||
static_assert(cx3 == "SomeMethod2", "");
|
||||
constexpr auto cx3 = NAMEOF(&SomeClass<int>::SomeMethod6<long int>);
|
||||
static_assert(cx3 == "SomeMethod6", "");
|
||||
// enum
|
||||
constexpr auto cx4 = NAMEOF(Color::RED);
|
||||
static_assert(cx4 == "RED", "");
|
||||
static_assert(cx4 == "RED", "");
|
||||
}
|
||||
|
||||
SECTION("NAMEOF_FULL") {
|
||||
// variable
|
||||
constexpr auto cx1 = NAMEOF_FULL(structvar);
|
||||
static_assert(cx1 == "structvar", "");
|
||||
// member
|
||||
constexpr auto cx2 = NAMEOF_FULL((&structvar)->somefield);
|
||||
static_assert(cx2 == "somefield", "");
|
||||
// function
|
||||
constexpr auto cx3 = NAMEOF_FULL(&SomeClass<int>::SomeMethod6<long int>);
|
||||
static_assert(cx3 == "SomeMethod6<long int>", "");
|
||||
// enum
|
||||
constexpr auto cx4 = NAMEOF_FULL(Color::RED);
|
||||
static_assert(cx4 == "RED", "");
|
||||
}
|
||||
|
||||
SECTION("NAMEOF_RAW") {
|
||||
// variable
|
||||
constexpr auto cx1 = NAMEOF_RAW(somevar);
|
||||
static_assert(cx1 == "somevar", "");
|
||||
constexpr auto cx1 = NAMEOF_RAW(structvar);
|
||||
static_assert(cx1 == "structvar", "");
|
||||
// member
|
||||
constexpr auto cx2 = NAMEOF_RAW((&somevar)->somefield);
|
||||
static_assert(cx2 == "(&somevar)->somefield", "");
|
||||
constexpr auto cx2 = NAMEOF_RAW((&structvar)->somefield);
|
||||
static_assert(cx2 == "(&structvar)->somefield", "");
|
||||
// type
|
||||
constexpr auto cx3 = NAMEOF_RAW(std::string);
|
||||
static_assert(cx3 == "std::string", "");
|
||||
|
@ -114,51 +128,57 @@ TEST_CASE("constexpr") {
|
|||
static_assert(cx6 == "__cplusplus", "");
|
||||
}
|
||||
|
||||
# if defined(_MSC_VER) || defined(__clang__)
|
||||
// constexpr in NAMEOF_TYPE not supported if GCC.
|
||||
#if defined(_MSC_VER) || defined(__clang__)
|
||||
SECTION("NAMEOF_TYPE") {
|
||||
SomeClass<int> a;
|
||||
|
||||
constexpr auto cx1 = NAMEOF_TYPE(a);
|
||||
constexpr auto cx2 = nameof::NameofType<SomeClass<int>>();
|
||||
constexpr auto cx3 = nameof::NameofType<decltype(a)>();
|
||||
|
||||
|
||||
static_assert(cx1 == "SomeClass", "");
|
||||
static_assert(cx2 == "SomeClass", "");
|
||||
static_assert(cx3 == "SomeClass", "");
|
||||
constexpr auto cx = NAMEOF_TYPE(classvar);
|
||||
static_assert(cx == "SomeClass", "");
|
||||
}
|
||||
|
||||
SECTION("NAMEOF_TYPE") {
|
||||
constexpr auto cx = NAMEOF_TYPE_T(const SomeClass<int> volatile *);
|
||||
static_assert(cx == "SomeClass", "");
|
||||
}
|
||||
|
||||
SECTION("NAMEOF_TYPE_FULL") {
|
||||
constexpr auto cx = NAMEOF_TYPE_FULL(classvar);
|
||||
static_assert(cx == "SomeClass<int>", "");
|
||||
}
|
||||
|
||||
SECTION("NAMEOF_TYPE_FULL") {
|
||||
constexpr auto cx = NAMEOF_TYPE_FULL_T(const SomeClass<int> volatile *);
|
||||
static_assert(cx == "SomeClass<int>", "");
|
||||
}
|
||||
# endif
|
||||
|
||||
SECTION("NAMEOF_TYPE_RAW") {
|
||||
SomeClass<int> a;
|
||||
|
||||
constexpr auto cx1 = NAMEOF_TYPE_RAW(a);
|
||||
constexpr auto cx2 = nameof::NameofTypeRaw<SomeClass<int>>();
|
||||
constexpr auto cx3 = nameof::NameofTypeRaw<decltype(a)>();
|
||||
|
||||
# if defined(_MSC_VER)
|
||||
static_assert(cx1 == "class SomeClass<int>", "");
|
||||
static_assert(cx2 == "class SomeClass<int>", "");
|
||||
static_assert(cx3 == "class SomeClass<int>", "");
|
||||
# elif defined(__clang__)
|
||||
static_assert(cx1 == "SomeClass<int>", "");
|
||||
static_assert(cx2 == "SomeClass<int>", "");
|
||||
static_assert(cx3 == "SomeClass<int>", "");
|
||||
# endif
|
||||
}
|
||||
}
|
||||
constexpr auto cx = NAMEOF_TYPE_RAW(classvar);
|
||||
#if defined(__clang__)
|
||||
static_assert(cx == "const volatile SomeClass<int> *", "");
|
||||
#elif defined(_MSC_VER)
|
||||
static_assert(cx == "SomeClass<int> const volatile *", "");
|
||||
#endif
|
||||
}
|
||||
SECTION("NAMEOF_TYPE_RAW") {
|
||||
constexpr auto cx = NAMEOF_TYPE_RAW_T(const SomeClass<int> volatile *);
|
||||
#if defined(__clang__)
|
||||
static_assert(cx == "const volatile SomeClass<int> *", "");
|
||||
#elif defined(_MSC_VER)
|
||||
static_assert(cx == "SomeClass<int> const volatile *", "");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("simple name") {
|
||||
TEST_CASE("NAMEOF") {
|
||||
SECTION("variable") {
|
||||
REQUIRE(NAMEOF(somevar) == "somevar");
|
||||
REQUIRE(NAMEOF(::somevar) == "somevar");
|
||||
REQUIRE(NAMEOF(structvar) == "structvar");
|
||||
REQUIRE(NAMEOF(::structvar) == "structvar");
|
||||
REQUIRE(NAMEOF(ptrvar) == "ptrvar");
|
||||
}
|
||||
|
||||
SECTION("member") {
|
||||
REQUIRE(NAMEOF(somevar.somefield) == "somefield");
|
||||
REQUIRE(NAMEOF((&somevar)->somefield) == "somefield");
|
||||
REQUIRE(NAMEOF(structvar.somefield) == "somefield");
|
||||
REQUIRE(NAMEOF((&structvar)->somefield) == "somefield");
|
||||
REQUIRE(NAMEOF(othervar.ll.field) == "field");
|
||||
}
|
||||
|
||||
|
@ -177,87 +197,162 @@ TEST_CASE("simple name") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("raw name") {
|
||||
TEST_CASE("NAMEOF_FULL") {
|
||||
SECTION("variable") {
|
||||
REQUIRE(NAMEOF_RAW(somevar) == "somevar");
|
||||
REQUIRE(NAMEOF_RAW(&somevar) == "&somevar");
|
||||
REQUIRE(NAMEOF_RAW(::somevar) == "::somevar");
|
||||
REQUIRE(NAMEOF_RAW(ptrvar) == "ptrvar");
|
||||
REQUIRE(NAMEOF_RAW(*ptrvar) == "*ptrvar");
|
||||
REQUIRE(NAMEOF_RAW(+somevar.somefield) == "+somevar.somefield");
|
||||
REQUIRE(NAMEOF_RAW(-somevar.somefield) == "-somevar.somefield");
|
||||
REQUIRE(NAMEOF_RAW(~somevar.somefield) == "~somevar.somefield");
|
||||
REQUIRE(NAMEOF_RAW(!somevar.somefield) == "!somevar.somefield");
|
||||
REQUIRE(NAMEOF_FULL(structvar) == "structvar");
|
||||
REQUIRE(NAMEOF_FULL(::structvar) == "structvar");
|
||||
REQUIRE(NAMEOF_FULL(ptrvar) == "ptrvar");
|
||||
}
|
||||
|
||||
SECTION("member") {
|
||||
REQUIRE(NAMEOF_RAW(somevar.somefield) == "somevar.somefield");
|
||||
REQUIRE(NAMEOF_RAW((&somevar)->somefield) == "(&somevar)->somefield");
|
||||
REQUIRE(NAMEOF_RAW(othervar.ll.field) == "othervar.ll.field");
|
||||
REQUIRE(NAMEOF_FULL(structvar.somefield) == "somefield");
|
||||
REQUIRE(NAMEOF_FULL((&structvar)->somefield) == "somefield");
|
||||
REQUIRE(NAMEOF_FULL(othervar.ll.field) == "field");
|
||||
}
|
||||
|
||||
SECTION("function") {
|
||||
REQUIRE(NAMEOF_FULL(&SomeStruct::SomeMethod1) == "SomeMethod1");
|
||||
REQUIRE(NAMEOF_FULL(&SomeStruct::SomeMethod2) == "SomeMethod2");
|
||||
REQUIRE(NAMEOF_FULL(SomeMethod3) == "SomeMethod3");
|
||||
REQUIRE(NAMEOF_FULL(SomeMethod4<int>) == "SomeMethod4<int>");
|
||||
REQUIRE(NAMEOF_FULL(&SomeClass<int>::SomeMethod5) == "SomeMethod5");
|
||||
REQUIRE(NAMEOF_FULL(&SomeClass<int>::SomeMethod6<long int>) == "SomeMethod6<long int>");
|
||||
}
|
||||
|
||||
SECTION("enum") {
|
||||
REQUIRE(NAMEOF_FULL(Color::RED) == "RED");
|
||||
REQUIRE(NAMEOF_FULL(Color::BLUE) == "BLUE");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("NAMEOF_RAW") {
|
||||
SECTION("variable") {
|
||||
REQUIRE(NAMEOF_RAW(structvar) == "structvar");
|
||||
REQUIRE(NAMEOF_RAW(&structvar) == "&structvar");
|
||||
REQUIRE(NAMEOF_RAW(::structvar) == "::structvar");
|
||||
REQUIRE(NAMEOF_RAW(ptrvar) == "ptrvar");
|
||||
REQUIRE(NAMEOF_RAW(*ptrvar) == "*ptrvar");
|
||||
REQUIRE(NAMEOF_RAW(+structvar.somefield) == "+structvar.somefield");
|
||||
REQUIRE(NAMEOF_RAW(-structvar.somefield) == "-structvar.somefield");
|
||||
REQUIRE(NAMEOF_RAW(~structvar.somefield) == "~structvar.somefield");
|
||||
REQUIRE(NAMEOF_RAW(!structvar.somefield) == "!structvar.somefield");
|
||||
REQUIRE(NAMEOF_RAW(structvar.somefield + refvar.somefield) == "structvar.somefield + refvar.somefield");
|
||||
}
|
||||
|
||||
SECTION("member") {
|
||||
REQUIRE(NAMEOF_RAW(structvar.somefield) == "structvar.somefield");
|
||||
REQUIRE(NAMEOF_RAW((&structvar)->somefield) == "(&structvar)->somefield");
|
||||
REQUIRE(NAMEOF_RAW(othervar.ll.field) == "othervar.ll.field");
|
||||
}
|
||||
|
||||
SECTION("type") {
|
||||
REQUIRE(NAMEOF_RAW(int[]) == "int[]");
|
||||
REQUIRE(NAMEOF_RAW(int) == "int");
|
||||
REQUIRE(NAMEOF_RAW(const volatile int[]) == "const volatile int[]");
|
||||
REQUIRE(NAMEOF_RAW(std::string) == "std::string");
|
||||
REQUIRE(NAMEOF_RAW(SomeStruct) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_RAW(Long::LL) == "Long::LL");
|
||||
REQUIRE(NAMEOF_RAW(Color) == "Color");
|
||||
REQUIRE(NAMEOF_RAW(int) == "int");
|
||||
REQUIRE(NAMEOF_RAW(const volatile int[]) == "const volatile int[]");
|
||||
REQUIRE(NAMEOF_RAW(std::string) == "std::string");
|
||||
REQUIRE(NAMEOF_RAW(SomeStruct) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_RAW(Long::LL) == "Long::LL");
|
||||
REQUIRE(NAMEOF_RAW(Color) == "Color");
|
||||
}
|
||||
|
||||
SECTION("function") {
|
||||
REQUIRE(NAMEOF_RAW(&SomeStruct::SomeMethod1) == "&SomeStruct::SomeMethod1");
|
||||
REQUIRE(NAMEOF_RAW(&SomeStruct::SomeMethod2) == "&SomeStruct::SomeMethod2");
|
||||
REQUIRE(NAMEOF_RAW(SomeMethod3) == "SomeMethod3");
|
||||
REQUIRE(NAMEOF_RAW(&SomeStruct::SomeMethod1) == "&SomeStruct::SomeMethod1");
|
||||
REQUIRE(NAMEOF_RAW(&SomeStruct::SomeMethod2) == "&SomeStruct::SomeMethod2");
|
||||
REQUIRE(NAMEOF_RAW(SomeMethod3) == "SomeMethod3");
|
||||
}
|
||||
|
||||
SECTION("enum") {
|
||||
REQUIRE(NAMEOF_RAW(Color::RED) == "Color::RED");
|
||||
REQUIRE(NAMEOF_RAW(Color::BLUE) == "Color::BLUE");
|
||||
REQUIRE(NAMEOF_RAW(Color::RED) == "Color::RED");
|
||||
REQUIRE(NAMEOF_RAW(Color::BLUE) == "Color::BLUE");
|
||||
}
|
||||
|
||||
SECTION("macros") {
|
||||
REQUIRE(NAMEOF_RAW(__cplusplus) == "__cplusplus");
|
||||
REQUIRE(NAMEOF_RAW(__LINE__) == "__LINE__");
|
||||
REQUIRE(NAMEOF_RAW(__FILE__) == "__FILE__");
|
||||
REQUIRE(NAMEOF_RAW(__cplusplus) == "__cplusplus");
|
||||
REQUIRE(NAMEOF_RAW(__LINE__) == "__LINE__");
|
||||
REQUIRE(NAMEOF_RAW(__FILE__) == "__FILE__");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("type name") {
|
||||
REQUIRE(NAMEOF_TYPE(somevar) == "SomeStruct");
|
||||
TEST_CASE("NAMEOF_TYPE") {
|
||||
REQUIRE(NAMEOF_TYPE(structvar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE(ptrvar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE(refvar) == "SomeStruct");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE(classvar) == "SomeClass");
|
||||
REQUIRE(NAMEOF_TYPE(std::declval<const SomeClass<int> volatile *>()) == "SomeClass");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE(othervar) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE(othervar.ll) == "LL");
|
||||
REQUIRE(NAMEOF_TYPE(othervar.ll.field) == "int");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE(Color::RED) == "Color");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE(std::string{}) == "basic_string");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE(std::declval<const SomeClass<int>>()) == "SomeClass");
|
||||
REQUIRE(NAMEOF_TYPE(Color::RED) == "Color");
|
||||
}
|
||||
|
||||
TEST_CASE("type raw name") {
|
||||
#if defined(_MSC_VER)
|
||||
REQUIRE(NAMEOF_TYPE_RAW(somevar) == "struct SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(ptrvar) == "structSomeStruct*");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(refvar) == "structSomeStruct&");
|
||||
TEST_CASE("NAMEOF_TYPE_T") {
|
||||
REQUIRE(NAMEOF_TYPE_T(decltype(structvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T(decltype(ptrvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T(decltype(refvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T(SomeStruct) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T(SomeStruct *) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T(SomeStruct &) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T(const SomeStruct volatile *) == "SomeStruct");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar) == "struct Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar.ll) == "struct Long::LL");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar.ll.field) == "int");
|
||||
REQUIRE(NAMEOF_TYPE_T(SomeClass<int>) == "SomeClass");
|
||||
REQUIRE(NAMEOF_TYPE_T(const SomeClass<int> volatile *) == "SomeClass");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(Color::RED) == "enum Color");
|
||||
REQUIRE(NAMEOF_TYPE_T(decltype(othervar)) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_T(Long) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_T(Long::LL) == "LL");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(std::declval<const SomeClass<int>>()) == "const classSomeClass<int>&&");
|
||||
#elif defined(__clang__)
|
||||
REQUIRE(NAMEOF_TYPE_RAW(somevar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T(std::string) == "basic_string");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_T(Color) == "Color");
|
||||
}
|
||||
|
||||
TEST_CASE("NAMEOF_TYPE_FULL") {
|
||||
REQUIRE(NAMEOF_TYPE_FULL(structvar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL(ptrvar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL(refvar) == "SomeStruct");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_FULL(classvar) == "SomeClass<int>");
|
||||
REQUIRE(NAMEOF_TYPE_FULL(std::declval<const SomeClass<int> volatile *>()) == "SomeClass<int>");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_FULL(othervar) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_FULL(othervar.ll) == "LL");
|
||||
REQUIRE(NAMEOF_TYPE_FULL(othervar.ll.field) == "int");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_FULL(Color::RED) == "Color");
|
||||
}
|
||||
|
||||
TEST_CASE("NAMEOF_TYPE_FULL_T") {
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(decltype(structvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(decltype(ptrvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(decltype(refvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(SomeStruct) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(SomeStruct *) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(SomeStruct &) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(const SomeStruct volatile *) == "SomeStruct");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(SomeClass<int>) == "SomeClass<int>");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(const SomeClass<int> volatile *) == "SomeClass<int>");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(decltype(othervar)) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(Long) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(Long::LL) == "LL");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T(Color) == "Color");
|
||||
}
|
||||
|
||||
TEST_CASE("NAMEOF_TYPE_RAW") {
|
||||
#if defined(__clang__)
|
||||
REQUIRE(NAMEOF_TYPE_RAW(structvar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(ptrvar) == "SomeStruct *");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(refvar) == "SomeStruct &");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(classvar) == "const volatile SomeClass<int> *");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar.ll) == "Long::LL");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar.ll.field) == "int");
|
||||
|
@ -265,11 +360,27 @@ TEST_CASE("type raw name") {
|
|||
REQUIRE(NAMEOF_TYPE_RAW(Color::RED) == "Color");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(std::declval<const SomeClass<int>>()) == "const SomeClass<int> &&");
|
||||
#elif defined(_MSC_VER)
|
||||
REQUIRE(NAMEOF_TYPE_RAW(structvar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(ptrvar) == "SomeStruct *");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(refvar) == "SomeStruct &");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(classvar) == "SomeClass<int> const volatile *");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar.ll) == "Long::LL");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar.ll.field) == "int");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(Color::RED) == "Color");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(std::declval<const SomeClass<int>>()) == "SomeClass<int> const &&");
|
||||
#elif defined(__GNUC__)
|
||||
REQUIRE(NAMEOF_TYPE_RAW(somevar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(structvar) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(ptrvar) == "SomeStruct*");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(refvar) == "SomeStruct&");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(classvar) == "const volatile SomeClass<int>*");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar.ll) == "Long::LL");
|
||||
REQUIRE(NAMEOF_TYPE_RAW(othervar.ll.field) == "int");
|
||||
|
@ -280,26 +391,85 @@ TEST_CASE("type raw name") {
|
|||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("NAMEOF_TYPE_RAW_T") {
|
||||
#if defined(__clang__)
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(structvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(ptrvar)) == "SomeStruct *");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(refvar)) == "SomeStruct &");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct *) == "SomeStruct *");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct &) == "SomeStruct &");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(const SomeStruct volatile *) == "const volatile SomeStruct *");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeClass<int>) == "SomeClass<int>");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass<int> volatile *) == "const volatile SomeClass<int> *");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(othervar)) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Long) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Long::LL) == "Long::LL");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Color) == "Color");
|
||||
#elif defined(_MSC_VER)
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(structvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(ptrvar)) == "SomeStruct *");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(refvar)) == "SomeStruct &");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct *) == "SomeStruct *");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct &) == "SomeStruct &");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(const SomeStruct volatile *) == "SomeStruct const volatile *");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeClass<int>) == "SomeClass<int>");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass<int> volatile *) == "SomeClass<int> const volatile *");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(othervar)) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Long) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Long::LL) == "Long::LL");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Color) == "Color");
|
||||
#elif defined(__GNUC__)
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(structvar)) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(ptrvar)) == "SomeStruct*");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(refvar)) == "SomeStruct&");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct *) == "SomeStruct*");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct &) == "SomeStruct&");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(const SomeStruct volatile *) == "const volatile SomeStruct*");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(SomeClass<int>) == "SomeClass<int>");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass<int> volatile *) == "const volatile SomeClass<int>*");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(decltype(othervar)) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Long) == "Long");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Long::LL) == "Long::LL");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T(Color) == "Color");
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("Spaces and Tabs ignored") {
|
||||
SECTION("Spaces") {
|
||||
REQUIRE(NAMEOF( somevar ) == "somevar");
|
||||
REQUIRE(NAMEOF_RAW( somevar ) == "somevar");
|
||||
REQUIRE(NAMEOF_TYPE( somevar ) == "SomeStruct");
|
||||
#if defined(_MSC_VER)
|
||||
REQUIRE(NAMEOF_TYPE_RAW( somevar ) == "struct SomeStruct");
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
REQUIRE(NAMEOF_TYPE_RAW( somevar ) == "SomeStruct");
|
||||
#endif
|
||||
REQUIRE(NAMEOF( structvar ) == "structvar");
|
||||
REQUIRE(NAMEOF_FULL( structvar ) == "structvar");
|
||||
REQUIRE(NAMEOF_RAW( structvar ) == "structvar");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE( structvar ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T( decltype(structvar) ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL( structvar ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T( decltype(structvar) ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW( structvar ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T( decltype(structvar) ) == "SomeStruct");
|
||||
}
|
||||
|
||||
SECTION("Tabs") {
|
||||
REQUIRE(NAMEOF( somevar ) == "somevar");
|
||||
REQUIRE(NAMEOF_RAW( somevar ) == "somevar");
|
||||
REQUIRE(NAMEOF_TYPE( somevar ) == "SomeStruct");
|
||||
#if defined(_MSC_VER)
|
||||
REQUIRE(NAMEOF_TYPE_RAW( somevar ) == "struct SomeStruct");
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
REQUIRE(NAMEOF_TYPE_RAW( somevar ) == "SomeStruct");
|
||||
#endif
|
||||
REQUIRE(NAMEOF( structvar ) == "structvar");
|
||||
REQUIRE(NAMEOF_FULL( structvar ) == "structvar");
|
||||
REQUIRE(NAMEOF_RAW( structvar ) == "structvar");
|
||||
|
||||
REQUIRE(NAMEOF_TYPE( structvar ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_T( decltype(structvar) ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL( structvar ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_FULL_T( decltype(structvar) ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW( structvar ) == "SomeStruct");
|
||||
REQUIRE(NAMEOF_TYPE_RAW_T( decltype(structvar) ) == "SomeStruct");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue