From d385b468cb8c39fd1c263fbe38cddca91b791713 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Mon, 11 Mar 2019 12:48:29 +0100 Subject: [PATCH] Add test for support of capturing lambdas in GENERATE() --- .../SelfTest/UsageTests/Generators.tests.cpp | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/projects/SelfTest/UsageTests/Generators.tests.cpp b/projects/SelfTest/UsageTests/Generators.tests.cpp index 0cf1ce6e0f..3642aada13 100644 --- a/projects/SelfTest/UsageTests/Generators.tests.cpp +++ b/projects/SelfTest/UsageTests/Generators.tests.cpp @@ -111,6 +111,51 @@ SCENARIO("Eating cucumbers", "[generators][approvals]") { REQUIRE( eatCucumbers( start, eat ) == left ); } } + +SCENARIO("capturing lambda", "[generators]") { + + class SomeStateMachine { + public: + void doA() { i++; } + void doB() { i += 2; } + bool checkSomeProperty() { return (i & 1); } + + private: + int i{}; + }; + + GIVEN("some instance") { + SomeStateMachine instance; + + auto[seqId, inputSequence, expectedProperty] = + GENERATE(table, bool>({ + { + "AA", + [&]() { + instance.doA(); + instance.doA(); + }, + false + }, + { + "AB", + [&]() { + instance.doA(); + instance.doB(); + }, + true + }, + })); + + WHEN("the input sequence " << seqId << " is applied") { + inputSequence(); + + THEN("the expected property value is met") { + REQUIRE(instance.checkSomeProperty() == expectedProperty); + } + } + } +} #endif // There are also some generic generator manipulators