mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 17:26:47 +08:00
Add a unit test which was removed in the original version
* Because unfinished traversals weren't allowed there.
This commit is contained in:
parent
36bd134120
commit
fbd87787aa
@ -123,6 +123,36 @@ struct async_increasing_int_visitor
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t ArgCount>
|
||||
struct async_increasing_int_interrupted_visitor
|
||||
: async_counter_base<async_increasing_int_interrupted_visitor<ArgCount>> {
|
||||
|
||||
bool operator()(async_traverse_visit_tag, std::size_t i) {
|
||||
EXPECT_EQ(i, this->counter());
|
||||
++this->counter();
|
||||
|
||||
// Detach the control flow at the second step
|
||||
return i == 0;
|
||||
}
|
||||
|
||||
template <typename N>
|
||||
void operator()(async_traverse_detach_tag, std::size_t i, N&& next) {
|
||||
EXPECT_EQ(i, 1U);
|
||||
EXPECT_EQ(this->counter(), 2U);
|
||||
|
||||
// Don't call next here
|
||||
unused(next);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator()(async_traverse_complete_tag, T&& pack) const {
|
||||
unused(pack);
|
||||
|
||||
// Will never be called
|
||||
FAIL();
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t ArgCount, typename... Args>
|
||||
void test_async_traversal_base(Args&&... args) {
|
||||
// Test that every element is traversed in the correct order
|
||||
@ -140,6 +170,14 @@ void test_async_traversal_base(Args&&... args) {
|
||||
traverse_pack_async(async_increasing_int_visitor<ArgCount>{}, args...);
|
||||
EXPECT_EQ(result->counter(), ArgCount + 1U);
|
||||
}
|
||||
|
||||
// Test that the first element is traversed only,
|
||||
// if we don't call the resume continuation.
|
||||
{
|
||||
auto result = traverse_pack_async(
|
||||
async_increasing_int_interrupted_visitor<ArgCount>{}, args...);
|
||||
EXPECT_EQ(result->counter(), 2U);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(async_traversal, base) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user