nameof_module/test/test.cpp

458 lines
17 KiB
C++
Raw Normal View History

2018-04-28 13:04:30 +00:00
// nameof test
2018-03-26 12:02:43 +00:00
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
2018-04-01 20:48:03 +00:00
// Copyright (c) 2018 Daniil Goncharov <neargye@gmail.com>.
2018-03-26 12:02:43 +00:00
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
2018-04-10 18:09:44 +00:00
2018-03-26 12:02:43 +00:00
#include <nameof.hpp>
2018-04-10 18:09:44 +00:00
2018-03-26 12:02:43 +00:00
#include <string>
2018-04-29 20:37:25 +00:00
#include <stdexcept>
2018-03-26 12:02:43 +00:00
struct SomeStruct {
2018-07-13 19:02:03 +00:00
int somefield = 0;
2018-04-10 18:09:44 +00:00
2018-08-02 14:51:44 +00:00
void SomeMethod1(const int i) { somefield = i; }
2018-04-10 18:09:44 +00:00
2018-08-02 14:51:44 +00:00
int SomeMethod2() const { return somefield; }
2018-03-26 12:02:43 +00:00
};
2018-08-02 14:51:44 +00:00
void SomeMethod3() {
std::cout << NAMEOF(SomeMethod3) << " no called!" << std::endl;
}
2018-08-28 14:00:48 +00:00
template <typename T, typename U>
2018-08-28 14:11:36 +00:00
std::string SomeMethod4(U value) {
2018-08-28 15:51:04 +00:00
return NAMEOF(SomeMethod4<T, U>) + "<" + NAMEOF_TYPE_T(T) + ", " + NAMEOF_TYPE_T(U) + ">(" + NAMEOF_TYPE_T(U) + " " + NAMEOF(value) + ")";
2018-08-02 14:51:44 +00:00
}
template <typename T>
class SomeClass {
public:
2018-08-03 12:19:51 +00:00
void SomeMethod5() const {
2018-08-26 20:31:32 +00:00
std::cout << NAMEOF_TYPE_T(T) << std::endl;
2018-08-03 12:19:51 +00:00
}
2018-08-02 14:51:44 +00:00
template <typename C>
2018-08-03 12:19:51 +00:00
C SomeMethod6() const {
C t{};
std::cout << NAMEOF_TYPE(t) << std::endl;
return t;
}
2018-08-02 14:51:44 +00:00
};
2018-03-26 12:02:43 +00:00
struct Long {
struct LL {
2018-07-13 19:02:03 +00:00
int field = 0;
2018-03-26 12:02:43 +00:00
};
2018-04-10 18:09:44 +00:00
LL ll;
2018-03-26 12:02:43 +00:00
};
2018-09-01 17:08:09 +00:00
enum class Color { RED = -1, GREEN, BLUE };
2018-03-27 14:00:06 +00:00
2018-09-01 13:27:49 +00:00
enum Directions { Up, Down, Right, Left};
2018-08-28 14:00:48 +00:00
SomeStruct struct_var;
2018-05-03 19:46:41 +00:00
Long othervar;
2018-08-28 14:00:48 +00:00
SomeStruct * ptr_s = &struct_var;
SomeStruct & ref_s = struct_var;
SomeClass<int> class_var;
const SomeClass<int> volatile * ptr_c = nullptr;
2018-04-02 11:25:43 +00:00
2018-09-01 13:27:49 +00:00
const Color color = Color::RED;
const Directions directions = Directions::Right;
2018-05-03 19:46:41 +00:00
TEST_CASE("constexpr") {
2018-04-02 11:25:43 +00:00
SECTION("NAMEOF") {
2018-04-14 17:51:07 +00:00
// variable
2018-08-28 14:00:48 +00:00
constexpr auto cx1 = NAMEOF(struct_var);
static_assert(cx1 == "struct_var", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx1 == "struct_var");
2018-08-02 14:51:44 +00:00
// member
2018-08-28 14:00:48 +00:00
constexpr auto cx2 = NAMEOF((&struct_var)->somefield);
2018-08-02 14:51:44 +00:00
static_assert(cx2 == "somefield", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx2 == "somefield");
2018-04-14 17:51:07 +00:00
// function
2018-08-26 20:31:32 +00:00
constexpr auto cx3 = NAMEOF(&SomeClass<int>::SomeMethod6<long int>);
static_assert(cx3 == "SomeMethod6", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx3 == "SomeMethod6");
2018-04-14 17:51:07 +00:00
// enum
constexpr auto cx4 = NAMEOF(Color::RED);
2018-08-26 20:31:32 +00:00
static_assert(cx4 == "RED", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx4 == "RED");
2018-08-26 20:31:32 +00:00
}
SECTION("NAMEOF_FULL") {
// variable
2018-08-28 14:00:48 +00:00
constexpr auto cx1 = NAMEOF_FULL(struct_var);
static_assert(cx1 == "struct_var", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx1 == "struct_var");
2018-08-26 20:31:32 +00:00
// member
2018-08-28 14:00:48 +00:00
constexpr auto cx2 = NAMEOF_FULL((&struct_var)->somefield);
2018-08-26 20:31:32 +00:00
static_assert(cx2 == "somefield", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx2 == "somefield");
2018-08-26 20:31:32 +00:00
// function
constexpr auto cx3 = NAMEOF_FULL(&SomeClass<int>::SomeMethod6<long int>);
static_assert(cx3 == "SomeMethod6<long int>", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx3 == "SomeMethod6<long int>");
2018-08-26 20:31:32 +00:00
// enum
constexpr auto cx4 = NAMEOF_FULL(Color::RED);
static_assert(cx4 == "RED", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx4 == "RED");
2018-04-02 11:25:43 +00:00
}
2018-08-02 14:51:44 +00:00
SECTION("NAMEOF_RAW") {
2018-04-14 17:51:07 +00:00
// variable
2018-08-28 14:00:48 +00:00
constexpr auto cx1 = NAMEOF_RAW(struct_var);
static_assert(cx1 == "struct_var", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx1 == "struct_var");
2018-08-02 14:51:44 +00:00
// member
2018-08-28 14:00:48 +00:00
constexpr auto cx2 = NAMEOF_RAW((&struct_var)->somefield);
static_assert(cx2 == "(&struct_var)->somefield", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx2 == "(&struct_var)->somefield");
2018-04-14 17:51:07 +00:00
// function
2018-08-02 14:51:44 +00:00
constexpr auto cx4 = NAMEOF_RAW(&SomeStruct::SomeMethod2);
static_assert(cx4 == "&SomeStruct::SomeMethod2", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx4 == "&SomeStruct::SomeMethod2");
2018-04-14 17:51:07 +00:00
// enum
2018-08-02 14:51:44 +00:00
constexpr auto cx5 = NAMEOF_RAW(Color::RED);
static_assert(cx5 == "Color::RED", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx5 == "Color::RED");
2018-04-14 19:12:32 +00:00
// macros
2018-08-02 14:51:44 +00:00
constexpr auto cx6 = NAMEOF_RAW(__cplusplus);
static_assert(cx6 == "__cplusplus", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx6 == "__cplusplus");
2018-07-13 15:18:52 +00:00
}
2018-08-28 14:00:48 +00:00
2018-09-01 13:27:49 +00:00
SECTION("NAMEOF_ENUM") {
constexpr auto cx = NAMEOF_ENUM(color);
2018-09-01 16:39:51 +00:00
#if defined(__clang__) || defined(_MSC_VER)
2018-09-01 13:27:49 +00:00
static_assert(cx == "RED", "");
REQUIRE(cx == "RED");
2018-09-01 16:39:51 +00:00
#elif defined(__GNUC__)
2018-09-01 17:08:09 +00:00
REQUIRE(cx == "(const Color)-1");
2018-09-01 16:39:51 +00:00
#endif
2018-09-01 13:27:49 +00:00
}
2018-08-27 13:40:23 +00:00
#if defined(NAMEOF_TYPE_HAS_CONSTEXPR)
2018-08-03 12:19:51 +00:00
SECTION("NAMEOF_TYPE") {
2018-08-28 14:00:48 +00:00
constexpr auto cx = NAMEOF_TYPE(ptr_c);
2018-08-27 13:40:23 +00:00
# if defined(__clang__)
2018-08-26 20:31:32 +00:00
static_assert(cx == "const volatile SomeClass<int> *", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx == "const volatile SomeClass<int> *");
# elif defined(__GNUC__)
REQUIRE(cx == "const volatile SomeClass<int>*");
2018-08-27 13:40:23 +00:00
# elif defined(_MSC_VER)
2018-08-26 20:31:32 +00:00
static_assert(cx == "SomeClass<int> const volatile *", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx == "SomeClass<int> const volatile *");
2018-08-27 13:40:23 +00:00
# endif
2018-08-26 20:31:32 +00:00
}
2018-08-27 13:40:23 +00:00
2018-08-26 23:57:25 +00:00
SECTION("NAMEOF_TYPE_T") {
constexpr auto cx = NAMEOF_TYPE_T(const SomeClass<int> volatile *);
2018-08-27 13:40:23 +00:00
# if defined(__clang__)
2018-08-26 20:31:32 +00:00
static_assert(cx == "const volatile SomeClass<int> *", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx == "const volatile SomeClass<int> *");
# elif defined(__GNUC__)
REQUIRE(cx == "const volatile SomeClass<int>*");
2018-08-27 13:40:23 +00:00
# elif defined(_MSC_VER)
2018-08-26 20:31:32 +00:00
static_assert(cx == "SomeClass<int> const volatile *", "");
2018-08-31 14:52:24 +00:00
REQUIRE(cx == "SomeClass<int> const volatile *");
2018-08-27 13:40:23 +00:00
# endif
2018-08-03 12:19:51 +00:00
}
#endif
2018-08-26 20:31:32 +00:00
}
2018-04-02 11:25:43 +00:00
2018-08-26 20:31:32 +00:00
TEST_CASE("NAMEOF") {
2018-04-14 17:51:07 +00:00
SECTION("variable") {
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF(othervar) == "othervar");
REQUIRE(NAMEOF(struct_var) == "struct_var");
REQUIRE(NAMEOF(::struct_var) == "struct_var");
REQUIRE(NAMEOF(ptr_s) == "ptr_s");
2018-03-26 12:02:43 +00:00
}
2018-08-02 14:51:44 +00:00
SECTION("member") {
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF(struct_var.somefield) == "somefield");
REQUIRE(NAMEOF(struct_var.somefield++) == "somefield");
REQUIRE(NAMEOF((&struct_var)->somefield) == "somefield");
2018-08-02 14:51:44 +00:00
REQUIRE(NAMEOF(othervar.ll.field) == "field");
2018-04-04 12:19:02 +00:00
}
2018-04-14 17:51:07 +00:00
SECTION("function") {
2018-08-02 14:51:44 +00:00
REQUIRE(NAMEOF(&SomeStruct::SomeMethod1) == "SomeMethod1");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF(struct_var.SomeMethod1(1)) == "SomeMethod1");
2018-08-02 14:51:44 +00:00
REQUIRE(NAMEOF(&SomeStruct::SomeMethod2) == "SomeMethod2");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF(struct_var.SomeMethod2()) == "SomeMethod2");
2018-08-02 14:51:44 +00:00
REQUIRE(NAMEOF(SomeMethod3) == "SomeMethod3");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF(SomeMethod3()) == "SomeMethod3");
REQUIRE(NAMEOF(SomeMethod4<int, float>) == "SomeMethod4");
REQUIRE(NAMEOF(SomeMethod4<int, float>(1.0f)) == "SomeMethod4");
2018-08-02 14:51:44 +00:00
REQUIRE(NAMEOF(&SomeClass<int>::SomeMethod5) == "SomeMethod5");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF(class_var.SomeMethod5()) == "SomeMethod5");
2018-08-02 14:51:44 +00:00
REQUIRE(NAMEOF(&SomeClass<int>::SomeMethod6<long int>) == "SomeMethod6");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF(class_var.SomeMethod6<long int>()) == "SomeMethod6");
2018-03-26 12:02:43 +00:00
}
2018-04-02 11:25:43 +00:00
2018-04-14 17:51:07 +00:00
SECTION("enum") {
2018-08-02 14:51:44 +00:00
REQUIRE(NAMEOF(Color::RED) == "RED");
REQUIRE(NAMEOF(Color::BLUE) == "BLUE");
2018-04-14 19:12:32 +00:00
}
2018-03-26 12:02:43 +00:00
}
2018-08-03 12:19:51 +00:00
2018-08-26 20:31:32 +00:00
TEST_CASE("NAMEOF_FULL") {
SECTION("variable") {
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_FULL(othervar) == "othervar");
REQUIRE(NAMEOF_FULL(struct_var) == "struct_var");
REQUIRE(NAMEOF_FULL(::struct_var) == "struct_var");
REQUIRE(NAMEOF_FULL(ptr_s) == "ptr_s");
2018-08-26 20:31:32 +00:00
}
SECTION("member") {
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_FULL(struct_var.somefield) == "somefield");
REQUIRE(NAMEOF_FULL(struct_var.somefield++) == "somefield");
REQUIRE(NAMEOF_FULL((&struct_var)->somefield) == "somefield");
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_FULL(othervar.ll.field) == "field");
}
SECTION("function") {
REQUIRE(NAMEOF_FULL(&SomeStruct::SomeMethod1) == "SomeMethod1");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_FULL(struct_var.SomeMethod1(1)) == "SomeMethod1");
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_FULL(&SomeStruct::SomeMethod2) == "SomeMethod2");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_FULL(struct_var.SomeMethod2()) == "SomeMethod2");
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_FULL(SomeMethod3) == "SomeMethod3");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_FULL(SomeMethod3()) == "SomeMethod3");
REQUIRE(NAMEOF_FULL(SomeMethod4<int, float>) == "SomeMethod4<int, float>");
REQUIRE(NAMEOF_FULL(SomeMethod4<int, float>(1.0f)) == "SomeMethod4<int, float>");
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_FULL(&SomeClass<int>::SomeMethod5) == "SomeMethod5");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_FULL(class_var.SomeMethod5()) == "SomeMethod5");
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_FULL(&SomeClass<int>::SomeMethod6<long int>) == "SomeMethod6<long int>");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_FULL(class_var.SomeMethod6<long int>()) == "SomeMethod6<long int>");
2018-08-26 20:31:32 +00:00
}
SECTION("enum") {
REQUIRE(NAMEOF_FULL(Color::RED) == "RED");
REQUIRE(NAMEOF_FULL(Color::BLUE) == "BLUE");
}
}
TEST_CASE("NAMEOF_RAW") {
2018-04-14 17:51:07 +00:00
SECTION("variable") {
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_RAW(othervar) == "othervar");
REQUIRE(NAMEOF_RAW(struct_var) == "struct_var");
REQUIRE(NAMEOF_RAW(&struct_var) == "&struct_var");
REQUIRE(NAMEOF_RAW(::struct_var) == "::struct_var");
REQUIRE(NAMEOF_RAW(ptr_s) == "ptr_s");
REQUIRE(NAMEOF_RAW(*ptr_s) == "*ptr_s");
2018-08-02 14:51:44 +00:00
}
2018-03-26 12:02:43 +00:00
2018-08-02 14:51:44 +00:00
SECTION("member") {
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_RAW(struct_var.somefield) == "struct_var.somefield");
REQUIRE(NAMEOF_RAW(struct_var.somefield++) == "struct_var.somefield++");
REQUIRE(NAMEOF_RAW((&struct_var)->somefield) == "(&struct_var)->somefield");
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_RAW(othervar.ll.field) == "othervar.ll.field");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_RAW(+struct_var.somefield) == "+struct_var.somefield");
REQUIRE(NAMEOF_RAW(-struct_var.somefield) == "-struct_var.somefield");
REQUIRE(NAMEOF_RAW(~struct_var.somefield) == "~struct_var.somefield");
REQUIRE(NAMEOF_RAW(!struct_var.somefield) == "!struct_var.somefield");
REQUIRE(NAMEOF_RAW(struct_var.somefield + ref_s.somefield) == "struct_var.somefield + ref_s.somefield");
2018-03-26 12:02:43 +00:00
}
2018-04-04 12:19:02 +00:00
2018-04-14 17:51:07 +00:00
SECTION("function") {
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_RAW(&SomeStruct::SomeMethod1) == "&SomeStruct::SomeMethod1");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_RAW(struct_var.SomeMethod1(1)) == "struct_var.SomeMethod1(1)");
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_RAW(&SomeStruct::SomeMethod2) == "&SomeStruct::SomeMethod2");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_RAW(struct_var.SomeMethod2()) == "struct_var.SomeMethod2()");
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_RAW(SomeMethod3) == "SomeMethod3");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_RAW(SomeMethod3()) == "SomeMethod3()");
REQUIRE(NAMEOF_RAW(SomeMethod4<int, float>) == "SomeMethod4<int, float>");
REQUIRE(NAMEOF_RAW(SomeMethod4<int, float>(1.0f)) == "SomeMethod4<int, float>(1.0f)");
REQUIRE(NAMEOF_RAW(&SomeClass<int>::SomeMethod5) == "&SomeClass<int>::SomeMethod5");
REQUIRE(NAMEOF_RAW(class_var.SomeMethod5()) == "class_var.SomeMethod5()");
REQUIRE(NAMEOF_RAW(&SomeClass<int>::SomeMethod6<long int>) == "&SomeClass<int>::SomeMethod6<long int>");
REQUIRE(NAMEOF_RAW(class_var.SomeMethod6<long int>()) == "class_var.SomeMethod6<long int>()");
2018-03-26 12:02:43 +00:00
}
2018-04-02 11:25:43 +00:00
2018-04-14 17:51:07 +00:00
SECTION("enum") {
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_RAW(Color::RED) == "Color::RED");
REQUIRE(NAMEOF_RAW(Color::BLUE) == "Color::BLUE");
2018-04-02 11:25:43 +00:00
}
2018-04-14 19:12:32 +00:00
SECTION("macros") {
2018-08-26 20:31:32 +00:00
REQUIRE(NAMEOF_RAW(__cplusplus) == "__cplusplus");
REQUIRE(NAMEOF_RAW(__LINE__) == "__LINE__");
REQUIRE(NAMEOF_RAW(__FILE__) == "__FILE__");
2018-04-14 19:12:32 +00:00
}
2018-03-26 12:02:43 +00:00
}
2018-05-03 19:50:08 +00:00
2018-09-01 13:27:49 +00:00
TEST_CASE("NAMEOF_ENUM") {
# if defined(__clang__) || defined(_MSC_VER)
REQUIRE(NAMEOF_ENUM(Color::RED) == "RED");
2018-09-01 17:08:09 +00:00
REQUIRE(NAMEOF_ENUM(::color) == "RED");
auto color_ = Color::BLUE;
REQUIRE(NAMEOF_ENUM(Color::BLUE) == "BLUE");
REQUIRE(NAMEOF_ENUM(color_) == "BLUE");
2018-09-01 13:27:49 +00:00
REQUIRE(NAMEOF_ENUM(Directions::Right) == "Right");
REQUIRE(NAMEOF_ENUM(directions) == "Right");
# elif defined(__GNUC__)
2018-09-01 17:08:09 +00:00
REQUIRE(NAMEOF_ENUM(Color::RED) == "(Color)-1");
REQUIRE(NAMEOF_ENUM(color) == "(const Color)-1");
2018-09-01 13:27:49 +00:00
2018-09-01 16:39:51 +00:00
REQUIRE(NAMEOF_ENUM(Directions::Right) == "(Directions)2");
REQUIRE(NAMEOF_ENUM(directions) == "(const Directions)2");
2018-09-01 13:27:49 +00:00
# endif
}
2018-08-26 20:31:32 +00:00
TEST_CASE("NAMEOF_TYPE") {
2018-08-26 23:57:25 +00:00
#if defined(__clang__)
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE(struct_var) == "SomeStruct");
REQUIRE(NAMEOF_TYPE(ptr_s) == "SomeStruct *");
2018-08-28 14:11:36 +00:00
REQUIRE(NAMEOF_TYPE(ref_s) == "SomeStruct &");
2018-08-03 12:19:51 +00:00
2018-08-28 14:11:36 +00:00
REQUIRE(NAMEOF_TYPE(ptr_c) == "const volatile SomeClass<int> *");
2018-08-26 20:31:32 +00:00
2018-08-03 12:19:51 +00:00
REQUIRE(NAMEOF_TYPE(othervar) == "Long");
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE(othervar.ll) == "Long::LL");
2018-08-03 12:19:51 +00:00
REQUIRE(NAMEOF_TYPE(othervar.ll.field) == "int");
REQUIRE(NAMEOF_TYPE(Color::RED) == "Color");
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE(std::declval<const SomeClass<int>>()) == "const SomeClass<int> &&");
#elif defined(_MSC_VER)
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE(struct_var) == "SomeStruct");
REQUIRE(NAMEOF_TYPE(ptr_s) == "SomeStruct *");
REQUIRE(NAMEOF_TYPE(ref_s) == "SomeStruct &");
2018-08-03 12:19:51 +00:00
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE(ptr_c) == "SomeClass<int> const volatile *");
2018-08-03 12:19:51 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE(othervar) == "Long");
REQUIRE(NAMEOF_TYPE(othervar.ll) == "Long::LL");
REQUIRE(NAMEOF_TYPE(othervar.ll.field) == "int");
2018-08-26 20:31:32 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE(Color::RED) == "Color");
2018-08-03 12:19:51 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE(std::declval<const SomeClass<int>>()) == "SomeClass<int> const &&");
#elif defined(__GNUC__)
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE(struct_var) == "SomeStruct");
REQUIRE(NAMEOF_TYPE(ptr_s) == "SomeStruct*");
2018-08-28 14:11:36 +00:00
REQUIRE(NAMEOF_TYPE(ref_s) == "SomeStruct&");
2018-08-26 20:31:32 +00:00
2018-08-28 14:11:36 +00:00
REQUIRE(NAMEOF_TYPE(ptr_c) == "const volatile SomeClass<int>*");
2018-08-26 20:31:32 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE(othervar) == "Long");
REQUIRE(NAMEOF_TYPE(othervar.ll) == "Long::LL");
REQUIRE(NAMEOF_TYPE(othervar.ll.field) == "int");
2018-08-26 20:31:32 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE(Color::RED) == "Color");
2018-08-03 12:19:51 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE(std::declval<const SomeClass<int>>()) == "const SomeClass<int>&&");
#endif
2018-08-26 20:31:32 +00:00
}
2018-08-26 23:57:25 +00:00
TEST_CASE("NAMEOF_TYPE_T") {
2018-08-26 20:31:32 +00:00
#if defined(__clang__)
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE_T(decltype(struct_var)) == "SomeStruct");
REQUIRE(NAMEOF_TYPE_T(decltype(ptr_s)) == "SomeStruct *");
2018-08-28 14:11:36 +00:00
REQUIRE(NAMEOF_TYPE_T(decltype(ref_s)) == "SomeStruct &");
2018-08-26 23:57:25 +00:00
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 *) == "const volatile SomeStruct *");
2018-08-26 20:31:32 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(SomeClass<int>) == "SomeClass<int>");
REQUIRE(NAMEOF_TYPE_T(const SomeClass<int> volatile *) == "const volatile SomeClass<int> *");
2018-08-06 11:01:40 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(decltype(othervar)) == "Long");
REQUIRE(NAMEOF_TYPE_T(Long) == "Long");
REQUIRE(NAMEOF_TYPE_T(Long::LL) == "Long::LL");
2018-08-06 11:01:40 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(Color) == "Color");
2018-08-26 20:31:32 +00:00
#elif defined(_MSC_VER)
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE_T(decltype(struct_var)) == "SomeStruct");
REQUIRE(NAMEOF_TYPE_T(decltype(ptr_s)) == "SomeStruct *");
REQUIRE(NAMEOF_TYPE_T(decltype(ref_s)) == "SomeStruct &");
2018-08-26 23:57:25 +00:00
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 const volatile *");
2018-08-26 20:31:32 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(SomeClass<int>) == "SomeClass<int>");
REQUIRE(NAMEOF_TYPE_T(const SomeClass<int> volatile *) == "SomeClass<int> const volatile *");
2018-08-26 20:31:32 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(decltype(othervar)) == "Long");
REQUIRE(NAMEOF_TYPE_T(Long) == "Long");
REQUIRE(NAMEOF_TYPE_T(Long::LL) == "Long::LL");
2018-08-26 20:31:32 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(Color) == "Color");
2018-08-06 11:01:40 +00:00
#elif defined(__GNUC__)
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE_T(decltype(struct_var)) == "SomeStruct");
REQUIRE(NAMEOF_TYPE_T(decltype(ptr_s)) == "SomeStruct*");
2018-08-28 14:11:36 +00:00
REQUIRE(NAMEOF_TYPE_T(decltype(ref_s)) == "SomeStruct&");
2018-08-26 23:57:25 +00:00
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 *) == "const volatile SomeStruct*");
2018-08-03 12:19:51 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(SomeClass<int>) == "SomeClass<int>");
REQUIRE(NAMEOF_TYPE_T(const SomeClass<int> volatile *) == "const volatile SomeClass<int>*");
2018-08-03 12:19:51 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(decltype(othervar)) == "Long");
REQUIRE(NAMEOF_TYPE_T(Long) == "Long");
REQUIRE(NAMEOF_TYPE_T(Long::LL) == "Long::LL");
2018-08-03 12:19:51 +00:00
2018-08-26 23:57:25 +00:00
REQUIRE(NAMEOF_TYPE_T(Color) == "Color");
2018-08-26 20:31:32 +00:00
#endif
}
2018-05-03 20:18:02 +00:00
TEST_CASE("Spaces and Tabs ignored") {
SECTION("Spaces") {
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF( struct_var ) == "struct_var");
REQUIRE(NAMEOF_FULL( struct_var ) == "struct_var");
REQUIRE(NAMEOF_RAW( struct_var ) == "struct_var");
2018-09-01 16:39:51 +00:00
#if defined(__clang__) || defined(_MSC_VER)
2018-09-01 13:27:49 +00:00
REQUIRE(NAMEOF_ENUM( color ) == "RED");
2018-09-01 16:39:51 +00:00
#elif defined(__GNUC__)
2018-09-01 17:08:09 +00:00
REQUIRE(NAMEOF_ENUM( color ) == "(const Color)-1");
2018-09-01 16:39:51 +00:00
#endif
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE( struct_var ) == "SomeStruct");
REQUIRE(NAMEOF_TYPE_T( decltype(struct_var) ) == "SomeStruct");
}
2018-07-13 15:18:52 +00:00
SECTION("Tabs") {
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF( struct_var ) == "struct_var");
REQUIRE(NAMEOF_FULL( struct_var ) == "struct_var");
REQUIRE(NAMEOF_RAW( struct_var ) == "struct_var");
2018-09-01 16:39:51 +00:00
#if defined(__clang__) || defined(_MSC_VER)
2018-09-01 13:27:49 +00:00
REQUIRE(NAMEOF_ENUM( color ) == "RED");
2018-09-01 16:39:51 +00:00
#elif defined(__GNUC__)
2018-09-01 17:08:09 +00:00
REQUIRE(NAMEOF_ENUM( color ) == "(const Color)-1");
2018-09-01 16:39:51 +00:00
#endif
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_TYPE( struct_var ) == "SomeStruct");
REQUIRE(NAMEOF_TYPE_T( decltype(struct_var) ) == "SomeStruct");
2018-07-13 15:18:52 +00:00
}
}
2018-08-28 15:51:04 +00:00
TEST_CASE("cstring") {}