diff --git a/include/asyncpp/stream.hpp b/include/asyncpp/stream.hpp index 7f6daa1..5c80b16 100644 --- a/include/asyncpp/stream.hpp +++ b/include/asyncpp/stream.hpp @@ -47,7 +47,7 @@ namespace impl_stream { const T& operator*() const noexcept { assert(m_result); - return m_result.get(); + return m_result.value(); } const std::remove_reference_t* operator->() const noexcept { diff --git a/test/test_stream.cpp b/test/test_stream.cpp index 3d13713..2b146c4 100644 --- a/test/test_stream.cpp +++ b/test/test_stream.cpp @@ -85,7 +85,7 @@ TEST_CASE("Stream: data types", "[Stream]") { } -TEST_CASE("Stream: destroy", "[Task]") { +TEST_CASE("Stream: destroy", "[Stream]") { static const auto coro = []() -> stream { co_yield 0; }; SECTION("no execution") { @@ -112,7 +112,7 @@ struct allocator_object { }; -TEST_CASE("Task: allocator erased", "[Task]") { +TEST_CASE("Stream: allocator erased", "[Stream]") { monitor_allocator<> alloc; using stream_t = stream&>; @@ -132,7 +132,7 @@ TEST_CASE("Task: allocator erased", "[Task]") { } -TEST_CASE("Task: allocator explicit", "[Task]") { +TEST_CASE("Stream: allocator explicit", "[Stream]") { monitor_allocator<> alloc; using stream_t = stream&, monitor_allocator<>>; @@ -149,4 +149,46 @@ TEST_CASE("Task: allocator explicit", "[Task]") { REQUIRE(alloc.get_num_allocations() == 1); REQUIRE(alloc.get_num_live_objects() == 0); } +} + + +TEST_CASE("Stream: item operator bool", "[Stream]") { + SECTION("empty") { + impl_stream::item item(std::nullopt); + REQUIRE(!item); + } + SECTION("valid") { + impl_stream::item item(1); + REQUIRE(!!item); + } +} + + +TEST_CASE("Stream: item deref", "[Stream]") { + impl_stream::item item(1); + REQUIRE(*item == 1); +} + + +TEST_CASE("Stream: item arrow", "[Stream]") { + struct data { + int value = 0; + }; + impl_stream::item item(data{ 1 }); + REQUIRE(item->value == 1); +} + + +TEST_CASE("Stream: item const deref", "[Stream]") { + const impl_stream::item item(1); + REQUIRE(*item == 1); +} + + +TEST_CASE("Stream: item const arrow", "[Stream]") { + struct data { + int value = 0; + }; + const impl_stream::item item(data{ 1 }); + REQUIRE(item->value == 1); } \ No newline at end of file