Add Concat generator for combining multiple generators

This commit is contained in:
Martin Hořeňovský
2026-01-12 14:27:49 +01:00
parent 6aedc79870
commit 44c597f074
21 changed files with 1020 additions and 20 deletions
@@ -85,7 +85,7 @@ TEST_CASE("Generators internals", "[generators][internals]") {
filter([](int) { return false; }, values({ 1, 2, 3 })),
Catch::GeneratorException);
}
// Non-trivial usage
SECTION("Out-of-line predicates are copied into the generator") {
auto evilNumber = Catch::Detail::make_unique<int>(2);
@@ -586,3 +586,21 @@ TEST_CASE("from_range(container) supports ADL begin/end and arrays", "[generator
}
}
TEST_CASE( "ConcatGenerator", "[generators][concat]" ) {
using namespace Catch::Generators;
SECTION( "Cat support single-generator construction" ) {
ConcatGenerator<int> c( value( 1 ) );
REQUIRE( c.get() == 1 );
REQUIRE_FALSE( c.next() );
}
SECTION( "Iterating over multiple generators" ) {
ConcatGenerator<int> c( value( 1 ), values( { 2, 3, 4 } ), value( 5 ) );
for ( int i = 0; i < 4; ++i ) {
REQUIRE( c.get() == i + 1 );
REQUIRE( c.next() );
}
REQUIRE( c.get() == 5 );
REQUIRE_FALSE( c.next() );
}
}