You can add your own constraints to Igloo to create more expressive specifications.
Fulfills Constraints
By defining the following matcher
struct IsEvenNumber
{
bool Matches(const int actual) const
{
return (actual % 2) == 0;
}
friend std::ostream& operator<<(std::ostream& stm, const IsEvenNumber& );
};
std::ostream& operator<<(std::ostream& stm, const IsEvenNumber& )
{
stm << "An even number";
return stm;
}
You can create the following constraints in Igloo:
Composite syntax: Assert::That(42, Fulfills(IsEvenNumber()));
Fluent syntax: Assert::That(42, Is().Fulfilling(IsEvenNumber()));
Your custom matcher should implement a method called Matches() that takes a parameter of the type you expect and returns true if the passed parameter fulfills the constraint.
To get more expressive failure messages, you should also implement the streaming operator as in the example above.
No comments