Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
#include <catch2/catch.hpp>
|
|
#include <tl/expected.hpp>
|
|
|
|
struct move_detector {
|
|
move_detector() = default;
|
|
move_detector(move_detector &&rhs) { rhs.been_moved = true; }
|
|
bool been_moved = false;
|
|
};
|
|
|
|
TEST_CASE("Observers", "[observers]") {
|
|
tl::expected<int,int> o1 = 42;
|
|
tl::expected<int,int> o2 {tl::unexpect, 0};
|
|
const tl::expected<int,int> o3 = 42;
|
|
|
|
REQUIRE(*o1 == 42);
|
|
REQUIRE(*o1 == o1.value());
|
|
REQUIRE(o2.value_or(42) == 42);
|
|
REQUIRE(o2.error() == 0);
|
|
REQUIRE(o3.value() == 42);
|
|
auto success = std::is_same<decltype(o1.value()), int &>::value;
|
|
REQUIRE(success);
|
|
success = std::is_same<decltype(o3.value()), const int &>::value;
|
|
REQUIRE(success);
|
|
success = std::is_same<decltype(std::move(o1).value()), int &&>::value;
|
|
REQUIRE(success);
|
|
|
|
#ifndef TL_EXPECTED_NO_CONSTRR
|
|
success = std::is_same<decltype(std::move(o3).value()), const int &&>::value;
|
|
REQUIRE(success);
|
|
#endif
|
|
|
|
tl::expected<move_detector,int> o4{tl::in_place};
|
|
move_detector o5 = std::move(o4).value();
|
|
REQUIRE(o4->been_moved);
|
|
REQUIRE(!o5.been_moved);
|
|
}
|