2019-10-25 06:44:01 -07:00
|
|
|
#include <catch2/catch.hpp>
|
2019-05-01 12:15:40 +01:00
|
|
|
#include <tl/expected.hpp>
|
2017-11-27 14:48:16 +00:00
|
|
|
|
2017-12-05 20:47:14 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2017-11-27 15:08:14 +00:00
|
|
|
// Old versions of GCC don't have the correct trait names. Could fix them up if needs be.
|
|
|
|
|
#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 && \
|
|
|
|
|
!defined(__clang__))
|
|
|
|
|
// nothing for now
|
|
|
|
|
#else
|
2017-11-27 14:48:16 +00:00
|
|
|
TEST_CASE("Triviality", "[bases.triviality]") {
|
|
|
|
|
REQUIRE(std::is_trivially_copy_constructible<tl::expected<int,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_copy_assignable<tl::expected<int,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_move_constructible<tl::expected<int,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_move_assignable<tl::expected<int,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_destructible<tl::expected<int,int>>::value);
|
|
|
|
|
|
2017-12-23 15:13:38 +00:00
|
|
|
REQUIRE(std::is_trivially_copy_constructible<tl::expected<void,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_move_constructible<tl::expected<void,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_destructible<tl::expected<void,int>>::value);
|
|
|
|
|
|
|
|
|
|
|
2017-11-27 14:48:16 +00:00
|
|
|
{
|
|
|
|
|
struct T {
|
|
|
|
|
T(const T&) = default;
|
|
|
|
|
T(T&&) = default;
|
|
|
|
|
T& operator=(const T&) = default;
|
|
|
|
|
T& operator=(T&&) = default;
|
|
|
|
|
~T() = default;
|
|
|
|
|
};
|
|
|
|
|
REQUIRE(std::is_trivially_copy_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_copy_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_move_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_move_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_destructible<tl::expected<T,int>>::value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct T {
|
|
|
|
|
T(const T&){}
|
|
|
|
|
T(T&&) {};
|
|
|
|
|
T& operator=(const T&) {}
|
|
|
|
|
T& operator=(T&&) {};
|
|
|
|
|
~T(){}
|
|
|
|
|
};
|
|
|
|
|
REQUIRE(!std::is_trivially_copy_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(!std::is_trivially_copy_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(!std::is_trivially_move_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(!std::is_trivially_move_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(!std::is_trivially_destructible<tl::expected<T,int>>::value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("Deletion", "[bases.deletion]") {
|
|
|
|
|
REQUIRE(std::is_copy_constructible<tl::expected<int,int>>::value);
|
|
|
|
|
REQUIRE(std::is_copy_assignable<tl::expected<int,int>>::value);
|
|
|
|
|
REQUIRE(std::is_move_constructible<tl::expected<int,int>>::value);
|
|
|
|
|
REQUIRE(std::is_move_assignable<tl::expected<int,int>>::value);
|
|
|
|
|
REQUIRE(std::is_destructible<tl::expected<int,int>>::value);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct T {
|
|
|
|
|
T()=default;
|
|
|
|
|
};
|
|
|
|
|
REQUIRE(std::is_default_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct T {
|
2018-08-22 14:02:43 +01:00
|
|
|
T(int){}
|
2017-11-27 14:48:16 +00:00
|
|
|
};
|
|
|
|
|
REQUIRE(!std::is_default_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct T {
|
|
|
|
|
T(const T&) = default;
|
|
|
|
|
T(T&&) = default;
|
|
|
|
|
T& operator=(const T&) = default;
|
|
|
|
|
T& operator=(T&&) = default;
|
|
|
|
|
~T() = default;
|
|
|
|
|
};
|
|
|
|
|
REQUIRE(std::is_copy_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_copy_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_move_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_move_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_destructible<tl::expected<T,int>>::value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct T {
|
|
|
|
|
T(const T&)=delete;
|
|
|
|
|
T(T&&)=delete;
|
|
|
|
|
T& operator=(const T&)=delete;
|
|
|
|
|
T& operator=(T&&)=delete;
|
|
|
|
|
};
|
|
|
|
|
REQUIRE(!std::is_copy_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(!std::is_copy_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(!std::is_move_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(!std::is_move_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct T {
|
|
|
|
|
T(const T&)=delete;
|
|
|
|
|
T(T&&)=default;
|
|
|
|
|
T& operator=(const T&)=delete;
|
|
|
|
|
T& operator=(T&&)=default;
|
|
|
|
|
};
|
|
|
|
|
REQUIRE(!std::is_copy_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(!std::is_copy_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_move_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_move_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
struct T {
|
|
|
|
|
T(const T&)=default;
|
|
|
|
|
T(T&&)=delete;
|
|
|
|
|
T& operator=(const T&)=default;
|
|
|
|
|
T& operator=(T&&)=delete;
|
|
|
|
|
};
|
|
|
|
|
REQUIRE(std::is_copy_constructible<tl::expected<T,int>>::value);
|
|
|
|
|
REQUIRE(std::is_copy_assignable<tl::expected<T,int>>::value);
|
|
|
|
|
}
|
2017-12-05 20:47:14 +00:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tl::expected<int, int> e;
|
|
|
|
|
REQUIRE(std::is_default_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_copy_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_move_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_move_assignable<decltype(e)>::value);
|
2018-01-14 07:37:23 +00:00
|
|
|
REQUIRE(TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
|
|
|
|
|
REQUIRE(TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
|
2017-12-05 20:47:14 +00:00
|
|
|
# if !defined(TL_EXPECTED_GCC49)
|
|
|
|
|
REQUIRE(std::is_trivially_move_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_trivially_move_assignable<decltype(e)>::value);
|
|
|
|
|
# endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tl::expected<int, std::string> e;
|
|
|
|
|
REQUIRE(std::is_default_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_copy_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_move_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_move_assignable<decltype(e)>::value);
|
2018-01-14 07:37:23 +00:00
|
|
|
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
|
|
|
|
|
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
|
2017-12-05 20:47:14 +00:00
|
|
|
# if !defined(TL_EXPECTED_GCC49)
|
|
|
|
|
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
|
|
|
|
|
# endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tl::expected<std::string, int> e;
|
|
|
|
|
REQUIRE(std::is_default_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_copy_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_move_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_move_assignable<decltype(e)>::value);
|
2018-01-14 07:37:23 +00:00
|
|
|
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
|
|
|
|
|
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
|
2017-12-05 20:47:14 +00:00
|
|
|
# if !defined(TL_EXPECTED_GCC49)
|
|
|
|
|
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
|
|
|
|
|
# endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
tl::expected<std::string, std::string> e;
|
|
|
|
|
REQUIRE(std::is_default_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_copy_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_move_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_copy_assignable<decltype(e)>::value);
|
|
|
|
|
REQUIRE(std::is_move_assignable<decltype(e)>::value);
|
2018-01-14 07:37:23 +00:00
|
|
|
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_CONSTRUCTIBLE(decltype(e))::value);
|
|
|
|
|
REQUIRE(!TL_EXPECTED_IS_TRIVIALLY_COPY_ASSIGNABLE(decltype(e))::value);
|
2017-12-05 20:47:14 +00:00
|
|
|
# if !defined(TL_EXPECTED_GCC49)
|
|
|
|
|
REQUIRE(!std::is_trivially_move_constructible<decltype(e)>::value);
|
|
|
|
|
REQUIRE(!std::is_trivially_move_assignable<decltype(e)>::value);
|
|
|
|
|
# endif
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 14:48:16 +00:00
|
|
|
}
|
2017-11-27 15:08:14 +00:00
|
|
|
|
2017-12-05 20:47:14 +00:00
|
|
|
|
2017-11-27 15:08:14 +00:00
|
|
|
#endif
|