mirror of
https://github.com/TartanLlama/optional.git
synced 2025-07-31 18:34:26 +02:00
More testing
This commit is contained in:
121
tests/bases.cpp
Normal file
121
tests/bases.cpp
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
#include "catch.hpp"
|
||||||
|
#include "optional.hpp"
|
||||||
|
|
||||||
|
TEST_CASE("Triviality", "[bases.triviality]") {
|
||||||
|
REQUIRE(std::is_trivially_copy_constructible<tl::optional<int>>::value);
|
||||||
|
REQUIRE(std::is_trivially_copy_assignable<tl::optional<int>>::value);
|
||||||
|
REQUIRE(std::is_trivially_move_constructible<tl::optional<int>>::value);
|
||||||
|
REQUIRE(std::is_trivially_move_assignable<tl::optional<int>>::value);
|
||||||
|
REQUIRE(std::is_trivially_destructible<tl::optional<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_trivially_copy_constructible<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_trivially_copy_assignable<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_trivially_move_constructible<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_trivially_move_assignable<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_trivially_destructible<tl::optional<T>>::value);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
struct T {
|
||||||
|
T(const T&){}
|
||||||
|
T(T&&) {};
|
||||||
|
T& operator=(const T&) {}
|
||||||
|
T& operator=(T&&) {};
|
||||||
|
~T(){}
|
||||||
|
};
|
||||||
|
REQUIRE(!std::is_trivially_copy_constructible<tl::optional<T>>::value);
|
||||||
|
REQUIRE(!std::is_trivially_copy_assignable<tl::optional<T>>::value);
|
||||||
|
REQUIRE(!std::is_trivially_move_constructible<tl::optional<T>>::value);
|
||||||
|
REQUIRE(!std::is_trivially_move_assignable<tl::optional<T>>::value);
|
||||||
|
REQUIRE(!std::is_trivially_destructible<tl::optional<T>>::value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Deletion", "[bases.deletion]") {
|
||||||
|
REQUIRE(std::is_copy_constructible<tl::optional<int>>::value);
|
||||||
|
REQUIRE(std::is_copy_assignable<tl::optional<int>>::value);
|
||||||
|
REQUIRE(std::is_move_constructible<tl::optional<int>>::value);
|
||||||
|
REQUIRE(std::is_move_assignable<tl::optional<int>>::value);
|
||||||
|
REQUIRE(std::is_destructible<tl::optional<int>>::value);
|
||||||
|
|
||||||
|
//TODO fix
|
||||||
|
/* {
|
||||||
|
struct T {
|
||||||
|
T()=default;
|
||||||
|
};
|
||||||
|
REQUIRE(std::is_default_constructible<tl::optional<T>>::value);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
struct T {
|
||||||
|
T(int);
|
||||||
|
};
|
||||||
|
REQUIRE(!std::is_default_constructible<tl::optional<T>>::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::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_copy_assignable<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_move_constructible<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_move_assignable<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_destructible<tl::optional<T>>::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::optional<T>>::value);
|
||||||
|
REQUIRE(!std::is_copy_assignable<tl::optional<T>>::value);
|
||||||
|
REQUIRE(!std::is_move_constructible<tl::optional<T>>::value);
|
||||||
|
REQUIRE(!std::is_move_assignable<tl::optional<T>>::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::optional<T>>::value);
|
||||||
|
REQUIRE(!std::is_copy_assignable<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_move_constructible<tl::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_move_assignable<tl::optional<T>>::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::optional<T>>::value);
|
||||||
|
REQUIRE(std::is_copy_assignable<tl::optional<T>>::value);
|
||||||
|
//TODO see why this fails
|
||||||
|
//REQUIRE(!std::is_move_constructible<tl::optional<T>>::value);
|
||||||
|
//REQUIRE(!std::is_move_assignable<tl::optional<T>>::value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user