diff options
| author | Martin Hořeňovský | 2019-10-09 14:51:24 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2019-10-09 14:51:36 +0200 |
| commit | c8db4e77c4c9aa20776db162e982f1af693ab8fe (patch) | |
| tree | 738b92425aa18c49a4da7d2302dd10d6663b7ad7 /projects/SelfTest/UsageTests | |
| parent | 1c5749669e85239ce3dd3bb80028d9b8d2402787 (diff) | |
| download | catch3-c8db4e77c4c9aa20776db162e982f1af693ab8fe.tar.gz | |
Add a from_range(Container) overload to the generator helpers
Diffstat (limited to 'projects/SelfTest/UsageTests')
| -rw-r--r-- | projects/SelfTest/UsageTests/Generators.tests.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/projects/SelfTest/UsageTests/Generators.tests.cpp b/projects/SelfTest/UsageTests/Generators.tests.cpp index 0d58186b..0e39bd5c 100644 --- a/projects/SelfTest/UsageTests/Generators.tests.cpp +++ b/projects/SelfTest/UsageTests/Generators.tests.cpp @@ -214,9 +214,15 @@ TEST_CASE("Nested generators and captured variables", "[generators]") { } namespace { + size_t call_count = 0; + size_t test_count = 0; std::vector<int> make_data() { return { 1, 3, 5, 7, 9, 11 }; } + std::vector<int> make_data_counted() { + ++call_count; + return make_data(); + } } #if defined(__clang__) @@ -225,13 +231,24 @@ namespace { #endif TEST_CASE("Copy and then generate a range", "[generators]") { - static auto data = make_data(); - - // It is important to notice that a generator is only initialized - // **once** per run. What this means is that modifying data will not - // modify the underlying generator. - auto elem = GENERATE_REF(from_range(data.begin(), data.end())); - REQUIRE(elem % 2 == 1); + SECTION("from var and iterators") { + static auto data = make_data(); + + // It is important to notice that a generator is only initialized + // **once** per run. What this means is that modifying data will not + // modify the underlying generator. + auto elem = GENERATE_REF(from_range(data.begin(), data.end())); + REQUIRE(elem % 2 == 1); + } + SECTION("From a temporary container") { + auto elem = GENERATE(from_range(make_data_counted())); + ++test_count; + REQUIRE(elem % 2 == 1); + } + SECTION("Final validation") { + REQUIRE(call_count == 1); + REQUIRE(make_data().size() == test_count); + } } #if defined(__clang__) |