Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #18

Merged
merged 1 commit into from
Mar 14, 2024
Merged

fix #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/asyncpp/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>* operator->() const noexcept {
Expand Down
48 changes: 45 additions & 3 deletions test/test_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> { co_yield 0; };

SECTION("no execution") {
Expand All @@ -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<monitor_allocator<>&>;

Expand All @@ -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<>&, monitor_allocator<>>;

Expand All @@ -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<int> item(std::nullopt);
REQUIRE(!item);
}
SECTION("valid") {
impl_stream::item<int> item(1);
REQUIRE(!!item);
}
}


TEST_CASE("Stream: item deref", "[Stream]") {
impl_stream::item<int> item(1);
REQUIRE(*item == 1);
}


TEST_CASE("Stream: item arrow", "[Stream]") {
struct data {
int value = 0;
};
impl_stream::item<data> item(data{ 1 });
REQUIRE(item->value == 1);
}


TEST_CASE("Stream: item const deref", "[Stream]") {
const impl_stream::item<int> item(1);
REQUIRE(*item == 1);
}


TEST_CASE("Stream: item const arrow", "[Stream]") {
struct data {
int value = 0;
};
const impl_stream::item<data> item(data{ 1 });
REQUIRE(item->value == 1);
}
Loading