diff options
Diffstat (limited to 'tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp')
-rw-r--r-- | tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp index 1c203b6b..acfeebed 100644 --- a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -10,12 +10,15 @@ # 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> #include <catch2/generators/catch_generators_adapters.hpp> #include <catch2/generators/catch_generators_random.hpp> #include <catch2/generators/catch_generators_range.hpp> +#include <catch2/generators/catch_generator_exception.hpp> // Tests of generator implementation details TEST_CASE("Generators internals", "[generators][internals]") { @@ -411,6 +414,7 @@ TEST_CASE("GENERATE handles function (pointers)", "[generators][compilation][app TEST_CASE("GENERATE decays arrays", "[generators][compilation][approvals]") { auto str = GENERATE("abc", "def", "gh"); + (void)str; STATIC_REQUIRE(std::is_same<decltype(str), const char*>::value); } @@ -534,3 +538,39 @@ TEST_CASE( "Random generators can be seeded", "[generators][approvals]" ) { } } } + +TEST_CASE("Filter generator throws exception for empty generator", + "[generators]") { + using namespace Catch::Generators; + + REQUIRE_THROWS_AS( + 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() ); + } + +} |