diff options
| author | Martin Hořeňovský | 2019-10-06 13:49:50 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2019-10-06 13:55:10 +0200 |
| commit | 319cb9e1daec5076ff1a3acd10b959c2bce05c5b (patch) | |
| tree | 7a9d9bf9e8e257593283692b2fdbbeee454d0fdb /projects/SelfTest/UsageTests/Generators.tests.cpp | |
| parent | b8b765d55e552d5892b46ccafd3a40a8ca3b9e0a (diff) | |
| download | catch3-319cb9e1daec5076ff1a3acd10b959c2bce05c5b.tar.gz | |
Add a generator that takes an iterator pair
Diffstat (limited to 'projects/SelfTest/UsageTests/Generators.tests.cpp')
| -rw-r--r-- | projects/SelfTest/UsageTests/Generators.tests.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/projects/SelfTest/UsageTests/Generators.tests.cpp b/projects/SelfTest/UsageTests/Generators.tests.cpp index e9b2f807..0d58186b 100644 --- a/projects/SelfTest/UsageTests/Generators.tests.cpp +++ b/projects/SelfTest/UsageTests/Generators.tests.cpp @@ -212,3 +212,28 @@ TEST_CASE("Nested generators and captured variables", "[generators]") { auto values = GENERATE_COPY(range(from, to)); REQUIRE(values > -6); } + +namespace { + std::vector<int> make_data() { + return { 1, 3, 5, 7, 9, 11 }; + } +} + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wexit-time-destructors" +#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); +} + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif |