Skip to content

Commit

Permalink
Add test for support of capturing lambdas in GENERATE()
Browse files Browse the repository at this point in the history
  • Loading branch information
alibabashack committed Mar 11, 2019
1 parent ed48d5e commit d385b46
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions projects/SelfTest/UsageTests/Generators.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::function<void()>, 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
Expand Down

0 comments on commit d385b46

Please sign in to comment.