From 2de92d950404171383cd7a14ba6ea9b1ac9ea260 Mon Sep 17 00:00:00 2001 From: Neargye Date: Mon, 27 Aug 2018 01:31:32 +0500 Subject: [PATCH] add more test --- test/test.cpp | 392 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 281 insertions(+), 111 deletions(-) diff --git a/test/test.cpp b/test/test.cpp index 750c244..3196de4 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -50,7 +50,7 @@ template class SomeClass { public: void SomeMethod5() const { - std::cout << nameof::NameofType() << std::endl; + std::cout << NAMEOF_TYPE_T(T) << std::endl; } template @@ -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 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::SomeMethod6); + 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::SomeMethod6); + static_assert(cx3 == "SomeMethod6", ""); + // 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 a; - - constexpr auto cx1 = NAMEOF_TYPE(a); - constexpr auto cx2 = nameof::NameofType>(); - constexpr auto cx3 = nameof::NameofType(); - - - 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 volatile *); + static_assert(cx == "SomeClass", ""); + } + + SECTION("NAMEOF_TYPE_FULL") { + constexpr auto cx = NAMEOF_TYPE_FULL(classvar); + static_assert(cx == "SomeClass", ""); + } + + SECTION("NAMEOF_TYPE_FULL") { + constexpr auto cx = NAMEOF_TYPE_FULL_T(const SomeClass volatile *); + static_assert(cx == "SomeClass", ""); } -# endif SECTION("NAMEOF_TYPE_RAW") { - SomeClass a; - - constexpr auto cx1 = NAMEOF_TYPE_RAW(a); - constexpr auto cx2 = nameof::NameofTypeRaw>(); - constexpr auto cx3 = nameof::NameofTypeRaw(); - -# if defined(_MSC_VER) - static_assert(cx1 == "class SomeClass", ""); - static_assert(cx2 == "class SomeClass", ""); - static_assert(cx3 == "class SomeClass", ""); -# elif defined(__clang__) - static_assert(cx1 == "SomeClass", ""); - static_assert(cx2 == "SomeClass", ""); - static_assert(cx3 == "SomeClass", ""); -# endif - } -} + constexpr auto cx = NAMEOF_TYPE_RAW(classvar); +#if defined(__clang__) + static_assert(cx == "const volatile SomeClass *", ""); +#elif defined(_MSC_VER) + static_assert(cx == "SomeClass const volatile *", ""); #endif + } + SECTION("NAMEOF_TYPE_RAW") { + constexpr auto cx = NAMEOF_TYPE_RAW_T(const SomeClass volatile *); +#if defined(__clang__) + static_assert(cx == "const volatile SomeClass *", ""); +#elif defined(_MSC_VER) + static_assert(cx == "SomeClass 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) == "SomeMethod4"); + REQUIRE(NAMEOF_FULL(&SomeClass::SomeMethod5) == "SomeMethod5"); + REQUIRE(NAMEOF_FULL(&SomeClass::SomeMethod6) == "SomeMethod6"); + } + + 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 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>()) == "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) == "SomeClass"); + REQUIRE(NAMEOF_TYPE_T(const SomeClass 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 classSomeClass&&"); -#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"); + REQUIRE(NAMEOF_TYPE_FULL(std::declval volatile *>()) == "SomeClass"); + + 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) == "SomeClass"); + REQUIRE(NAMEOF_TYPE_FULL_T(const SomeClass volatile *) == "SomeClass"); + + 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 *"); + 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 &&"); +#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 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>()) == "SomeClass 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*"); + 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) == "SomeClass"); + REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass volatile *) == "const volatile SomeClass *"); + + 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) == "SomeClass"); + REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass volatile *) == "SomeClass 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) == "SomeClass"); + REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass volatile *) == "const volatile SomeClass*"); + + 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"); } }