blob: a47f6bf4fe837cb60cd537d960423302b8b1bbef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// Copyright Joakim Karlsson & Kim Gräsman 2010-2012.
// 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)
#ifndef IGLOO_EQUALSCONSTRAINT_H
#define IGLOO_EQUALSCONSTRAINT_H
#include <cstddef>
#include "./expressions/expression.h"
namespace snowhouse {
template< typename ExpectedType >
struct EqualsConstraint : Expression< EqualsConstraint<ExpectedType> >
{
EqualsConstraint(const ExpectedType& expected)
: m_expected(expected)
{
}
template<typename ActualType>
bool operator()(const ActualType& actual) const
{
return (m_expected == actual);
}
ExpectedType m_expected;
};
template< typename ExpectedType >
inline EqualsConstraint<ExpectedType> Equals(const ExpectedType& expected)
{
return EqualsConstraint<ExpectedType>(expected);
}
inline EqualsConstraint<std::string> Equals(const char* expected)
{
return EqualsConstraint<std::string>(expected);
}
inline EqualsConstraint<bool> IsFalse()
{
return EqualsConstraint<bool>(false);
}
inline EqualsConstraint<bool> IsTrue()
{
return EqualsConstraint<bool>(true);
}
#if __cplusplus > 199711L
inline EqualsConstraint<std::nullptr_t> IsNull()
{
return EqualsConstraint<std::nullptr_t>(nullptr);
}
#endif
template <>
struct Stringizer< EqualsConstraint< bool > >
{
static std::string ToString(const EqualsConstraint<bool>& constraint)
{
return constraint.m_expected ? "true" : "false";
}
};
template< typename ExpectedType >
struct Stringizer< EqualsConstraint< ExpectedType > >
{
static std::string ToString(const EqualsConstraint<ExpectedType>& constraint)
{
std::ostringstream builder;
builder << "equal to " << snowhouse::Stringize(constraint.m_expected);
return builder.str();
}
};
}
#endif
|