This C++ unit test validates the jau::has_toString and other type traints queries.
This C++ unit test validates the jau::has_toString and other type traints queries
#include <cassert>
#include <cinttypes>
#include <cstring>
#include <iostream>
static constexpr bool v =
true;
};
#if 0
TYPEDEF_CHECKER(has_type, type);
TYPEDEF_CHECKER_ANY(any_type, type);
TYPEDEF_CHECKER_STRICT(exact_type, type);
MVALUE_CHECKER(true_v, v, true);
MVALUE_CHECKER(true_z, z, true);
MVALUE_CHECKER(false_v, v, false);
MVALUE_CHECKER(one_v, v, 1);
MVALUE_CHECKER_STRICT(exact_v, v, 1);
#endif
#define CHECK_2(name, desc, ...) std::cout << std::endl; \
std::cout << "One " << (name<One, ##__VA_ARGS__>() ? "has " : "does not have ") << desc << std::endl; \
std::cout << "Two " << (name<Two, ##__VA_ARGS__>() ? "has " : "does not have ") << desc << std::endl; \
std::cout << "Not " << (name<Not, ##__VA_ARGS__>() ? "has " : "does not have ") << desc << std::endl; \
std::cout << "int " << (name<int, ##__VA_ARGS__>() ? "has " : "does not have ") << desc << std::endl
std::string sep = std::string(60, '-');
#if 0
std::cout << sep;
CHECK_2(has_type,
"typedef type convertible to long",
long);
CHECK_2(exact_type,
"typedef type = int",
int);
CHECK_2(exact_type,
"typedef type = long",
long);
std::cout << sep;
CHECK_2(true_v,
"var v with value equal to true");
CHECK_2(true_z,
"var z with value equal to true");
CHECK_2(false_v,
"var v with value equal to false");
CHECK_2(one_v,
"var v with value equal to 1");
CHECK_2(exact_v,
"var v with value equal to 1 of type int");
#endif
std::cout << sep;
CHECK_2(has_x,
"var x of type convertible to long",
long);
CHECK_2(exact_x,
"var x of type int",
int);
CHECK_2(exact_x,
"var x of type long",
long);
std::cout << sep;
CHECK_2(has_get,
"get() with return type covertible to long");
CHECK_2(has_add,
"add() accepting two ints and returning ~ long");
}
#define METHOD_CHECKER_STRICT_RET(name, fn, ret, args)
Checker for member function with exact retutn type and accepting given arguments.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
type add(type x_, type y_)
#define CHECK_2(name, desc,...)
MTYPE_CHECKER_ANY(any_x, x)
TEST_CASE("01 Type Traits Queries")
METHOD_CHECKER_ANY(any_get, get,())
MTYPE_CHECKER_STRICT(exact_x, x)
METHOD_CHECKER(has_get, get, long,())