Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/projects/SelfTest/UsageTests/Generators.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2019-10-06 13:49:50 +0200
committerMartin Hořeňovský2019-10-06 13:55:10 +0200
commit319cb9e1daec5076ff1a3acd10b959c2bce05c5b (patch)
tree7a9d9bf9e8e257593283692b2fdbbeee454d0fdb /projects/SelfTest/UsageTests/Generators.tests.cpp
parentb8b765d55e552d5892b46ccafd3a40a8ca3b9e0a (diff)
downloadcatch3-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.cpp25
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