1
0
Fork 0
mirror of https://gitlab.com/niansa/libcrosscoro.git synced 2025-03-06 20:53:32 +01:00
libcrosscoro/test/test_generator.cpp
Josh Baldwin 303cc3384c
Issue 5/clang format (#6)
* clang-format all existing files

* Add detailed comments for event
2020-10-14 08:53:00 -06:00

40 lines
722 B
C++

#include "catch.hpp"
#include <coro/coro.hpp>
TEST_CASE("generator single yield")
{
std::string msg{"Hello World Generator!"};
auto func = [&]() -> coro::generator<std::string> { co_yield msg; };
for (const auto& v : func())
{
REQUIRE(v == msg);
}
}
TEST_CASE("generator infinite incrementing integer yield")
{
constexpr const int64_t max = 1024;
auto func = []() -> coro::generator<int64_t> {
int64_t i{0};
while (true)
{
++i;
co_yield i;
}
};
int64_t v{1};
for (const auto& v_1 : func())
{
REQUIRE(v == v_1);
++v;
if (v > max)
{
break;
}
}
}