diff options
author | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 19:57:41 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 20:02:19 -0700 |
commit | c3d2579ad8d7eb33059aa8fdbaf5b564411a57f2 (patch) | |
tree | 1570cda0676fdcf4171a69a7fe313c1b89a52b0c /vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp | |
parent | 986b7742bf244b4073ecca0723615f70be8a1ab6 (diff) | |
parent | 4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff) |
Merge branch 'upstream' into debian-cmake-fixes
Diffstat (limited to 'vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp')
-rw-r--r-- | vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp new file mode 100644 index 00000000..c5437f9f --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp @@ -0,0 +1,69 @@ + +// Copyright Joakim Karlsson & Kim Gräsman 2010-2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +struct IsEvenNumberNoStreamOperator +{ + bool Matches(const int actual) const + { + return (actual % 2) == 0; + } +}; + +struct IsEvenNumberWithStreamOperator +{ + bool Matches(const int actual) const + { + return (actual % 2) == 0; + } + + friend std::ostream& operator<<(std::ostream& stm, + const IsEvenNumberWithStreamOperator& ); +}; + +std::ostream& operator<<(std::ostream& stm, + const IsEvenNumberWithStreamOperator& ) +{ + stm << "An even number"; + return stm; +} + +void CustomMatchers() +{ + std::cout << "================================================" << std::endl; + std::cout << " CustomMatchersNoStreamOperator" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "CanHandleCustomMatcher" << std::endl; + { + Assert::That(2, Fulfills(IsEvenNumberNoStreamOperator())); + } + + std::cout << "CustomMatcherWithFluent" << std::endl; + { + Assert::That(2, Is().Fulfilling(IsEvenNumberNoStreamOperator())); + } + + std::cout << "OutputsCorrectMessageWhenFails" << std::endl; + { + AssertTestFails(Assert::That(3, Fulfills(IsEvenNumberNoStreamOperator())), + "Expected: [unsupported type]\nActual: 3"); + } + + + std::cout << "================================================" << std::endl; + std::cout << "CustomMatcherWithStreamOperator" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ErrorMessageUsesCustomStreamOperatorIfAvailable" << std::endl; + { + AssertTestFails(Assert::That(3, Fulfills(IsEvenNumberWithStreamOperator())), + "Expected: An even number\nActual: 3"); + } +} |