diff options
| author | Martin Hořeňovský | 2023-08-29 15:37:46 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2023-08-29 15:38:13 +0200 |
| commit | f24d39e42b3b41215c7a9082f45381b32f78edbc (patch) | |
| tree | 4724704ae3bd2d442f413962746cfd4c9fabfb51 /tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp | |
| parent | 85eb4652b46cc69c4ad7915c9fd3b009d99e9fb7 (diff) | |
| download | catch3-f24d39e42b3b41215c7a9082f45381b32f78edbc.tar.gz | |
Support C arrays and ADL ranges in from_range generator
Closes #2737
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp')
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp index f7b7c57c..acfeebed 100644 --- a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -10,6 +10,8 @@ # pragma GCC diagnostic ignored "-Wfloat-equal" #endif +#include <helpers/range_test_helpers.hpp> + #include <catch2/catch_approx.hpp> #include <catch2/catch_test_macros.hpp> #include <catch2/generators/catch_generator_exception.hpp> @@ -545,3 +547,30 @@ TEST_CASE("Filter generator throws exception for empty generator", filter( []( int ) { return false; }, value( 3 ) ), Catch::GeneratorException ); } + +TEST_CASE("from_range(container) supports ADL begin/end and arrays", "[generators][from-range][approvals]") { + using namespace Catch::Generators; + + SECTION("C array") { + int arr[3]{ 5, 6, 7 }; + auto gen = from_range( arr ); + REQUIRE( gen.get() == 5 ); + REQUIRE( gen.next() ); + REQUIRE( gen.get() == 6 ); + REQUIRE( gen.next() ); + REQUIRE( gen.get() == 7 ); + REQUIRE_FALSE( gen.next() ); + } + + SECTION( "ADL range" ) { + unrelated::needs_ADL_begin<int> range{ 1, 2, 3 }; + auto gen = from_range( range ); + REQUIRE( gen.get() == 1 ); + REQUIRE( gen.next() ); + REQUIRE( gen.get() == 2 ); + REQUIRE( gen.next() ); + REQUIRE( gen.get() == 3 ); + REQUIRE_FALSE( gen.next() ); + } + +} |