Skip to content

Commit

Permalink
Add bdd test example
Browse files Browse the repository at this point in the history
  • Loading branch information
daixtrose committed Oct 16, 2024
1 parent 3ceb45e commit a661554
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions polymorphism/test/test_consume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
#include <polymorphism/impl_with_interface.hpp>
#include <polymorphism/impl_without_interface.hpp>

// ctest --rerun-failed --output-on-failure

int main()
{
using namespace boost::ut;
using namespace boost::ut::bdd;
using namespace std::string_literals;

"classic interface call yields 42"_test = [] {
Expand All @@ -24,4 +23,24 @@ int main()
expect("The answer to all questions is 42"s == modern::consume(i));
expect("42"s == i.coolFeature());
};

"[modern]"_test
= [] {
given("I have a an implementation that adheres to a concept") = [] {
modern::Impl impl;
expect("<default value>"s == impl.coolFeature());

when("I pass it to a function that expects an argument that fulfils the constraints") = [&] {
auto result = modern::consume(impl);

then("the answer to all questions should be given") = [=] {
expect("The answer to all questions is 42"s == result);
};

then("the state of the argument should be modified as a side effect") = [=] {
expect("42"s == impl.coolFeature());
};
};
};
};
}

0 comments on commit a661554

Please sign in to comment.