nameof_module/test/test.cpp

702 lines
29 KiB
C++
Raw Normal View History

2018-03-26 12:02:43 +00:00
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
2019-03-20 16:41:51 +00:00
// SPDX-License-Identifier: MIT
2020-02-25 10:53:42 +00:00
// Copyright (c) 2018 - 2020 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
2019-08-24 15:31:42 +00:00
#include <catch.hpp>
2018-04-10 18:09:44 +00:00
2019-04-18 08:52:09 +00:00
#define NAMEOF_ENUM_RANGE_MIN -120
#define NAMEOF_ENUM_RANGE_MAX 120
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
2019-04-18 08:52:09 +00:00
void SomeMethod1(int) {
throw std::runtime_error{"should not be called!"};
}
2018-04-10 18:09:44 +00:00
2019-04-18 08:52:09 +00:00
int SomeMethod2() const {
throw std::runtime_error{"should not be called!"};
}
2018-03-26 12:02:43 +00:00
};
2018-08-02 14:51:44 +00:00
void SomeMethod3() {
2019-03-20 16:41:51 +00:00
throw std::runtime_error{"should not be called!"};
2018-08-02 14:51:44 +00:00
}
2018-08-28 14:00:48 +00:00
template <typename T, typename U>
2019-03-20 16:41:51 +00:00
std::string SomeMethod4(U) {
throw std::runtime_error{"should not be called!"};
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 {
2019-04-18 08:52:09 +00:00
throw std::runtime_error{"should not be called!"};
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 {
2019-04-18 08:52:09 +00:00
throw std::runtime_error{"should not be called!"};
2018-08-03 12:19:51 +00:00
}
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
};
2019-04-18 08:52:09 +00:00
enum class Color { RED = -12, GREEN = 7, BLUE = 15 };
2019-10-01 13:43:32 +00:00
enum class Numbers : int { one = 1, two, three, many = 127 };
2019-04-18 08:52:09 +00:00
enum Directions { Up = 85, Down = -42, Right = 120, Left = -120 };
2019-05-03 10:22:23 +00:00
enum number : unsigned long { one = 100, two = 200, three = 300, four = 400 };
2018-03-27 14:00:06 +00:00
2019-04-18 08:52:09 +00:00
namespace nameof {
template <>
struct enum_range<number> {
2019-04-25 16:57:00 +00:00
static_assert(std::is_enum_v<number>, "nameof::enum_range<number> requires enum type.");
2019-04-18 08:52:09 +00:00
static constexpr int min = 100;
static constexpr int max = 300;
2019-04-25 16:57:00 +00:00
static_assert(max > min, "nameof::enum_range<number> requires max > min.");
2019-04-18 08:52:09 +00:00
};
2020-02-14 13:04:48 +00:00
} // namespace nameof
2018-09-01 13:27:49 +00:00
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;
2018-08-26 20:31:32 +00:00
TEST_CASE("NAMEOF") {
2018-04-14 17:51:07 +00:00
SECTION("variable") {
2019-04-10 13:48:14 +00:00
constexpr auto name = NAMEOF(othervar);
REQUIRE(name == "othervar");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF(struct_var) == "struct_var");
REQUIRE(NAMEOF(::struct_var) == "struct_var");
REQUIRE(NAMEOF(ptr_s) == "ptr_s");
2019-04-18 09:05:40 +00:00
REQUIRE(NAMEOF(color) == "color");
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");
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") {
2019-04-10 13:48:14 +00:00
constexpr auto full_name = NAMEOF_FULL(othervar);
REQUIRE(full_name == "othervar");
2018-08-28 14:00:48 +00:00
REQUIRE(NAMEOF_FULL(struct_var) == "struct_var");
REQUIRE(NAMEOF_FULL(::struct_var) == "struct_var");
REQUIRE(NAMEOF_FULL(ptr_s) == "ptr_s");
2019-04-18 09:05:40 +00:00
REQUIRE(NAMEOF_FULL(color) == "color");
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");
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") {
2019-04-10 13:48:14 +00:00
constexpr auto raw_name = NAMEOF_RAW(othervar);
REQUIRE(raw_name == "othervar");
2018-08-28 14:00:48 +00:00
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");
2019-04-02 15:42:47 +00:00
REQUIRE(NAMEOF_RAW(ptr_s[0]) == "ptr_s[0]");
2019-04-18 09:05:40 +00:00
REQUIRE(NAMEOF_RAW(color) == "color");
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
2019-03-22 04:46:37 +00:00
SECTION("macro") {
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
#if defined(NAMEOF_ENUM_SUPPORTED)
2019-10-01 13:43:32 +00:00
static_assert(nameof::is_nameof_enum_supported, "nameof::nameof_enum: Unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
2019-05-03 10:22:23 +00:00
TEST_CASE("NAMEOF_ENUM") {
2019-04-18 08:52:09 +00:00
constexpr Color cr = Color::RED;
constexpr auto cr_name = NAMEOF_ENUM(cr);
Color cm[3] = {Color::RED, Color::GREEN, Color::BLUE};
REQUIRE(cr_name == "RED");
2018-09-01 17:08:09 +00:00
REQUIRE(NAMEOF_ENUM(Color::BLUE) == "BLUE");
2019-04-18 08:52:09 +00:00
REQUIRE(NAMEOF_ENUM(cm[1]) == "GREEN");
REQUIRE(NAMEOF_ENUM(static_cast<Color>(0)).empty());
constexpr Numbers no = Numbers::one;
constexpr auto no_name = NAMEOF_ENUM(no);
REQUIRE(no_name == "one");
REQUIRE(NAMEOF_ENUM(Numbers::two) == "two");
REQUIRE(NAMEOF_ENUM(Numbers::three) == "three");
2019-05-03 10:57:48 +00:00
REQUIRE(NAMEOF_ENUM(Numbers::many).empty());
2019-04-18 08:52:09 +00:00
REQUIRE(NAMEOF_ENUM(static_cast<Numbers>(0)).empty());
constexpr Directions dr = Directions::Right;
constexpr auto dr_name = NAMEOF_ENUM(dr);
REQUIRE(NAMEOF_ENUM(Directions::Up) == "Up");
REQUIRE(NAMEOF_ENUM(Directions::Down) == "Down");
REQUIRE(dr_name == "Right");
REQUIRE(NAMEOF_ENUM(Directions::Left) == "Left");
REQUIRE(NAMEOF_ENUM(static_cast<Directions>(0)).empty());
constexpr number nt = number::three;
constexpr auto nt_name = NAMEOF_ENUM(nt);
REQUIRE(NAMEOF_ENUM(number::one) == "one");
REQUIRE(NAMEOF_ENUM(number::two) == "two");
REQUIRE(nt_name == "three");
2019-05-03 10:57:48 +00:00
REQUIRE(NAMEOF_ENUM(number::four).empty());
2019-04-18 08:52:09 +00:00
REQUIRE(NAMEOF_ENUM(static_cast<number>(0)).empty());
2018-09-01 13:27:49 +00:00
}
2019-05-03 10:22:23 +00:00
TEST_CASE("NAMEOF_CONST_ENUM") {
2019-04-18 08:52:09 +00:00
constexpr Color cr = Color::RED;
2019-05-03 10:22:23 +00:00
constexpr auto cr_name = NAMEOF_CONST_ENUM(cr);
2019-05-03 10:57:48 +00:00
constexpr Color cm[3] = {Color::RED, Color::GREEN, Color::BLUE};
2019-04-18 08:52:09 +00:00
REQUIRE(cr_name == "RED");
2019-05-03 10:22:23 +00:00
REQUIRE(NAMEOF_CONST_ENUM(Color::BLUE) == "BLUE");
REQUIRE(NAMEOF_CONST_ENUM(cm[1]) == "GREEN");
2019-04-18 08:52:09 +00:00
constexpr Numbers no = Numbers::one;
2019-05-03 10:22:23 +00:00
constexpr auto no_name = NAMEOF_CONST_ENUM(no);
2019-04-18 08:52:09 +00:00
REQUIRE(no_name == "one");
2019-05-03 10:22:23 +00:00
REQUIRE(NAMEOF_CONST_ENUM(Numbers::two) == "two");
REQUIRE(NAMEOF_CONST_ENUM(Numbers::three) == "three");
2019-05-03 10:57:48 +00:00
REQUIRE(NAMEOF_CONST_ENUM(Numbers::many) == "many");
2019-04-18 08:52:09 +00:00
constexpr Directions dr = Directions::Right;
2019-05-03 10:22:23 +00:00
constexpr auto dr_name = NAMEOF_CONST_ENUM(dr);
REQUIRE(NAMEOF_CONST_ENUM(Directions::Up) == "Up");
REQUIRE(NAMEOF_CONST_ENUM(Directions::Down) == "Down");
2019-04-18 08:52:09 +00:00
REQUIRE(dr_name == "Right");
2019-05-03 10:22:23 +00:00
REQUIRE(NAMEOF_CONST_ENUM(Directions::Left) == "Left");
2019-04-18 08:52:09 +00:00
constexpr number nt = number::three;
2019-05-03 10:22:23 +00:00
constexpr auto nt_name = NAMEOF_CONST_ENUM(nt);
REQUIRE(NAMEOF_CONST_ENUM(number::one) == "one");
REQUIRE(NAMEOF_CONST_ENUM(number::two) == "two");
2019-04-18 08:52:09 +00:00
REQUIRE(nt_name == "three");
2019-05-03 10:57:48 +00:00
REQUIRE(NAMEOF_CONST_ENUM(number::four) == "four");
2019-03-22 10:30:32 +00:00
}
2019-05-03 10:22:23 +00:00
TEST_CASE("nameof_enum") {
SECTION("automatic storage") {
constexpr Color cr = Color::RED;
constexpr auto cr_name = nameof::nameof_enum(cr);
Color cm[3] = {Color::RED, Color::GREEN, Color::BLUE};
REQUIRE(cr_name == "RED");
REQUIRE(nameof::nameof_enum(Color::BLUE) == "BLUE");
REQUIRE(nameof::nameof_enum(cm[1]) == "GREEN");
REQUIRE(nameof::nameof_enum(static_cast<Color>(0)).empty());
constexpr Numbers no = Numbers::one;
constexpr auto no_name = nameof::nameof_enum(no);
REQUIRE(no_name == "one");
REQUIRE(nameof::nameof_enum(Numbers::two) == "two");
REQUIRE(nameof::nameof_enum(Numbers::three) == "three");
REQUIRE(nameof::nameof_enum(Numbers::many).empty());
REQUIRE(nameof::nameof_enum(static_cast<Numbers>(0)).empty());
constexpr Directions dr = Directions::Right;
constexpr auto dr_name = nameof::nameof_enum(dr);
REQUIRE(nameof::nameof_enum(Directions::Up) == "Up");
REQUIRE(nameof::nameof_enum(Directions::Down) == "Down");
REQUIRE(dr_name == "Right");
REQUIRE(nameof::nameof_enum(Directions::Left) == "Left");
REQUIRE(nameof::nameof_enum(static_cast<Directions>(0)).empty());
constexpr number nt = number::three;
constexpr auto nt_name = nameof::nameof_enum(nt);
REQUIRE(nameof::nameof_enum(number::one) == "one");
REQUIRE(nameof::nameof_enum(number::two) == "two");
REQUIRE(nt_name == "three");
REQUIRE(nameof::nameof_enum(number::four).empty());
REQUIRE(nameof::nameof_enum(static_cast<number>(0)).empty());
}
SECTION("static storage") {
constexpr Color cr = Color::RED;
constexpr auto cr_name = nameof::nameof_enum<cr>();
constexpr Color cm[3] = {Color::RED, Color::GREEN, Color::BLUE};
REQUIRE(cr_name == "RED");
REQUIRE(nameof::nameof_enum<Color::BLUE>() == "BLUE");
REQUIRE(nameof::nameof_enum<cm[1]>() == "GREEN");
constexpr Numbers no = Numbers::one;
constexpr auto no_name = nameof::nameof_enum<no>();
REQUIRE(no_name == "one");
REQUIRE(nameof::nameof_enum<Numbers::two>() == "two");
REQUIRE(nameof::nameof_enum<Numbers::three>() == "three");
REQUIRE(nameof::nameof_enum<Numbers::many>() == "many");
constexpr Directions dr = Directions::Right;
constexpr auto dr_name = nameof::nameof_enum<dr>();
REQUIRE(nameof::nameof_enum<Directions::Up>() == "Up");
REQUIRE(nameof::nameof_enum<Directions::Down>() == "Down");
REQUIRE(dr_name == "Right");
REQUIRE(nameof::nameof_enum<Directions::Left>() == "Left");
constexpr number nt = number::three;
constexpr auto nt_name = nameof::nameof_enum<nt>();
REQUIRE(nameof::nameof_enum<number::one>() == "one");
REQUIRE(nameof::nameof_enum<number::two>() == "two");
REQUIRE(nt_name == "three");
REQUIRE(nameof::nameof_enum<number::four>() == "four");
}
}
2019-10-01 13:43:32 +00:00
2019-05-03 10:22:23 +00:00
#endif
#if defined(NAMEOF_TYPE_SUPPORTED)
2019-10-01 13:43:32 +00:00
static_assert(nameof::is_nameof_type_supported, "nameof::nameof_type: Unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
2019-07-21 19:13:14 +00:00
TEST_CASE("NAMEOF_FULL_TYPE_EXPR") {
constexpr auto type_name = NAMEOF_FULL_TYPE_EXPR(struct_var);
2018-08-26 23:57:25 +00:00
#if defined(__clang__)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "SomeStruct");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_s) == "SomeStruct *");
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ref_s) == "SomeStruct &");
2018-08-03 12:19:51 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_c) == "const volatile SomeClass<int> *");
2018-08-26 20:31:32 +00:00
2019-07-21 19:13:14 +00:00
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");
2018-08-03 12:19:51 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(Color::RED) == "Color");
2018-08-03 12:19:51 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(std::declval<const SomeClass<int>>()) == "const SomeClass<int> &&");
2018-08-26 23:57:25 +00:00
#elif defined(_MSC_VER)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "struct SomeStruct");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_s) == "struct SomeStruct *");
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ref_s) == "struct SomeStruct &");
2018-08-03 12:19:51 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_c) == "class SomeClass<int> const volatile *");
2018-08-03 12:19:51 +00:00
2019-07-21 19:13:14 +00:00
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");
2018-08-26 20:31:32 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(Color::RED) == "enum Color");
2018-08-03 12:19:51 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(std::declval<const SomeClass<int>>()) == "class SomeClass<int> const &&");
2018-08-26 23:57:25 +00:00
#elif defined(__GNUC__)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "SomeStruct");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_s) == "SomeStruct*");
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ref_s) == "SomeStruct&");
2018-08-26 20:31:32 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(ptr_c) == "const volatile SomeClass<int>*");
2018-08-26 20:31:32 +00:00
2019-07-21 19:13:14 +00:00
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");
2018-08-26 20:31:32 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(Color::RED) == "Color");
2018-08-03 12:19:51 +00:00
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_FULL_TYPE_EXPR(std::declval<const SomeClass<int>>()) == "const SomeClass<int>&&");
#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<int>) == "SomeClass<int>");
REQUIRE(NAMEOF_FULL_TYPE(const SomeClass<int> volatile *) == "const volatile SomeClass<int> *");
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<int>) == "class SomeClass<int>");
REQUIRE(NAMEOF_FULL_TYPE(const SomeClass<int> volatile *) == "class SomeClass<int> 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<int>) == "SomeClass<int>");
REQUIRE(NAMEOF_FULL_TYPE(const SomeClass<int> volatile *) == "const volatile SomeClass<int>*");
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<decltype(struct_var)>();
#if defined(__clang__)
REQUIRE(type_name == "SomeStruct");
REQUIRE(nameof::nameof_full_type<decltype(ptr_s)>() == "SomeStruct *");
REQUIRE(nameof::nameof_full_type<decltype(ref_s)>() == "SomeStruct &");
REQUIRE(nameof::nameof_full_type<SomeStruct>() == "SomeStruct");
REQUIRE(nameof::nameof_full_type<SomeStruct *>() == "SomeStruct *");
REQUIRE(nameof::nameof_full_type<SomeStruct &>() == "SomeStruct &");
REQUIRE(nameof::nameof_full_type<const SomeStruct volatile *>() == "const volatile SomeStruct *");
REQUIRE(nameof::nameof_full_type<SomeClass<int>>() == "SomeClass<int>");
REQUIRE(nameof::nameof_full_type<const SomeClass<int> volatile *>() == "const volatile SomeClass<int> *");
REQUIRE(nameof::nameof_full_type<decltype(othervar)>() == "Long");
REQUIRE(nameof::nameof_full_type<Long>() == "Long");
REQUIRE(nameof::nameof_full_type<Long::LL>() == "Long::LL");
REQUIRE(nameof::nameof_full_type<Color>() == "Color");
#elif defined(_MSC_VER)
REQUIRE(type_name == "struct SomeStruct");
REQUIRE(nameof::nameof_full_type<decltype(ptr_s)>() == "struct SomeStruct *");
REQUIRE(nameof::nameof_full_type<decltype(ref_s)>() == "struct SomeStruct &");
REQUIRE(nameof::nameof_full_type<SomeStruct>() == "struct SomeStruct");
REQUIRE(nameof::nameof_full_type<SomeStruct *>() == "struct SomeStruct *");
REQUIRE(nameof::nameof_full_type<SomeStruct &>() == "struct SomeStruct &");
REQUIRE(nameof::nameof_full_type<const SomeStruct volatile *>() == "struct SomeStruct const volatile *");
REQUIRE(nameof::nameof_full_type<SomeClass<int>>() == "class SomeClass<int>");
REQUIRE(nameof::nameof_full_type<const SomeClass<int> volatile *>() == "class SomeClass<int> const volatile *");
REQUIRE(nameof::nameof_full_type<decltype(othervar)>() == "struct Long");
REQUIRE(nameof::nameof_full_type<Long>() == "struct Long");
REQUIRE(nameof::nameof_full_type<Long::LL>() == "struct Long::LL");
REQUIRE(nameof::nameof_full_type<Color>() == "enum Color");
#elif defined(__GNUC__)
REQUIRE(type_name == "SomeStruct");
REQUIRE(nameof::nameof_full_type<decltype(ptr_s)>() == "SomeStruct*");
REQUIRE(nameof::nameof_full_type<decltype(ref_s)>() == "SomeStruct&");
REQUIRE(nameof::nameof_full_type<SomeStruct>() == "SomeStruct");
REQUIRE(nameof::nameof_full_type<SomeStruct *>() == "SomeStruct*");
REQUIRE(nameof::nameof_full_type<SomeStruct &>() == "SomeStruct&");
REQUIRE(nameof::nameof_full_type<const SomeStruct volatile *>() == "const volatile SomeStruct*");
REQUIRE(nameof::nameof_full_type<SomeClass<int>>() == "SomeClass<int>");
REQUIRE(nameof::nameof_full_type<const SomeClass<int> volatile *>() == "const volatile SomeClass<int>*");
REQUIRE(nameof::nameof_full_type<decltype(othervar)>() == "Long");
REQUIRE(nameof::nameof_full_type<Long>() == "Long");
REQUIRE(nameof::nameof_full_type<Long::LL>() == "Long::LL");
REQUIRE(nameof::nameof_full_type<Color>() == "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<int> *");
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<const SomeClass<int>>()) == "SomeClass<int>");
#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<int> 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<const SomeClass<int>>()) == "class SomeClass<int>");
#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<int>*");
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<const SomeClass<int>>()) == "SomeClass<int>");
2018-08-26 23:57:25 +00:00
#endif
2018-08-26 20:31:32 +00:00
}
2019-04-01 19:07:28 +00:00
TEST_CASE("NAMEOF_TYPE") {
2019-04-10 13:48:14 +00:00
constexpr auto type_name = NAMEOF_TYPE(decltype(struct_var));
2018-08-26 20:31:32 +00:00
#if defined(__clang__)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "SomeStruct");
2019-04-01 19:07:28 +00:00
REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "SomeStruct *");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct");
2019-04-01 19:07:28 +00:00
REQUIRE(NAMEOF_TYPE(SomeStruct) == "SomeStruct");
REQUIRE(NAMEOF_TYPE(SomeStruct *) == "SomeStruct *");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_TYPE(const SomeStruct &) == "SomeStruct");
2019-04-01 19:07:28 +00:00
REQUIRE(NAMEOF_TYPE(const SomeStruct volatile *) == "const volatile SomeStruct *");
REQUIRE(NAMEOF_TYPE(SomeClass<int>) == "SomeClass<int>");
REQUIRE(NAMEOF_TYPE(const SomeClass<int> volatile *) == "const volatile SomeClass<int> *");
REQUIRE(NAMEOF_TYPE(decltype(othervar)) == "Long");
REQUIRE(NAMEOF_TYPE(Long) == "Long");
REQUIRE(NAMEOF_TYPE(Long::LL) == "Long::LL");
REQUIRE(NAMEOF_TYPE(Color) == "Color");
2018-08-26 20:31:32 +00:00
#elif defined(_MSC_VER)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "struct SomeStruct");
2019-04-10 12:23:21 +00:00
REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "struct SomeStruct *");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "struct SomeStruct");
2019-04-10 12:23:21 +00:00
REQUIRE(NAMEOF_TYPE(SomeStruct) == "struct SomeStruct");
REQUIRE(NAMEOF_TYPE(SomeStruct *) == "struct SomeStruct *");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_TYPE(const SomeStruct &) == "struct SomeStruct");
2019-04-10 12:23:21 +00:00
REQUIRE(NAMEOF_TYPE(const SomeStruct volatile *) == "struct SomeStruct const volatile *");
REQUIRE(NAMEOF_TYPE(SomeClass<int>) == "class SomeClass<int>");
REQUIRE(NAMEOF_TYPE(const SomeClass<int> volatile *) == "class SomeClass<int> const volatile *");
REQUIRE(NAMEOF_TYPE(decltype(othervar)) == "struct Long");
REQUIRE(NAMEOF_TYPE(Long) == "struct Long");
REQUIRE(NAMEOF_TYPE(Long::LL) == "struct Long::LL");
REQUIRE(NAMEOF_TYPE(Color) == "enum Color");
2018-08-06 11:01:40 +00:00
#elif defined(__GNUC__)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "SomeStruct");
2019-04-01 19:07:28 +00:00
REQUIRE(NAMEOF_TYPE(decltype(ptr_s)) == "SomeStruct*");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_TYPE(decltype(ref_s)) == "SomeStruct");
2019-04-01 19:07:28 +00:00
REQUIRE(NAMEOF_TYPE(SomeStruct) == "SomeStruct");
REQUIRE(NAMEOF_TYPE(SomeStruct *) == "SomeStruct*");
2019-07-21 19:13:14 +00:00
REQUIRE(NAMEOF_TYPE(const SomeStruct &) == "SomeStruct");
2019-04-01 19:07:28 +00:00
REQUIRE(NAMEOF_TYPE(const SomeStruct volatile *) == "const volatile SomeStruct*");
REQUIRE(NAMEOF_TYPE(SomeClass<int>) == "SomeClass<int>");
REQUIRE(NAMEOF_TYPE(const SomeClass<int> volatile *) == "const volatile SomeClass<int>*");
REQUIRE(NAMEOF_TYPE(decltype(othervar)) == "Long");
REQUIRE(NAMEOF_TYPE(Long) == "Long");
REQUIRE(NAMEOF_TYPE(Long::LL) == "Long::LL");
REQUIRE(NAMEOF_TYPE(Color) == "Color");
2018-08-26 20:31:32 +00:00
#endif
}
2019-04-10 13:48:14 +00:00
TEST_CASE("nameof::nameof_type") {
constexpr auto type_name = nameof::nameof_type<decltype(struct_var)>();
2019-03-22 10:30:32 +00:00
#if defined(__clang__)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "SomeStruct");
2019-03-22 10:30:32 +00:00
REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "SomeStruct *");
2019-07-21 19:13:14 +00:00
REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "SomeStruct");
2019-03-22 10:30:32 +00:00
REQUIRE(nameof::nameof_type<SomeStruct>() == "SomeStruct");
REQUIRE(nameof::nameof_type<SomeStruct *>() == "SomeStruct *");
2019-07-21 19:13:14 +00:00
REQUIRE(nameof::nameof_type<const SomeStruct &>() == "SomeStruct");
2019-03-22 10:30:32 +00:00
REQUIRE(nameof::nameof_type<const SomeStruct volatile *>() == "const volatile SomeStruct *");
REQUIRE(nameof::nameof_type<SomeClass<int>>() == "SomeClass<int>");
REQUIRE(nameof::nameof_type<const SomeClass<int> volatile *>() == "const volatile SomeClass<int> *");
REQUIRE(nameof::nameof_type<decltype(othervar)>() == "Long");
REQUIRE(nameof::nameof_type<Long>() == "Long");
REQUIRE(nameof::nameof_type<Long::LL>() == "Long::LL");
REQUIRE(nameof::nameof_type<Color>() == "Color");
#elif defined(_MSC_VER)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "struct SomeStruct");
2019-04-10 12:23:21 +00:00
REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "struct SomeStruct *");
2019-07-21 19:13:14 +00:00
REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "struct SomeStruct");
2019-04-10 12:23:21 +00:00
REQUIRE(nameof::nameof_type<SomeStruct>() == "struct SomeStruct");
REQUIRE(nameof::nameof_type<SomeStruct *>() == "struct SomeStruct *");
2019-07-21 19:13:14 +00:00
REQUIRE(nameof::nameof_type<const SomeStruct &>() == "struct SomeStruct");
2019-04-10 12:23:21 +00:00
REQUIRE(nameof::nameof_type<const SomeStruct volatile *>() == "struct SomeStruct const volatile *");
REQUIRE(nameof::nameof_type<SomeClass<int>>() == "class SomeClass<int>");
REQUIRE(nameof::nameof_type<const SomeClass<int> volatile *>() == "class SomeClass<int> const volatile *");
REQUIRE(nameof::nameof_type<decltype(othervar)>() == "struct Long");
REQUIRE(nameof::nameof_type<Long>() == "struct Long");
REQUIRE(nameof::nameof_type<Long::LL>() == "struct Long::LL");
REQUIRE(nameof::nameof_type<Color>() == "enum Color");
2019-03-22 10:30:32 +00:00
#elif defined(__GNUC__)
2019-04-10 13:48:14 +00:00
REQUIRE(type_name == "SomeStruct");
2019-03-22 10:30:32 +00:00
REQUIRE(nameof::nameof_type<decltype(ptr_s)>() == "SomeStruct*");
2019-07-21 19:13:14 +00:00
REQUIRE(nameof::nameof_type<decltype(ref_s)>() == "SomeStruct");
2019-03-22 10:30:32 +00:00
REQUIRE(nameof::nameof_type<SomeStruct>() == "SomeStruct");
REQUIRE(nameof::nameof_type<SomeStruct *>() == "SomeStruct*");
2019-07-21 19:13:14 +00:00
REQUIRE(nameof::nameof_type<const SomeStruct &>() == "SomeStruct");
2019-03-22 10:30:32 +00:00
REQUIRE(nameof::nameof_type<const SomeStruct volatile *>() == "const volatile SomeStruct*");
REQUIRE(nameof::nameof_type<SomeClass<int>>() == "SomeClass<int>");
REQUIRE(nameof::nameof_type<const SomeClass<int> volatile *>() == "const volatile SomeClass<int>*");
REQUIRE(nameof::nameof_type<decltype(othervar)>() == "Long");
REQUIRE(nameof::nameof_type<Long>() == "Long");
REQUIRE(nameof::nameof_type<Long::LL>() == "Long::LL");
REQUIRE(nameof::nameof_type<Color>() == "Color");
#endif
}
2019-10-01 13:43:32 +00:00
#endif
2020-06-03 14:33:01 +00:00
#if defined(NAMEOF_TYPE_RTTI_SUPPORTED) && NAMEOF_TYPE_RTTI_SUPPORTED
TEST_CASE("NAMEOF_TYPE_RTTI") {
#if defined(__clang__)
REQUIRE(NAMEOF_TYPE_RTTI(std::string) == "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >");
REQUIRE(NAMEOF_TYPE_RTTI(Color) == "Color");
#elif defined(_MSC_VER)
REQUIRE(NAMEOF_TYPE_RTTI(std::string) == "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
REQUIRE(NAMEOF_TYPE_RTTI(Color) == "enum Color");
#elif defined(__GNUC__)
REQUIRE(NAMEOF_TYPE_RTTI(std::string) == "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >");
REQUIRE(NAMEOF_TYPE_RTTI(Color) == "Color");
#endif
}
#endif