diff options
Diffstat (limited to 'vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent')
16 files changed, 1109 insertions, 0 deletions
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/constraintadapter.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/constraintadapter.h new file mode 100644 index 00000000..b1719288 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/constraintadapter.h @@ -0,0 +1,39 @@ + +// 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_CONSTRAINTADAPTER_H +#define IGLOO_CONSTRAINTADAPTER_H + +namespace snowhouse { + + template <typename ConstraintType> + struct ConstraintAdapter + { + ConstraintAdapter(const ConstraintType& constraint) : m_constraint(constraint) + { + } + + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + result.push(m_constraint(actual)); + EvaluateConstraintList(list.m_tail, result, operators, actual); + } + + ConstraintType m_constraint; + }; + + template<typename ConstraintType> + struct Stringizer< ConstraintAdapter<ConstraintType> > + { + static std::string ToString(const ConstraintAdapter<ConstraintType>& constraintAdapter) + { + return snowhouse::Stringize(constraintAdapter.m_constraint); + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/constraintlist.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/constraintlist.h new file mode 100644 index 00000000..1a62a60e --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/constraintlist.h @@ -0,0 +1,91 @@ + +// 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_CONSTRAINT_H +#define IGLOO_CONSTRAINT_H + +namespace snowhouse { + + struct ConstraintOperator; + typedef std::stack<bool> ResultStack; + typedef std::stack<ConstraintOperator*> OperatorStack; + + template <typename HT, typename TT> + struct ConstraintList + { + typedef HT HeadType; + typedef TT TailType; + + ConstraintList(const HeadType& head, const TailType& tail) + : m_head(head), m_tail(tail) + { + } + + HeadType m_head; + TailType m_tail; + }; + + struct Nil + { + Nil() {} + Nil(const Nil&) {} + }; + + + // ---- These structs defines the resulting types of list concatenation operations + template <typename L1, typename L2> + struct type_concat + { + typedef ConstraintList<typename L1::HeadType, typename type_concat<typename L1::TailType, L2>::t> t; + }; + + template <typename L2> struct type_concat<Nil, L2> { typedef L2 t; }; + + template <typename L3> inline L3 tr_concat(const Nil&, const Nil&) { return Nil(); } + + + // ---- These structs define the concatenation operations. + + template <typename LeftList, typename RightList, typename ResultList> + struct ListConcat + { + static ResultList Concatenate(const LeftList& left, const RightList& right) + { + return ResultList(left.m_head, ListConcat<typename LeftList::TailType, RightList, typename type_concat< typename LeftList::TailType, RightList>::t>::Concatenate(left.m_tail, right)); + } + }; + + // Concatenating an empty list with a second list yields the second list + template <typename RightList, typename ResultList> + struct ListConcat<Nil, RightList, ResultList> + { + static ResultList Concatenate(const Nil&, const RightList& right) + { + return right; + } + + }; + + // Concatenating two empty lists yields an empty list + template <typename ResultList> + struct ListConcat<Nil, Nil, ResultList> + { + static ResultList Concatenate(const Nil&, const Nil&) + { + return Nil(); + } + }; + + // ---- The concatenation operation + + template <typename L1, typename L2> + inline typename type_concat<L1, L2>::t Concatenate(const L1& list1, const L2& list2) + { + return ListConcat<L1, L2, typename type_concat<L1, L2>::t>::Concatenate(list1, list2); + } +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/expressionbuilder.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/expressionbuilder.h new file mode 100644 index 00000000..f0889f1d --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/expressionbuilder.h @@ -0,0 +1,357 @@ + +// 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_EXPRESSIONBUILDER_H +#define IGLOO_EXPRESSIONBUILDER_H + +#include <cstddef> + +namespace snowhouse { + + // ---- Evaluation of list of constraints + + template <typename ConstraintListType, typename ActualType> + inline void EvaluateConstraintList(ConstraintListType& constraint_list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + constraint_list.m_head.Evaluate(constraint_list, result, operators, actual); + } + + template <typename ActualType> + inline void EvaluateConstraintList(Nil&, ResultStack&, OperatorStack&, const ActualType&) {} + + + template <typename ConstraintListType> + struct ExpressionBuilder + { + ExpressionBuilder(const ConstraintListType& list) : m_constraint_list(list) + { + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EqualsConstraint<ExpectedType> >, Nil> >::t> + EqualTo(const ExpectedType& expected) + { + typedef ConstraintAdapter<EqualsConstraint<ExpectedType> > ConstraintAdapterType; + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename ExpectedType, typename DeltaType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EqualsWithDeltaConstraint<ExpectedType, DeltaType> >, Nil> >::t> + EqualToWithDelta(const ExpectedType& expected, const DeltaType& delta) + { + typedef ConstraintAdapter<EqualsWithDeltaConstraint<ExpectedType, DeltaType> > ConstraintAdapterType; + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + + ConstraintAdapterType constraint(EqualsWithDeltaConstraint<ExpectedType, DeltaType>(expected, delta)); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename MatcherType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<FulfillsConstraint<MatcherType> >, Nil> >::t> + Fulfilling(const MatcherType& matcher) + { + typedef ConstraintAdapter<FulfillsConstraint<MatcherType> > ConstraintAdapterType; + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + + ConstraintAdapterType constraint(matcher); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EqualsConstraint<bool> >, Nil> >::t> + False() + { + return EqualTo<bool>(false); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EqualsConstraint<bool> >, Nil> >::t> + True() + { + return EqualTo<bool>(true); + } + +#if __cplusplus > 199711L + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EqualsConstraint<std::nullptr_t> >, Nil> >::t> + Null() + { + return EqualTo<std::nullptr_t>(nullptr); + } +#endif + + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EqualsConstraint<std::string> >, Nil> >::t> + EqualTo(const char* expected) + { + return EqualTo<std::string>(std::string(expected)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<IsGreaterThanConstraint<ExpectedType> >, Nil> >::t> + GreaterThan(const ExpectedType& expected) + { + typedef ConstraintAdapter<IsGreaterThanConstraint<ExpectedType> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<IsGreaterThanOrEqualToConstraint<ExpectedType> >, Nil> >::t> + GreaterThanOrEqualTo(const ExpectedType& expected) + { + typedef ConstraintAdapter<IsGreaterThanOrEqualToConstraint<ExpectedType> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<IsLessThanConstraint<ExpectedType> >, Nil> >::t> + LessThan(const ExpectedType& expected) + { + typedef ConstraintAdapter<IsLessThanConstraint<ExpectedType> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<IsLessThanOrEqualToConstraint<ExpectedType> >, Nil> >::t> + LessThanOrEqualTo(const ExpectedType& expected) + { + typedef ConstraintAdapter<IsLessThanOrEqualToConstraint<ExpectedType> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<ContainsConstraint<ExpectedType> >, Nil> >::t> + Containing(const ExpectedType& expected) + { + typedef ConstraintAdapter<ContainsConstraint<ExpectedType> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<ContainsConstraint<std::string> >, Nil> >::t> + Containing(const char* expected) + { + return Containing<std::string>(std::string(expected)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EndsWithConstraint<ExpectedType> >, Nil> >::t> + EndingWith(const ExpectedType& expected) + { + typedef ConstraintAdapter<EndsWithConstraint<ExpectedType> > ConstraintAdapterType; + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EndsWithConstraint<std::string> >, Nil> >::t> + EndingWith(const char* expected) + { + return EndingWith(std::string(expected)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<StartsWithConstraint<ExpectedType> >, Nil> >::t> + StartingWith(const ExpectedType& expected) + { + typedef ConstraintAdapter<StartsWithConstraint<ExpectedType> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<StartsWithConstraint<std::string> >, Nil> >::t> + StartingWith(const char* expected) + { + return StartingWith(std::string(expected)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<HasLengthConstraint<ExpectedType> >, Nil> >::t> + OfLength(const ExpectedType& expected) + { + typedef ConstraintAdapter<HasLengthConstraint<ExpectedType> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(expected); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<HasLengthConstraint<int> >, Nil> >::t> + Empty() + { + typedef ConstraintAdapter<HasLengthConstraint<int> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(0); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename ExpectedType> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EqualsContainerConstraint<ExpectedType, bool (*)(const typename ExpectedType::value_type&, const typename ExpectedType::value_type&)> >, Nil> >::t> + EqualToContainer(const ExpectedType& expected) + { + typedef bool (*DefaultBinaryPredivateType)(const typename ExpectedType::value_type&, const typename ExpectedType::value_type&); + typedef ConstraintAdapter<EqualsContainerConstraint<ExpectedType, DefaultBinaryPredivateType> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(EqualsContainerConstraint<ExpectedType, DefaultBinaryPredivateType>(expected, constraint_internal::default_comparer<typename ExpectedType::value_type>)); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename ExpectedType, typename BinaryPredicate> + ExpressionBuilder<typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapter<EqualsContainerConstraint<ExpectedType, BinaryPredicate> >, Nil> >::t> + EqualToContainer(const ExpectedType& expected, const BinaryPredicate predicate) + { + typedef ConstraintAdapter<EqualsContainerConstraint<ExpectedType, BinaryPredicate> > ConstraintAdapterType; + + typedef ExpressionBuilder< typename type_concat<ConstraintListType, ConstraintList<ConstraintAdapterType, Nil> >::t > BuilderType; + ConstraintAdapterType constraint(EqualsContainerConstraint<ExpectedType, BinaryPredicate>(expected, predicate)); + ConstraintList<ConstraintAdapterType, Nil> node(constraint, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + typedef ConstraintList<AndOperator, Nil> AndOperatorNode; + typedef ConstraintList<OrOperator, Nil> OrOperatorNode; + typedef ConstraintList<NotOperator, Nil> NotOperatorNode; + typedef ConstraintList<AllOperator, Nil> AllOperatorNode; + typedef ConstraintList<AtLeastOperator, Nil> AtLeastOperatorNode; + typedef ConstraintList<ExactlyOperator, Nil> ExactlyOperatorNode; + typedef ConstraintList<AtMostOperator, Nil> AtMostOperatorNode; + typedef ConstraintList<NoneOperator, Nil> NoneOperatorNode; + + ExpressionBuilder<typename type_concat<ConstraintListType, AllOperatorNode>::t> All() + { + typedef ExpressionBuilder<typename type_concat<ConstraintListType, AllOperatorNode>::t> BuilderType; + AllOperator op; + AllOperatorNode node(op, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, AtLeastOperatorNode>::t> AtLeast(unsigned int expected) + { + typedef ExpressionBuilder<typename type_concat<ConstraintListType, AtLeastOperatorNode>::t> BuilderType; + AtLeastOperator op(expected); + AtLeastOperatorNode node(op, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, ExactlyOperatorNode>::t> Exactly(unsigned int expected) + { + typedef ExpressionBuilder<typename type_concat<ConstraintListType, ExactlyOperatorNode>::t> BuilderType; + ExactlyOperator op(expected); + ExactlyOperatorNode node(op, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, AtMostOperatorNode>::t> AtMost(unsigned int expected) + { + typedef ExpressionBuilder<typename type_concat<ConstraintListType, AtMostOperatorNode>::t> BuilderType; + AtMostOperator op(expected); + AtMostOperatorNode node(op, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, NoneOperatorNode>::t> None() + { + typedef ExpressionBuilder<typename type_concat<ConstraintListType, NoneOperatorNode>::t> BuilderType; + NoneOperator op; + NoneOperatorNode node(op, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, AndOperatorNode>::t> And() + { + typedef ExpressionBuilder<typename type_concat<ConstraintListType, AndOperatorNode>::t> BuilderType; + AndOperator op; + AndOperatorNode node(op, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, OrOperatorNode>::t> Or() + { + typedef ExpressionBuilder<typename type_concat<ConstraintListType, OrOperatorNode>::t> BuilderType; + OrOperator op; + OrOperatorNode node(op, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + ExpressionBuilder<typename type_concat<ConstraintListType, NotOperatorNode>::t> Not() + { + typedef ExpressionBuilder<typename type_concat<ConstraintListType, NotOperatorNode>::t> BuilderType; + NotOperator op; + NotOperatorNode node(op, Nil()); + return BuilderType(Concatenate(m_constraint_list, node)); + } + + template <typename ActualType> + void Evaluate(ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + EvaluateConstraintList(m_constraint_list, result, operators, actual); + } + + ConstraintListType m_constraint_list; + }; + + template <typename T> + inline void StringizeConstraintList(const T& list, std::ostringstream& stm) + { + if (stm.tellp() > 0) + stm << " "; + + stm << snowhouse::Stringize(list.m_head); + StringizeConstraintList(list.m_tail, stm); + } + + inline void StringizeConstraintList(const Nil&, std::ostringstream&) + { + } + + template<typename ConstraintListType> + struct Stringizer< ExpressionBuilder<ConstraintListType> > + { + static std::string ToString(const ExpressionBuilder<ConstraintListType>& builder) + { + std::ostringstream stm; + StringizeConstraintList(builder.m_constraint_list, stm); + + return stm.str(); + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/fluent.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/fluent.h new file mode 100644 index 00000000..6bbd4b81 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/fluent.h @@ -0,0 +1,38 @@ + +// 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_FLUENT_H +#define IGLOO_FLUENT_H + +#include "constraintlist.h" +#include "constraintadapter.h" +#include "operators/constraintoperator.h" +#include "operators/andoperator.h" +#include "operators/oroperator.h" +#include "operators/collections/collectionconstraintevaluator.h" +#include "operators/collections/alloperator.h" +#include "operators/collections/noneoperator.h" +#include "operators/collections/atleastoperator.h" +#include "operators/collections/exactlyoperator.h" +#include "operators/collections/atmostoperator.h" +#include "operators/notoperator.h" +#include "expressionbuilder.h" + +namespace snowhouse { + + inline ExpressionBuilder<Nil> Is() + { + return ExpressionBuilder<Nil>(Nil()); + } + + inline ExpressionBuilder<Nil> Has() + { + return ExpressionBuilder<Nil>(Nil()); + } + +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/andoperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/andoperator.h new file mode 100644 index 00000000..39670632 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/andoperator.h @@ -0,0 +1,54 @@ + +// 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_ANDOPERATOR_H +#define IGLOO_ANDOPERATOR_H + +namespace snowhouse { + + struct AndOperator : public ConstraintOperator + { + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + EvaluateOperatorsWithLessOrEqualPrecedence(*this, operators, result); + + operators.push(this); + + EvaluateConstraintList(list.m_tail, result, operators, actual); + } + + void PerformOperation(ResultStack& result) + { + if(result.size() < 2) + { + throw InvalidExpressionException("The expression contains an and operator with too few operands"); + } + + bool right = result.top(); + result.pop(); + bool left = result.top(); + result.pop(); + + result.push(left && right); + } + + int Precedence() const + { + return 3; + } + }; + + template<> + struct Stringizer<AndOperator> + { + static std::string ToString(const AndOperator&) + { + return "and"; + } + }; +} +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/alloperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/alloperator.h new file mode 100644 index 00000000..4157faf9 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/alloperator.h @@ -0,0 +1,35 @@ + +// 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_ALLOPERATOR_H +#define IGLOO_ALLOPERATOR_H + +#include "collectionoperator.h" + +namespace snowhouse { + + struct AllOperator : public CollectionOperator + { + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + unsigned int passed_elements = CollectionConstraintEvaluator<ConstraintListType, ActualType>::Evaluate(*this, list, result, operators, actual); + + result.push(passed_elements == actual.size()); + } + }; + + template<> + struct Stringizer<AllOperator> + { + static std::string ToString(const AllOperator&) + { + return "all"; + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/atleastoperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/atleastoperator.h new file mode 100644 index 00000000..d46e697f --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/atleastoperator.h @@ -0,0 +1,41 @@ + +// 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_ATLEASTOPERATOR_H +#define IGLOO_ATLEASTOPERATOR_H + +#include "collectionoperator.h" + +namespace snowhouse { + + struct AtLeastOperator : public CollectionOperator + { + AtLeastOperator(unsigned int expected) : m_expected(expected) {} + + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + unsigned int passed_elements = CollectionConstraintEvaluator<ConstraintListType, ActualType>::Evaluate(*this, list, result, operators, actual); + + result.push(passed_elements >= m_expected); + } + + unsigned int m_expected; + }; + + template<> + struct Stringizer<AtLeastOperator> + { + static std::string ToString(const AtLeastOperator& op) + { + std::ostringstream stm; + stm << "at least " << op.m_expected; + return stm.str(); + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/atmostoperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/atmostoperator.h new file mode 100644 index 00000000..53debbc8 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/atmostoperator.h @@ -0,0 +1,39 @@ + +// 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_ATMOSTOPERATOR_H +#define IGLOO_ATMOSTOPERATOR_H + +namespace snowhouse { + + struct AtMostOperator : public CollectionOperator + { + AtMostOperator(unsigned int expected) : m_expected(expected) {} + + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + unsigned int passed_elements = CollectionConstraintEvaluator<ConstraintListType, ActualType>::Evaluate(*this, list, result, operators, actual); + + result.push(passed_elements <= m_expected); + } + + unsigned int m_expected; + }; + + template<> + struct Stringizer<AtMostOperator> + { + static std::string ToString(const AtMostOperator& op) + { + std::ostringstream stm; + stm << "at most " << op.m_expected; + return stm.str(); + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h new file mode 100644 index 00000000..3fa30f2c --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/collectionconstraintevaluator.h @@ -0,0 +1,113 @@ + +// 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_COLLECTIONCONSTRAINTEVALUATOR_H +#define IGLOO_COLLECTIONCONSTRAINTEVALUATOR_H + +#include <string> +#include "../invalidexpressionexception.h" + +namespace snowhouse +{ + +template<typename ConstraintListType, typename ActualType> +struct CollectionConstraintEvaluator +{ + static unsigned int Evaluate(const ConstraintOperator& op, + ConstraintListType& expression, ResultStack& result, + OperatorStack& operators, const ActualType& actual) + { + ConstraintOperator::EvaluateOperatorsWithLessOrEqualPrecedence(op, + operators, result); + + unsigned int passed_elements = 0; + typename ActualType::const_iterator it; + for(it = actual.begin(); it != actual.end(); it++) + { + if(ConstraintOperator::EvaluateElementAgainstRestOfExpression(expression, + *it)) + { + passed_elements++; + } + } + + return passed_elements; + } +}; + +struct StringLineParser +{ + static void Parse(const std::string& str, std::vector<std::string>& res) + { + size_t start = 0; + size_t newline = FindNewline(str, start); + + while(newline != std::string::npos) + { + StoreLine(str, start, newline, res); + start = MoveToNextLine(str, newline); + newline = FindNewline(str, start); + } + + if(start < str.size()) + { + StoreLine(str, start, std::string::npos, res); + } + } + +private: + static size_t FindNewline(const std::string& str, size_t start) + { + return str.find_first_of("\r\n", start); + } + + static void StoreLine(const std::string& str, size_t start, size_t end, + std::vector<std::string>& res) + { + std::string line = str.substr(start, end - start); + res.push_back(line); + } + + static size_t MoveToNextLine(const std::string& str, size_t newline) + { + if(str.find("\r\n", newline) == newline) + { + return newline + 2; + } + + if(str.find("\n", newline) == newline) + { + return newline + 1; + } + + if(str.find("\r", newline) == newline) + { + return newline + 1; + } + + std::ostringstream stm; + stm << "This string seems to contain an invalid line ending at position " + << newline << ":\n" << str << std::endl; + throw InvalidExpressionException(stm.str()); + } +}; + +template<typename ConstraintListType> +struct CollectionConstraintEvaluator<ConstraintListType, std::string> +{ + static unsigned int Evaluate(const ConstraintOperator& op, + ConstraintListType& expression, ResultStack& result, + OperatorStack& operators, const std::string& actual) + { + std::vector<std::string> lines; + StringLineParser::Parse(actual, lines); + return CollectionConstraintEvaluator<ConstraintListType, std::vector<std::string> >::Evaluate(op, expression, result, operators, lines); + } +}; + +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/collectionoperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/collectionoperator.h new file mode 100644 index 00000000..c1bb8bec --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/collectionoperator.h @@ -0,0 +1,24 @@ + +// 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_COLLECTIONOPERATOR_H +#define IGLOO_COLLECTIONOPERATOR_H + +namespace snowhouse { + struct CollectionOperator : public ConstraintOperator + { + void PerformOperation(ResultStack&) + { + } + + int Precedence() const + { + return 1; + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/exactlyoperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/exactlyoperator.h new file mode 100644 index 00000000..81c2dcaa --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/exactlyoperator.h @@ -0,0 +1,39 @@ + +// 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_EXACTLYOPERATOR_H +#define IGLOO_EXACTLYOPERATOR_H + +namespace snowhouse { + + struct ExactlyOperator : public CollectionOperator + { + ExactlyOperator(unsigned int expected) : m_expected(expected) {} + + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + unsigned int passed_elements = CollectionConstraintEvaluator<ConstraintListType, ActualType>::Evaluate(*this, list, result, operators, actual); + + result.push(passed_elements == m_expected); + } + + unsigned int m_expected; + }; + + template<> + struct Stringizer< ExactlyOperator > + { + static std::string ToString(const ExactlyOperator& op) + { + std::ostringstream stm; + stm << "exactly " << op.m_expected; + return stm.str(); + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/noneoperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/noneoperator.h new file mode 100644 index 00000000..c4570915 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/collections/noneoperator.h @@ -0,0 +1,33 @@ + +// 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_NONEOPERATOR_H +#define IGLOO_NONEOPERATOR_H + +namespace snowhouse { + + struct NoneOperator : public CollectionOperator + { + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + unsigned int passed_elements = CollectionConstraintEvaluator<ConstraintListType, ActualType>::Evaluate(*this, list, result, operators, actual); + result.push(passed_elements == 0); + } + }; + + template<> + struct Stringizer<NoneOperator> + { + static std::string ToString(const NoneOperator&) + { + return "none"; + } + }; + +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/constraintoperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/constraintoperator.h new file mode 100644 index 00000000..eafe6c51 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/constraintoperator.h @@ -0,0 +1,70 @@ + +// 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_CONTRAINTOPERATOR_H +#define IGLOO_CONTRAINTOPERATOR_H + +#include "invalidexpressionexception.h" + +namespace snowhouse { + + struct ConstraintOperator + { +#if __cplusplus > 199711L +#else + virtual ~ConstraintOperator() {} +#endif + + virtual void PerformOperation(ResultStack& result) = 0; + virtual int Precedence() const = 0; + + template <typename ConstraintListType, typename ActualType> + static bool EvaluateElementAgainstRestOfExpression(ConstraintListType& list, const ActualType& actual) + { + ResultStack innerResult; + OperatorStack innerOperators; + + EvaluateConstraintList(list.m_tail, innerResult, innerOperators, actual); + EvaluateAllOperatorsOnStack(innerOperators, innerResult); + + if(innerResult.empty()) + { + throw InvalidExpressionException("The expression after \"" + snowhouse::Stringize(list.m_head) + "\" operator does not yield any result"); + } + + return innerResult.top(); + } + + static void EvaluateOperatorsWithLessOrEqualPrecedence(const ConstraintOperator& op, OperatorStack& operators, ResultStack& result) + { + while(!operators.empty()) + { + ConstraintOperator* op_from_stack = operators.top(); + + if(op_from_stack->Precedence() > op.Precedence()) + { + break; + } + + op_from_stack->PerformOperation(result); + operators.pop(); + } + } + + static void EvaluateAllOperatorsOnStack(OperatorStack& operators, ResultStack& result) + { + while(!operators.empty()) + { + ConstraintOperator* op = operators.top(); + op->PerformOperation(result); + operators.pop(); + } + } + }; + +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/invalidexpressionexception.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/invalidexpressionexception.h new file mode 100644 index 00000000..404341f1 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/invalidexpressionexception.h @@ -0,0 +1,28 @@ + +// 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_INVALUDEXPRESSIONEXCEPTION_H +#define IGLOO_INVALUDEXPRESSIONEXCEPTION_H + +namespace snowhouse { + + struct InvalidExpressionException + { + InvalidExpressionException(const std::string& message) : m_message(message) + { + } + + const std::string& Message() const + { + return m_message; + } + + std::string m_message; + }; + +} + +#endif // IGLOO_INVALUDEXPRESSIONEXCEPTION_H diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/notoperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/notoperator.h new file mode 100644 index 00000000..709c8413 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/notoperator.h @@ -0,0 +1,53 @@ + +// 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_NOTOPERATOR_H +#define IGLOO_NOTOPERATOR_H + +namespace snowhouse { + + struct NotOperator : public ConstraintOperator + { + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + EvaluateOperatorsWithLessOrEqualPrecedence(*this, operators, result); + + operators.push(this); + + EvaluateConstraintList(list.m_tail, result, operators, actual); + } + + void PerformOperation(ResultStack& result) + { + if(result.size() < 1) + { + throw InvalidExpressionException("The expression contains a not operator without any operand"); + } + + bool right = result.top(); + result.pop(); + + result.push(!right); + } + + int Precedence() const + { + return 2; + } + }; + + template<> + struct Stringizer<NotOperator> + { + static std::string ToString(const NotOperator&) + { + return "not"; + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/oroperator.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/oroperator.h new file mode 100644 index 00000000..5a307ff6 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/oroperator.h @@ -0,0 +1,55 @@ + +// 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_OROPERATOR_H +#define IGLOO_OROPERATOR_H + +namespace snowhouse { + + struct OrOperator : public ConstraintOperator + { + template <typename ConstraintListType, typename ActualType> + void Evaluate(ConstraintListType& list, ResultStack& result, OperatorStack& operators, const ActualType& actual) + { + EvaluateOperatorsWithLessOrEqualPrecedence(*this, operators, result); + + operators.push(this); + + EvaluateConstraintList(list.m_tail, result, operators, actual); + } + + void PerformOperation(ResultStack& result) + { + if(result.size() < 2) + { + throw InvalidExpressionException("The expression contains an or operator with too few operands"); + } + + bool right = result.top(); + result.pop(); + bool left = result.top(); + result.pop(); + + result.push(left || right); + } + + int Precedence() const + { + return 4; + } + }; + + template<> + struct Stringizer<OrOperator> + { + static std::string ToString(const OrOperator&) + { + return "or"; + } + }; +} + +#endif |