diff --git a/test/test.cpp b/test/test.cpp index afb5d17..78fedbb 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -365,50 +365,209 @@ TEST_CASE("nameof_enum") { } #endif -TEST_CASE("NAMEOF_VAR_TYPE") { - constexpr auto type_name = NAMEOF_VAR_TYPE(struct_var); +TEST_CASE("NAMEOF_FULL_TYPE_EXPR") { + constexpr auto type_name = NAMEOF_FULL_TYPE_EXPR(struct_var); #if defined(__clang__) REQUIRE(type_name == "SomeStruct"); - REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "SomeStruct *"); - REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "SomeStruct &"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_s) == "SomeStruct *"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ref_s) == "SomeStruct &"); - REQUIRE(NAMEOF_VAR_TYPE(ptr_c) == "const volatile SomeClass *"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_c) == "const volatile SomeClass *"); - REQUIRE(NAMEOF_VAR_TYPE(othervar) == "Long"); - REQUIRE(NAMEOF_VAR_TYPE(othervar.ll) == "Long::LL"); - REQUIRE(NAMEOF_VAR_TYPE(othervar.ll.field) == "int"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar) == "Long"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar.ll) == "Long::LL"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar.ll.field) == "int"); - REQUIRE(NAMEOF_VAR_TYPE(Color::RED) == "Color"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(Color::RED) == "Color"); - REQUIRE(NAMEOF_VAR_TYPE(std::declval>()) == "const SomeClass &&"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(std::declval>()) == "const SomeClass &&"); #elif defined(_MSC_VER) REQUIRE(type_name == "struct SomeStruct"); - REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "struct SomeStruct *"); - REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "struct SomeStruct &"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_s) == "struct SomeStruct *"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ref_s) == "struct SomeStruct &"); - REQUIRE(NAMEOF_VAR_TYPE(ptr_c) == "class SomeClass const volatile *"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_c) == "class SomeClass const volatile *"); - REQUIRE(NAMEOF_VAR_TYPE(othervar) == "struct Long"); - REQUIRE(NAMEOF_VAR_TYPE(othervar.ll) == "struct Long::LL"); - REQUIRE(NAMEOF_VAR_TYPE(othervar.ll.field) == "int"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar) == "struct Long"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar.ll) == "struct Long::LL"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar.ll.field) == "int"); - REQUIRE(NAMEOF_VAR_TYPE(Color::RED) == "enum Color"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(Color::RED) == "enum Color"); - REQUIRE(NAMEOF_VAR_TYPE(std::declval>()) == "class SomeClass const &&"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(std::declval>()) == "class SomeClass const &&"); #elif defined(__GNUC__) REQUIRE(type_name == "SomeStruct"); - REQUIRE(NAMEOF_VAR_TYPE(ptr_s) == "SomeStruct*"); - REQUIRE(NAMEOF_VAR_TYPE(ref_s) == "SomeStruct&"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_s) == "SomeStruct*"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ref_s) == "SomeStruct&"); - REQUIRE(NAMEOF_VAR_TYPE(ptr_c) == "const volatile SomeClass*"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_c) == "const volatile SomeClass*"); - REQUIRE(NAMEOF_VAR_TYPE(othervar) == "Long"); - REQUIRE(NAMEOF_VAR_TYPE(othervar.ll) == "Long::LL"); - REQUIRE(NAMEOF_VAR_TYPE(othervar.ll.field) == "int"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar) == "Long"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar.ll) == "Long::LL"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(othervar.ll.field) == "int"); - REQUIRE(NAMEOF_VAR_TYPE(Color::RED) == "Color"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(Color::RED) == "Color"); - REQUIRE(NAMEOF_VAR_TYPE(std::declval>()) == "const SomeClass&&"); + REQUIRE(NAMEOF_FULL_TYPE_EXPR(std::declval>()) == "const SomeClass&&"); +#endif +} + +TEST_CASE("NAMEOF_FULL_TYPE") { + constexpr auto type_name = NAMEOF_FULL_TYPE(decltype(struct_var)); +#if defined(__clang__) + REQUIRE(type_name == "SomeStruct"); + REQUIRE(NAMEOF_FULL_TYPE(decltype(ptr_s)) == "SomeStruct *"); + REQUIRE(NAMEOF_FULL_TYPE(decltype(ref_s)) == "SomeStruct &"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct) == "SomeStruct"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct *) == "SomeStruct *"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct &) == "SomeStruct &"); + REQUIRE(NAMEOF_FULL_TYPE(const SomeStruct volatile *) == "const volatile SomeStruct *"); + + REQUIRE(NAMEOF_FULL_TYPE(SomeClass) == "SomeClass"); + REQUIRE(NAMEOF_FULL_TYPE(const SomeClass volatile *) == "const volatile SomeClass *"); + + REQUIRE(NAMEOF_FULL_TYPE(decltype(othervar)) == "Long"); + REQUIRE(NAMEOF_FULL_TYPE(Long) == "Long"); + REQUIRE(NAMEOF_FULL_TYPE(Long::LL) == "Long::LL"); + + REQUIRE(NAMEOF_FULL_TYPE(Color) == "Color"); +#elif defined(_MSC_VER) + REQUIRE(type_name == "struct SomeStruct"); + REQUIRE(NAMEOF_FULL_TYPE(decltype(ptr_s)) == "struct SomeStruct *"); + REQUIRE(NAMEOF_FULL_TYPE(decltype(ref_s)) == "struct SomeStruct &"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct) == "struct SomeStruct"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct *) == "struct SomeStruct *"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct &) == "struct SomeStruct &"); + REQUIRE(NAMEOF_FULL_TYPE(const SomeStruct volatile *) == "struct SomeStruct const volatile *"); + + REQUIRE(NAMEOF_FULL_TYPE(SomeClass) == "class SomeClass"); + REQUIRE(NAMEOF_FULL_TYPE(const SomeClass volatile *) == "class SomeClass const volatile *"); + + REQUIRE(NAMEOF_FULL_TYPE(decltype(othervar)) == "struct Long"); + REQUIRE(NAMEOF_FULL_TYPE(Long) == "struct Long"); + REQUIRE(NAMEOF_FULL_TYPE(Long::LL) == "struct Long::LL"); + + REQUIRE(NAMEOF_FULL_TYPE(Color) == "enum Color"); +#elif defined(__GNUC__) + REQUIRE(type_name == "SomeStruct"); + REQUIRE(NAMEOF_FULL_TYPE(decltype(ptr_s)) == "SomeStruct*"); + REQUIRE(NAMEOF_FULL_TYPE(decltype(ref_s)) == "SomeStruct&"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct) == "SomeStruct"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct *) == "SomeStruct*"); + REQUIRE(NAMEOF_FULL_TYPE(SomeStruct &) == "SomeStruct&"); + REQUIRE(NAMEOF_FULL_TYPE(const SomeStruct volatile *) == "const volatile SomeStruct*"); + + REQUIRE(NAMEOF_FULL_TYPE(SomeClass) == "SomeClass"); + REQUIRE(NAMEOF_FULL_TYPE(const SomeClass volatile *) == "const volatile SomeClass*"); + + REQUIRE(NAMEOF_FULL_TYPE(decltype(othervar)) == "Long"); + REQUIRE(NAMEOF_FULL_TYPE(Long) == "Long"); + REQUIRE(NAMEOF_FULL_TYPE(Long::LL) == "Long::LL"); + + REQUIRE(NAMEOF_FULL_TYPE(Color) == "Color"); +#endif +} + +TEST_CASE("nameof::nameof_full_type") { + constexpr auto type_name = nameof::nameof_full_type(); +#if defined(__clang__) + REQUIRE(type_name == "SomeStruct"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct *"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct &"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct *"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct &"); + REQUIRE(nameof::nameof_full_type() == "const volatile SomeStruct *"); + + REQUIRE(nameof::nameof_full_type>() == "SomeClass"); + REQUIRE(nameof::nameof_full_type volatile *>() == "const volatile SomeClass *"); + + REQUIRE(nameof::nameof_full_type() == "Long"); + REQUIRE(nameof::nameof_full_type() == "Long"); + REQUIRE(nameof::nameof_full_type() == "Long::LL"); + + REQUIRE(nameof::nameof_full_type() == "Color"); +#elif defined(_MSC_VER) + REQUIRE(type_name == "struct SomeStruct"); + REQUIRE(nameof::nameof_full_type() == "struct SomeStruct *"); + REQUIRE(nameof::nameof_full_type() == "struct SomeStruct &"); + REQUIRE(nameof::nameof_full_type() == "struct SomeStruct"); + REQUIRE(nameof::nameof_full_type() == "struct SomeStruct *"); + REQUIRE(nameof::nameof_full_type() == "struct SomeStruct &"); + REQUIRE(nameof::nameof_full_type() == "struct SomeStruct const volatile *"); + + REQUIRE(nameof::nameof_full_type>() == "class SomeClass"); + REQUIRE(nameof::nameof_full_type volatile *>() == "class SomeClass const volatile *"); + + REQUIRE(nameof::nameof_full_type() == "struct Long"); + REQUIRE(nameof::nameof_full_type() == "struct Long"); + REQUIRE(nameof::nameof_full_type() == "struct Long::LL"); + + REQUIRE(nameof::nameof_full_type() == "enum Color"); +#elif defined(__GNUC__) + REQUIRE(type_name == "SomeStruct"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct*"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct&"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct*"); + REQUIRE(nameof::nameof_full_type() == "SomeStruct&"); + REQUIRE(nameof::nameof_full_type() == "const volatile SomeStruct*"); + + REQUIRE(nameof::nameof_full_type>() == "SomeClass"); + REQUIRE(nameof::nameof_full_type volatile *>() == "const volatile SomeClass*"); + + REQUIRE(nameof::nameof_full_type() == "Long"); + REQUIRE(nameof::nameof_full_type() == "Long"); + REQUIRE(nameof::nameof_full_type() == "Long::LL"); + + REQUIRE(nameof::nameof_full_type() == "Color"); +#endif +} + +TEST_CASE("NAMEOF_TYPE_EXPR") { + constexpr auto type_name = NAMEOF_TYPE_EXPR(struct_var); +#if defined(__clang__) + REQUIRE(type_name == "SomeStruct"); + REQUIRE(NAMEOF_TYPE_EXPR(ptr_s) == "SomeStruct *"); + REQUIRE(NAMEOF_TYPE_EXPR(ref_s) == "SomeStruct"); + + REQUIRE(NAMEOF_TYPE_EXPR(ptr_c) == "const volatile SomeClass *"); + + REQUIRE(NAMEOF_TYPE_EXPR(othervar) == "Long"); + REQUIRE(NAMEOF_TYPE_EXPR(othervar.ll) == "Long::LL"); + REQUIRE(NAMEOF_TYPE_EXPR(othervar.ll.field) == "int"); + + REQUIRE(NAMEOF_TYPE_EXPR(Color::RED) == "Color"); + + REQUIRE(NAMEOF_TYPE_EXPR(std::declval>()) == "SomeClass"); +#elif defined(_MSC_VER) + REQUIRE(type_name == "struct SomeStruct"); + REQUIRE(NAMEOF_TYPE_EXPR(ptr_s) == "struct SomeStruct *"); + REQUIRE(NAMEOF_TYPE_EXPR(ref_s) == "struct SomeStruct"); + + REQUIRE(NAMEOF_TYPE_EXPR(ptr_c) == "class SomeClass const volatile *"); + + REQUIRE(NAMEOF_TYPE_EXPR(othervar) == "struct Long"); + REQUIRE(NAMEOF_TYPE_EXPR(othervar.ll) == "struct Long::LL"); + REQUIRE(NAMEOF_TYPE_EXPR(othervar.ll.field) == "int"); + + REQUIRE(NAMEOF_TYPE_EXPR(Color::RED) == "enum Color"); + + REQUIRE(NAMEOF_TYPE_EXPR(std::declval>()) == "class SomeClass"); +#elif defined(__GNUC__) + REQUIRE(type_name == "SomeStruct"); + REQUIRE(NAMEOF_TYPE_EXPR(ptr_s) == "SomeStruct*"); + REQUIRE(NAMEOF_TYPE_EXPR(ref_s) == "SomeStruct"); + + REQUIRE(NAMEOF_TYPE_EXPR(ptr_c) == "const volatile SomeClass*"); + + REQUIRE(NAMEOF_TYPE_EXPR(othervar) == "Long"); + REQUIRE(NAMEOF_TYPE_EXPR(othervar.ll) == "Long::LL"); + REQUIRE(NAMEOF_TYPE_EXPR(othervar.ll.field) == "int"); + + REQUIRE(NAMEOF_TYPE_EXPR(Color::RED) == "Color"); + + REQUIRE(NAMEOF_TYPE_EXPR(std::declval>()) == "SomeClass"); #endif } @@ -417,10 +576,10 @@ TEST_CASE("NAMEOF_TYPE") { #if defined(__clang__) REQUIRE(type_name == "SomeStruct"); REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "SomeStruct *"); - REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct &"); + REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct) == "SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct *) == "SomeStruct *"); - REQUIRE(NAMEOF_TYPE(SomeStruct &) == "SomeStruct &"); + REQUIRE(NAMEOF_TYPE(const SomeStruct &) == "SomeStruct"); REQUIRE(NAMEOF_TYPE(const SomeStruct volatile *) == "const volatile SomeStruct *"); REQUIRE(NAMEOF_TYPE(SomeClass) == "SomeClass"); @@ -434,10 +593,10 @@ TEST_CASE("NAMEOF_TYPE") { #elif defined(_MSC_VER) REQUIRE(type_name == "struct SomeStruct"); REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "struct SomeStruct *"); - REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "struct SomeStruct &"); + REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "struct SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct) == "struct SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct *) == "struct SomeStruct *"); - REQUIRE(NAMEOF_TYPE(SomeStruct &) == "struct SomeStruct &"); + REQUIRE(NAMEOF_TYPE(const SomeStruct &) == "struct SomeStruct"); REQUIRE(NAMEOF_TYPE(const SomeStruct volatile *) == "struct SomeStruct const volatile *"); REQUIRE(NAMEOF_TYPE(SomeClass) == "class SomeClass"); @@ -451,10 +610,10 @@ TEST_CASE("NAMEOF_TYPE") { #elif defined(__GNUC__) REQUIRE(type_name == "SomeStruct"); REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "SomeStruct*"); - REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct&"); + REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct) == "SomeStruct"); REQUIRE(NAMEOF_TYPE(SomeStruct *) == "SomeStruct*"); - REQUIRE(NAMEOF_TYPE(SomeStruct &) == "SomeStruct&"); + REQUIRE(NAMEOF_TYPE(const SomeStruct &) == "SomeStruct"); REQUIRE(NAMEOF_TYPE(const SomeStruct volatile *) == "const volatile SomeStruct*"); REQUIRE(NAMEOF_TYPE(SomeClass) == "SomeClass"); @@ -473,10 +632,10 @@ TEST_CASE("nameof::nameof_type") { #if defined(__clang__) REQUIRE(type_name == "SomeStruct"); REQUIRE(nameof::nameof_type() == "SomeStruct *"); - REQUIRE(nameof::nameof_type() == "SomeStruct &"); + REQUIRE(nameof::nameof_type() == "SomeStruct"); REQUIRE(nameof::nameof_type() == "SomeStruct"); REQUIRE(nameof::nameof_type() == "SomeStruct *"); - REQUIRE(nameof::nameof_type() == "SomeStruct &"); + REQUIRE(nameof::nameof_type() == "SomeStruct"); REQUIRE(nameof::nameof_type() == "const volatile SomeStruct *"); REQUIRE(nameof::nameof_type>() == "SomeClass"); @@ -490,10 +649,10 @@ TEST_CASE("nameof::nameof_type") { #elif defined(_MSC_VER) REQUIRE(type_name == "struct SomeStruct"); REQUIRE(nameof::nameof_type() == "struct SomeStruct *"); - REQUIRE(nameof::nameof_type() == "struct SomeStruct &"); + REQUIRE(nameof::nameof_type() == "struct SomeStruct"); REQUIRE(nameof::nameof_type() == "struct SomeStruct"); REQUIRE(nameof::nameof_type() == "struct SomeStruct *"); - REQUIRE(nameof::nameof_type() == "struct SomeStruct &"); + REQUIRE(nameof::nameof_type() == "struct SomeStruct"); REQUIRE(nameof::nameof_type() == "struct SomeStruct const volatile *"); REQUIRE(nameof::nameof_type>() == "class SomeClass"); @@ -507,10 +666,10 @@ TEST_CASE("nameof::nameof_type") { #elif defined(__GNUC__) REQUIRE(type_name == "SomeStruct"); REQUIRE(nameof::nameof_type() == "SomeStruct*"); - REQUIRE(nameof::nameof_type() == "SomeStruct&"); + REQUIRE(nameof::nameof_type() == "SomeStruct"); REQUIRE(nameof::nameof_type() == "SomeStruct"); REQUIRE(nameof::nameof_type() == "SomeStruct*"); - REQUIRE(nameof::nameof_type() == "SomeStruct&"); + REQUIRE(nameof::nameof_type() == "SomeStruct"); REQUIRE(nameof::nameof_type() == "const volatile SomeStruct*"); REQUIRE(nameof::nameof_type>() == "SomeClass");