mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 05:16:10 +01:00
parent
85eb4652b4
commit
f24d39e42b
@ -96,10 +96,11 @@ GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) {
|
||||
return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(from, to));
|
||||
}
|
||||
|
||||
template <typename Container,
|
||||
typename ResultType = typename Container::value_type>
|
||||
GeneratorWrapper<ResultType> from_range(Container const& cnt) {
|
||||
return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end()));
|
||||
template <typename Container>
|
||||
auto from_range(Container const& cnt) {
|
||||
using std::begin;
|
||||
using std::end;
|
||||
return from_range( begin( cnt ), end( cnt ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -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() );
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user