Matchers.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_TESTING__MATCHERS
18 #define COM_BORA_SOFTWARE__BALAU_TESTING__MATCHERS
19 
20 #include <Balau/Testing/Impl/MatcherClasses.hpp>
21 
22 namespace Balau::Testing {
23 
27 template <typename E>
28 inline ExpectedValue<E, MatcherCompareEquals, EvNotUsed, EvNotUsed> is(const E & expected) {
29  return ExpectedValue<E, MatcherCompareEquals, EvNotUsed, EvNotUsed>(expected);
30 }
31 
35 template <typename E>
36 inline ExpectedValue<E, MatcherCompareNotEqual, EvNotUsed, EvNotUsed> isNot(const E & expected) {
37  return ExpectedValue<E, MatcherCompareNotEqual, EvNotUsed, EvNotUsed>(expected);
38 }
39 
43 inline ExpectedValue<void *, MatcherCompareNotEqual, EvNotUsed, EvNotUsed> isNotNull() {
44  return ExpectedValue<void *, MatcherCompareNotEqual, EvNotUsed, EvNotUsed>(nullptr);
45 }
46 
50 template <typename E>
51 inline ExpectedValue<E, MatcherCompareGreaterThan, EvNotUsed, EvNotUsed> isGreaterThan(const E & expected) {
52  return ExpectedValue<E, MatcherCompareGreaterThan, EvNotUsed, EvNotUsed>(expected);
53 }
54 
58 template <typename E>
59 inline ExpectedValue<E, MatcherCompareGreaterThanOrEqualTo, EvNotUsed, EvNotUsed> isGreaterThanOrEqualTo(const E & expected) {
60  return ExpectedValue<E, MatcherCompareGreaterThanOrEqualTo, EvNotUsed, EvNotUsed>(expected);
61 }
62 
66 template <typename E>
67 inline ExpectedValue<E, MatcherCompareLessThan, EvNotUsed, EvNotUsed> isLessThan(const E & expected) {
68  return ExpectedValue<E, MatcherCompareLessThan, EvNotUsed, EvNotUsed>(expected);
69 }
70 
74 template <typename E>
75 inline ExpectedValue<E, MatcherCompareLessThanOrEqualTo, EvNotUsed, EvNotUsed> isLessThanOrEqualTo(const E & expected) {
76  return ExpectedValue<E, MatcherCompareLessThanOrEqualTo, EvNotUsed, EvNotUsed>(expected);
77 }
78 
82 template <typename E, typename V>
83 inline ExpectedValue<E, MatcherCompareAlmostEqual, V, EvNotUsed> isAlmostEqual(const E & expected, const V & errorDelta) {
84  return ExpectedValue<E, MatcherCompareAlmostEqual, V, EvNotUsed>(expected, errorDelta);
85 }
86 
90 template <typename E>
91 inline ExpectedValue<E, MatcherCompareStartsWith, EvNotUsed, EvNotUsed> startsWith(const E & expected) {
92  return ExpectedValue<E, MatcherCompareStartsWith, EvNotUsed, EvNotUsed>(expected);
93 }
94 
98 template <typename E>
99 inline ExpectedValue<E, MatcherCompareEndsWith, EvNotUsed, EvNotUsed> endsWith(const E & expected) {
100  return ExpectedValue<E, MatcherCompareEndsWith, EvNotUsed, EvNotUsed>(expected);
101 }
102 
106 template <typename E>
107 inline ExpectedValue<E, MatcherCompareContains, EvNotUsed, EvNotUsed> contains(const E & expected) {
108  return ExpectedValue<E, MatcherCompareContains, EvNotUsed, EvNotUsed>(expected);
109 }
110 
114 template <typename E>
115 inline ExpectedValue<E, MatcherCompareDoesNotContain, EvNotUsed, EvNotUsed> doesNotContain(const E & expected) {
116  return ExpectedValue<E, MatcherCompareDoesNotContain, EvNotUsed, EvNotUsed>(expected);
117 }
118 
122 template <typename T> inline const IsAExpectation<T> isA() {
123  return IsAExpectation<T>();
124 }
125 
129 template <typename E> inline const ThrowTypeExpectation<E> throws() {
130  return ThrowTypeExpectation<E>();
131 }
132 
136 template <typename E> inline const ThrowExpectation<E> throws(const E & expected) {
137  return ThrowExpectation<E>(expected);
138 }
139 
145 template <typename E>
146 inline const ThrowExpectationWithPredicate<E> throws(const std::function<bool (const E & )> & predicate) {
147  return ThrowExpectationWithPredicate<E>(predicate);
148 }
149 
155 template <typename E, typename C>
156 inline const ThrowExpectationWithFunction<E, C> throws(const E & expected, C comparisonFunction) {
157  return ThrowExpectationWithFunction<E, C>(expected, comparisonFunction);
158 }
159 
160 } // namespace Balau::Testing
161 
162 #endif // COM_BORA_SOFTWARE__BALAU_TESTING__MATCHERS
ExpectedValue< E, MatcherCompareLessThan, EvNotUsed, EvNotUsed > isLessThan(const E &expected)
Is the actual value less than the supplied expected value?
Definition: Matchers.hpp:67
ExpectedValue< E, MatcherCompareGreaterThanOrEqualTo, EvNotUsed, EvNotUsed > isGreaterThanOrEqualTo(const E &expected)
Is the actual value greater than or equal to the supplied expected value?
Definition: Matchers.hpp:59
ExpectedValue< E, MatcherCompareNotEqual, EvNotUsed, EvNotUsed > isNot(const E &expected)
Is the actual value not equal to the supplied expected value?
Definition: Matchers.hpp:36
ExpectedValue< E, MatcherCompareDoesNotContain, EvNotUsed, EvNotUsed > doesNotContain(const E &expected)
Does the actual value not contain the supplied expected value?
Definition: Matchers.hpp:115
const IsAExpectation< T > isA()
Is the type of the actual value castable to the specified type?
Definition: Matchers.hpp:122
ExpectedValue< E, MatcherCompareAlmostEqual, V, EvNotUsed > isAlmostEqual(const E &expected, const V &errorDelta)
Is the actual value equal to within the specified error limit to the supplied expected value...
Definition: Matchers.hpp:83
ExpectedValue< E, MatcherCompareStartsWith, EvNotUsed, EvNotUsed > startsWith(const E &expected)
Does the actual value start with the supplied expected value?
Definition: Matchers.hpp:91
ExpectedValue< E, MatcherCompareEquals, EvNotUsed, EvNotUsed > is(const E &expected)
Is the actual value equal to the supplied expected value?
Definition: Matchers.hpp:28
The test runner and test assertion functions.
Definition: Assertions.hpp:23
ExpectedValue< E, MatcherCompareGreaterThan, EvNotUsed, EvNotUsed > isGreaterThan(const E &expected)
Is the actual value greater than the supplied expected value?
Definition: Matchers.hpp:51
ExpectedValue< void *, MatcherCompareNotEqual, EvNotUsed, EvNotUsed > isNotNull()
Is the actual value not equal to the supplied expected value?
Definition: Matchers.hpp:43
ExpectedValue< E, MatcherCompareEndsWith, EvNotUsed, EvNotUsed > endsWith(const E &expected)
Does the actual value end with the supplied expected value?
Definition: Matchers.hpp:99
ExpectedValue< E, MatcherCompareContains, EvNotUsed, EvNotUsed > contains(const E &expected)
Does the actual value contains the supplied expected value?
Definition: Matchers.hpp:107
ExpectedValue< E, MatcherCompareLessThanOrEqualTo, EvNotUsed, EvNotUsed > isLessThanOrEqualTo(const E &expected)
Is the actual value less than or equal to the supplied expected value?
Definition: Matchers.hpp:75