diff options
Diffstat (limited to 'vendor/bandit/bandit/assertion_frameworks')
42 files changed, 2687 insertions, 0 deletions
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/.gitignore b/vendor/bandit/bandit/assertion_frameworks/snowhouse/.gitignore new file mode 100644 index 00000000..bf3ce9c6 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/.gitignore @@ -0,0 +1,6 @@ +#cmake files +CMakeCache.txt +CMakeFiles/ +Makefile +bin/ +cmake_install.cmake diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/CMakeLists.txt b/vendor/bandit/bandit/assertion_frameworks/snowhouse/CMakeLists.txt new file mode 100644 index 00000000..edfabc0d --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 2.8) + +project(snowhouse) + +include_directories("${PROJECT_SOURCE_DIR}") + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin) + +set(CMAKE_CXX_FLAGS "-Wfatal-errors -Wall -W -Werror -Wfloat-equal -Wundef -Wendif-labels -Wshadow -pedantic-errors") + +FILE(GLOB SnowhouseSpecSourceFiles example/*.cpp) +add_executable(snowhouse-tests ${SnowhouseSpecSourceFiles}) + +add_custom_command(TARGET snowhouse-tests + POST_BUILD + COMMAND snowhouse-tests + WORKING_DIRECTORY ./bin) diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/README.md b/vendor/bandit/bandit/assertion_frameworks/snowhouse/README.md new file mode 100644 index 00000000..67d849b6 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/README.md @@ -0,0 +1,338 @@ +snowhouse +========= + +An assertion library for C++ + +Snowhouse is a stand alone assertion framework for C++. It was originally +developed as part of [Igloo](http://github.com/joakimkarlsson/igloo) and has +been extracted to be usable in other contexts. + +## Usage + +```C++ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; + +int main() +{ + std::cout << "Testing that 23 is 23" << std::endl; + AssertThat(23, Is().EqualTo(23)); + + try + { + AssertThat(12, Is().LessThan(11).And().GreaterThan(99)); + } + catch(const AssertionException& ex) + { + std::cout << "Apparently this failed:" << std::endl; + std::cout << ex.GetMessage() << std::endl; + } + + return 0; +} +``` + +### Assertions + +Snowhouse uses a constraint based assertion model that is heavily inspired by the +model used in [NUnit](http://nunit.org/). An assertion in Snowhouse is written +using the following format: + +```cpp +AssertThat(actual_value, <constraint expression>); +``` + +where <constraint expression> is an expression that actual_value is evaluated against when the test is executed. + +Constraint expressions come in two basic forms: composite and fluent expressions + +#### Composite Expressions + +With composite expressions, you can create compact, powerful expressions that combine a set of predefined constraints with ones that you provide yourself. + +Example: + +```cpp +AssertThat(length, IsGreaterThan(4) && !Equals(10)); +``` + +Composite expressions can be any combination of constraints and the standard logical C++ operators. + +You can also add your own constraints to be used within composite expressions. + +####Fluent Expressions + +With fluent expressions, you can create assertions that better convey the intent of a test without exposing implementation-specific details. Fluent expressions aim to help you create tests that are not just by developers for developers, but rather can be read and understood by domain experts. + +Fluent expressions also has the ability to make assertions on the elements in a conteiner in a way you cannot achieve with composite expressions. + +Example: + +```cpp +AssertThat(length, Is().GreaterThan(4).And().Not().EqualTo(10)); +``` + +### Basic Constraints + +####Equality Constraint + +Used to verify equality between actual and expected. + +```cpp +AssertThat(x, Equals(12)); +AssertThat(x, Is().EqualTo(12)); +``` + +####EqualityWithDelta Constraint + +Used to verify equality between actual and expected, allowing the two to differ by a delta. + +```cpp +AssertThat(2.49, EqualsWithDelta(2.5, 0.1)); +AssertThat(2.49, Is().EqualToWithDelta(2.5, 0.1)); +``` + +####GreaterThan Constraint + +Used to verify that actual is greater than a value. + +```cpp +AssertThat(x, IsGreaterThan(4)); +AssertThat(x, Is().GreaterThan(4)); +``` + + +####LessThan Constraint + +Used to verify that actual is less than a value. + +```cpp +AssertThat(x, IsLessThan(3)); +AssertThat(x, Is().LessThan(3)); +``` + +### String Constraints + +String assertions in Snowhouse are used to verify the values of STL strings (std::string). + +####Equality Constraints + +Used to verify that actual is equal to an expected value. + +```cpp +Assert:That(actual_str, Equals("foo")); +AssertThat(actual_str, Is().EqualTo("foo")); +``` + +####Contains Constraint + +Used to verify that a string contains a substring. + +```cpp +AssertThat(actual_str, Contains("foo")); +AssertThat(actual_str, Is().Containing("foo")); +``` + +####EndsWith Constraint + +Used to verify that a string ends with an expected substring. + +```cpp +AssertThat(actual_str, EndsWith("foo")); +AssertThat(actual_str, Is().EndingWith("foo")); +``` + +####StartsWith Constraint + +Used to verify that a string starts with an expected substring. + +```cpp +AssertThat(actual_str, StartsWith("foo")); +AssertThat(actual_str, Is().StartingWith("foo")); +``` + +####HasLength Constraint + +Used to verify that a string is of the expected length. + +```cpp +AssertThat(actual_str, HasLength(5)); +AssertThat(actual_str, Is().OfLength(5)); +``` + +###Constraints on Multi Line Strings + +If you have a string that contains multiple lines, you can use the collection constraints to make assertions on the content of that string. This may be handy if you have a string that, for instance, represents the resulting content of a file or a network transmission. + +Snowhouse can handle both windows (CR+LF) and unix (LF) line endings + +```cpp +std::string lines = "First line\r\nSecond line\r\nThird line"; +AssertThat(lines, Has().Exactly(1).StartingWith("Second")); +``` + +###Container Constraints + +The following constraints can be applied to containers in the standard template library: + +####Contains Constraint + +Used to verify that a container contains an expected value. + +```cpp +AssertThat(container, Contains(12)); +AssertThat(container, Is().Containing(12)); +``` + +####HasLength Constraint + +Used to verify that a container has the expected length. + +```cpp +AssertThat(container, HasLength(3)); +AssertThat(container, Is().OfLength(3)); +``` + +####IsEmpty Constraint + +Used to verify that a container is empty. + +```cpp +AssertThat(contatiner, IsEmpty()); +AssertThat(container, Is().Empty()); +``` + +####All + +Used to verify that all elements of a STL sequence container matches an expectation. + +```cpp +AssertThat(container, Has().All().LessThan(5).Or().EqualTo(66)); +``` + +####AtLeast + +Used to verify that at least a specified amount of elements in a STL sequence container matches an expectation. + +```cpp +AssertThat(container, Has().AtLeast(3).StartingWith("foo")); +``` + +####AtMost + +Used to verify that at most a specified amount of elements in a STL sequence container matches an expectation. + +```cpp +Assert:That(container, Has().AtMost(2).Not().Containing("failed")); +``` + +####Exactly + +Used to verify that a STL sequence container has exactly a specified amount of elements that matches an expectation. + +```cpp +AssertThat(container, Has().Exactly(3).GreaterThan(10).And().LessThan(20)); +``` + +####EqualsContainer + +Used to verify that two STL sequence containers are equal. + +```cpp +AssertThat(container1, EqualsContainer(container2)); +AssertThat(container1, Is().EqualToContainer(container2)); +``` + +#####Predicate functions + +You can supply a predicate function or a functor to EqualsContainer to customize how to compare the elements in the two containers. + +With a predicate function: + +```cpp +static bool are_my_types_equal(const my_type& lhs, const my_type& rhs) +{ + return lhs.my_val_ == rhs.my_val_; +} + +AssertThat(container1, EqualsContainer(container2, are_my_types_equal)); +``` + +With a functor as predicate: + +```cpp +struct within_delta +{ + within_delta(int delta) : delta_(delta) {} + + bool operator()(const my_type& lhs, const my_type& rhs) const + { + return abs(lhs.my_val_ - rhs.my_val_) <= delta_; + } + +private: + int delta_; +}; + +AssertThat(container1, Is().EqualToContainer(container1, within_delta(1)); +``` + +###Exceptions + +Exception constraints can be used to verify that your code throws the correct exceptions. + +####AssertThrows + +AssertThrows succeeds if the exception thrown by the call is of the supplied type (or one of its subtypes). + +```cpp +AssertThrows(std::logic_error, myObject.a_method(42)); +``` + +####Making Assertions on the Thrown Exceptions + +If AssertThrows succeeds, it will store the thrown exception so that you can make more detailed assertions on it. + +```cpp +AssertThrows(std::logic_error, myObject.a_method(42)); +AssertThat(LastException<std::logic_error>().what(), Is().Containing("logic failure")); +``` + +The LastException<> is available in the scope of the call to AssertThrows. An exception is not available between specs in order to avoid the result of one spec contaminating another. + +###Custom Constraints + +You can add your own constraints to Snowhouse to create more expressive specifications. + +####Fulfills Constraints + +By defining the following matcher + +```cpp +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 Snowhouse: + +```cpp +AssertThat(42, Fulfills(IsEvenNumber())); +AssertThat(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. diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/main.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/main.cpp new file mode 100644 index 00000000..4153ec7f --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/main.cpp @@ -0,0 +1,21 @@ +#include <snowhouse/snowhouse.h> + +using namespace snowhouse; + +int main() +{ + std::cout << "Testing that 23 is 23" << std::endl; + Assert::That(23, Is().EqualTo(23)); + + try + { + AssertThat(12, Is().LessThan(11).And().GreaterThan(99)); + } + catch(const AssertionException& ex) + { + std::cout << "Apparently this failed:" << std::endl; + std::cout << ex.GetMessage() << std::endl; + } + + return 0; +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assert.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assert.h new file mode 100644 index 00000000..e25bf501 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assert.h @@ -0,0 +1,116 @@ + +// 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_ASSERT_H +#define IGLOO_ASSERT_H + +#include "stringize.h" +#include "stringizers.h" + +namespace snowhouse { + + class Assert + { + public: + + template <typename ActualType, typename ConstraintListType> + static void That(const ActualType& actual, ExpressionBuilder<ConstraintListType> expression) + { + const char* no_file = ""; + int line_number = 0; + + Assert::That(actual, expression, no_file, line_number); + } + + template <typename ActualType, typename ConstraintListType> + static void That(const ActualType& actual, ExpressionBuilder<ConstraintListType> expression, const char* file_name, int line_number) + { + try + { + ResultStack result; + OperatorStack operators; + expression.Evaluate(result, operators, actual); + + while (!operators.empty()) + { + ConstraintOperator* op = operators.top(); + op->PerformOperation(result); + operators.pop(); + } + + if (result.empty()) + { + throw InvalidExpressionException("The expression did not yield any result"); + } + + if (!result.top()) + { + throw AssertionException(CreateErrorText(expression, actual), file_name, line_number); + } + } + catch (const InvalidExpressionException& e) + { + throw AssertionException("Malformed expression: \"" + snowhouse::Stringize(expression) + "\"\n" + e.Message()); + } + } + + template <typename ConstraintListType> + static void That(const char* actual, ExpressionBuilder<ConstraintListType> expression) + { + return That(std::string(actual), expression); + } + + template <typename ActualType, typename ExpressionType> + static void That(const ActualType& actual, const ExpressionType& expression) + { + const char* no_file = ""; + int no_line = 0; + That(actual, expression, no_file, no_line); + } + + template <typename ActualType, typename ExpressionType> + static void That(const ActualType& actual, const ExpressionType& expression, const char* file_name, int line_number) + { + if (!expression(actual)) + { + throw AssertionException(CreateErrorText(expression, actual), file_name, line_number); + } + } + + template <typename ExpressionType> + static void That(const char* actual, const ExpressionType& expression) + { + return That(std::string(actual), expression); + } + + static void That(bool actual) + { + if (!actual) + { + throw AssertionException("Expected: true\nActual: false"); + } + } + + static void Failure(const std::string& message) + { + throw AssertionException(message); + } + + private: + template <class ExpectedType, class ActualType> + static std::string CreateErrorText(const ExpectedType& expected, const ActualType& actual) + { + std::ostringstream str; + + str << "Expected: " << snowhouse::Stringize(expected) << std::endl; + str << "Actual: " << snowhouse::Stringize(actual) << std::endl; + + return str.str(); + } + }; +} + +#endif // IGLOO_ASSERT_H diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assertionexception.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assertionexception.h new file mode 100644 index 00000000..77890a7e --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assertionexception.h @@ -0,0 +1,48 @@ + +// 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_ASSERTIONEXCEPTION_H +#define IGLOO_ASSERTIONEXCEPTION_H + +namespace snowhouse { + class AssertionException : public std::exception + { + public: + AssertionException(const std::string& message) + : m_message(message), m_fileName(""), m_line(0) + {} + + AssertionException(const std::string& message, const std::string& fileName, unsigned int line) + : m_message(message), m_fileName(fileName), m_line(line) + {} + + virtual ~AssertionException() throw() + { + } + + std::string GetMessage() const + { + return m_message; + } + + std::string GetFilename() const + { + return m_fileName; + } + + unsigned int GetLineNumber() const + { + return m_line; + } + + private: + std::string m_message; + std::string m_fileName; + unsigned int m_line; + }; +} + +#endif // IGLOO_ASSERTIONEXCEPTION_H diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assertmacro.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assertmacro.h new file mode 100644 index 00000000..6ebdfe1f --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assertmacro.h @@ -0,0 +1,15 @@ + +// 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_ASSERTMACRO_H +#define IGLOO_ASSERTMACRO_H + +#include "assert.h" + +#define AssertThat(p1,p2)\ + Assert::That((p1), (p2), __FILE__, __LINE__);\ + +#endif // IGLOO_ASSERTMACRO_H diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/constraints.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/constraints.h new file mode 100644 index 00000000..ea7a53d1 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/constraints.h @@ -0,0 +1,21 @@ +
+// 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_CONSTRAINTS_H
+#define IGLOO_CONSTRAINTS_H
+
+#include "containsconstraint.h"
+#include "endswithconstraint.h"
+#include "equalsconstraint.h"
+#include "haslengthconstraint.h"
+#include "isgreaterthanconstraint.h"
+#include "islessthanconstraint.h"
+#include "startswithconstraint.h"
+#include "fulfillsconstraint.h"
+#include "equalswithdeltaconstraint.h"
+#include "equalscontainerconstraint.h"
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/containsconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/containsconstraint.h new file mode 100644 index 00000000..f20d6800 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/containsconstraint.h @@ -0,0 +1,80 @@ +
+// 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_CONTAINSCONSTRAINT_H
+#define IGLOO_CONTAINSCONSTRAINT_H
+
+#include <algorithm>
+
+#include "./expressions/expression.h"
+
+namespace snowhouse {
+
+ template <typename ContainerType>
+ struct find_in_container_traits
+ {
+ template <typename ExpectedType>
+ static bool find(const ContainerType& container, const ExpectedType& expected)
+ {
+ return std::find(container.begin(), container.end(), expected) != container.end();
+ }
+ };
+
+ template <typename KeyType, typename ValueType>
+ struct find_in_container_traits<std::map<KeyType, ValueType> >
+ {
+ template <typename ExpectedType>
+ static bool find(const std::map<KeyType, ValueType>& container, const ExpectedType& expected)
+ {
+ return container.find(expected) != container.end();
+ }
+ };
+
+ template <typename ExpectedType>
+ struct ContainsConstraint : Expression< ContainsConstraint<ExpectedType> >
+ {
+ ContainsConstraint(const ExpectedType& expected)
+ : m_expected(expected) {}
+
+ template <typename ActualType>
+ bool operator()(const ActualType& actual) const
+ {
+ return find_in_container_traits<ActualType>::find(actual, m_expected);
+ }
+
+ bool operator()(const std::string& actual) const
+ {
+ return actual.find(m_expected) != actual.npos;
+ }
+
+ ExpectedType m_expected;
+ };
+
+ template< typename ExpectedType >
+ inline ContainsConstraint<ExpectedType> Contains(const ExpectedType& expected)
+ {
+ return ContainsConstraint<ExpectedType>(expected);
+ }
+
+ inline ContainsConstraint<std::string> Contains(const char* expected)
+ {
+ return ContainsConstraint<std::string>(expected);
+ }
+
+ template< typename ExpectedType >
+ struct Stringizer< ContainsConstraint< ExpectedType > >
+ {
+ static std::string ToString(const ContainsConstraint<ExpectedType>& constraint)
+ {
+ std::ostringstream builder;
+ builder << "contains " << snowhouse::Stringize(constraint.m_expected);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/endswithconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/endswithconstraint.h new file mode 100644 index 00000000..c867e203 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/endswithconstraint.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_ENDSWITHCONSTRAINT_H
+#define IGLOO_ENDSWITHCONSTRAINT_H
+
+#include "./expressions/expression.h"
+
+namespace snowhouse {
+
+ template <typename ExpectedType>
+ struct EndsWithConstraint : Expression< EndsWithConstraint<ExpectedType> >
+ {
+ EndsWithConstraint(const ExpectedType& expected)
+ : m_expected(expected) {}
+
+ bool operator()(const std::string& actual) const
+ {
+ size_t expectedPos = actual.length() - m_expected.length();
+ return actual.find(m_expected) == expectedPos;
+ }
+
+ ExpectedType m_expected;
+ };
+
+ template< typename ExpectedType >
+ inline EndsWithConstraint<ExpectedType> EndsWith(const ExpectedType& expected)
+ {
+ return EndsWithConstraint<ExpectedType>(expected);
+ }
+
+ inline EndsWithConstraint<std::string> EndsWith(const char* expected)
+ {
+ return EndsWithConstraint<std::string>(expected);
+ }
+
+ template< typename ExpectedType >
+ struct Stringizer< EndsWithConstraint< ExpectedType > >
+ {
+ static std::string ToString(const EndsWithConstraint<ExpectedType>& constraint)
+ {
+ std::ostringstream builder;
+ builder << "ends with " << snowhouse::Stringize(constraint.m_expected);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalsconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalsconstraint.h new file mode 100644 index 00000000..cbdc4054 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalsconstraint.h @@ -0,0 +1,74 @@ +
+// 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 "./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);
+ }
+
+ 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
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalscontainerconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalscontainerconstraint.h new file mode 100644 index 00000000..6bb5d797 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalscontainerconstraint.h @@ -0,0 +1,75 @@ + +// 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_EQUALSCONTAINERCONSTRAINT_H +#define IGLOO_EQUALSCONTAINERCONSTRAINT_H + +namespace snowhouse { + + namespace constraint_internal { + template<typename T> + inline bool default_comparer(const T& lhs, const T& rhs) + { + return lhs == rhs; + } + } + + template< typename ExpectedType, typename BinaryPredicate> + struct EqualsContainerConstraint : Expression< EqualsContainerConstraint<ExpectedType, BinaryPredicate> > + { + EqualsContainerConstraint(const ExpectedType& expected, const BinaryPredicate predicate) + : expected_(expected), predicate_(predicate) + {} + + template<typename ActualType> + bool operator()(const ActualType& actual) const + { + typename ActualType::const_iterator actual_it; + typename ExpectedType::const_iterator expected_it; + + for(actual_it = actual.begin(), expected_it = expected_.begin(); actual_it != actual.end() && expected_it != expected_.end(); actual_it++, expected_it++) + { + if(!predicate_(*actual_it, *expected_it)) + { + return false; + } + } + + return actual.size() == expected_.size(); + } + + const ExpectedType expected_; + const BinaryPredicate predicate_; + + private: + EqualsContainerConstraint& operator=(const EqualsContainerConstraint&) { return *this; } + }; + + template< typename ExpectedType> + inline EqualsContainerConstraint<ExpectedType, bool (*)(const typename ExpectedType::value_type&, const typename ExpectedType::value_type&)> EqualsContainer(const ExpectedType& expected) + { + return EqualsContainerConstraint<ExpectedType, bool (*)(const typename ExpectedType::value_type&, const typename ExpectedType::value_type&)>(expected, constraint_internal::default_comparer); + } + + template< typename ExpectedType, typename BinaryPredicate > + inline EqualsContainerConstraint<ExpectedType, BinaryPredicate> EqualsContainer(const ExpectedType& expected, const BinaryPredicate predicate) + { + return EqualsContainerConstraint<ExpectedType, BinaryPredicate>(expected, predicate); + } + + template< typename ExpectedType, typename BinaryPredicate > + struct Stringizer< EqualsContainerConstraint<ExpectedType, BinaryPredicate> > + { + static std::string ToString(const EqualsContainerConstraint<ExpectedType, BinaryPredicate>& constraint) + { + std::ostringstream builder; + builder << snowhouse::Stringize(constraint.expected_); + return builder.str(); + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalswithdeltaconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalswithdeltaconstraint.h new file mode 100644 index 00000000..b54fb74e --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalswithdeltaconstraint.h @@ -0,0 +1,51 @@ + +// 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_EQUALSWITHDELTACONSTRAINT_H +#define IGLOO_EQUALSWITHDELTACONSTRAINT_H + +#include "./expressions/expression.h" + +namespace snowhouse { + + template< typename ExpectedType, typename DeltaType > + struct EqualsWithDeltaConstraint : Expression< EqualsWithDeltaConstraint<ExpectedType, DeltaType> > + { + EqualsWithDeltaConstraint(const ExpectedType& expected, const DeltaType& delta) + : m_expected(expected), m_delta(delta) + { + } + + template<typename ActualType> + bool operator()(const ActualType& actual) const + { + return ((m_expected <= (actual + m_delta)) && (m_expected >= (actual - m_delta))); + } + + ExpectedType m_expected; + DeltaType m_delta; + }; + + template< typename ExpectedType, typename DeltaType > + inline EqualsWithDeltaConstraint<ExpectedType, DeltaType> EqualsWithDelta(const ExpectedType& expected, const DeltaType& delta) + { + return EqualsWithDeltaConstraint<ExpectedType, DeltaType>(expected, delta); + } + + template< typename ExpectedType, typename DeltaType > + struct Stringizer< EqualsWithDeltaConstraint< ExpectedType, DeltaType > > + { + static std::string ToString(const EqualsWithDeltaConstraint<ExpectedType, DeltaType>& constraint) + { + std::ostringstream builder; + builder << "equal to " << snowhouse::Stringize(constraint.m_expected) << " (+/- " << snowhouse::Stringize(constraint.m_delta) << ")"; + + return builder.str(); + } + }; +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/andexpression.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/andexpression.h new file mode 100644 index 00000000..8b6b7d12 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/andexpression.h @@ -0,0 +1,46 @@ +
+// 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_ANDEXPRESSION_H
+#define IGLOO_ANDEXPRESSION_H
+
+#include "./expression_fwd.h"
+
+namespace snowhouse {
+
+ template< typename LeftExpression, typename RightExpression >
+ struct AndExpression : Expression< AndExpression<LeftExpression, RightExpression> >
+ {
+ AndExpression(const LeftExpression& left, const RightExpression& right)
+ : m_left(left)
+ , m_right(right)
+ {
+ }
+
+ template< typename ActualType >
+ bool operator()(const ActualType& actual) const
+ {
+ return (m_left(actual) && m_right(actual));
+ }
+
+ LeftExpression m_left;
+ RightExpression m_right;
+ };
+
+ template< typename LeftExpression, typename RightExpression >
+ struct Stringizer< AndExpression<LeftExpression, RightExpression> >
+ {
+ static std::string ToString(const AndExpression<LeftExpression, RightExpression>& expression)
+ {
+ std::ostringstream builder;
+ builder << Stringize(expression.m_left) << " and " << Stringize(expression.m_right);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/expression.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/expression.h new file mode 100644 index 00000000..fa894818 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/expression.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_EXPRESSION_H
+#define IGLOO_EXPRESSION_H
+
+#include "./notexpression.h"
+#include "./andexpression.h"
+#include "./orexpression.h"
+
+namespace snowhouse {
+
+ template<typename T>
+ struct Expression
+ {
+ NotExpression<T> operator!() const
+ {
+ return NotExpression<T>(static_cast<const T&>(*this));
+ }
+
+ template< typename Right >
+ AndExpression<T, Right> operator&&(const Right& right) const
+ {
+ return AndExpression<T, Right>(static_cast<const T&>(*this), right);
+ }
+
+ template< typename Right >
+ OrExpression<T, Right> operator||(const Right& right) const
+ {
+ return OrExpression<T, Right>(static_cast<const T&>(*this), right);
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/expression_fwd.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/expression_fwd.h new file mode 100644 index 00000000..c0e3706e --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/expression_fwd.h @@ -0,0 +1,15 @@ +
+// 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_EXPRESSION_FWD_H
+#define IGLOO_EXPRESSION_FWD_H
+
+namespace snowhouse {
+ template<typename T>
+ struct Expression;
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/notexpression.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/notexpression.h new file mode 100644 index 00000000..4785f07b --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/notexpression.h @@ -0,0 +1,44 @@ +
+// 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_NOTEXPRESSION_H
+#define IGLOO_NOTEXPRESSION_H
+
+#include "./expression_fwd.h"
+
+namespace snowhouse {
+
+ template< typename ExpressionType >
+ struct NotExpression : Expression< NotExpression<ExpressionType> >
+ {
+ NotExpression(const ExpressionType& expression)
+ : m_expression(expression)
+ {
+ }
+
+ template<typename ActualType>
+ bool operator()(const ActualType& actual) const
+ {
+ return !m_expression(actual);
+ }
+
+ ExpressionType m_expression;
+ };
+
+ template< typename ExpressionType >
+ struct Stringizer< NotExpression<ExpressionType> >
+ {
+ static std::string ToString(const NotExpression<ExpressionType>& expression)
+ {
+ std::ostringstream builder;
+ builder << "not " << snowhouse::Stringize(expression.m_expression);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/orexpression.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/orexpression.h new file mode 100644 index 00000000..c1b6c12b --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/expressions/orexpression.h @@ -0,0 +1,46 @@ +
+// 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_OREXPRESSION_H
+#define IGLOO_OREXPRESSION_H
+
+#include "./expression_fwd.h"
+
+namespace snowhouse {
+
+ template< typename LeftExpression, typename RightExpression >
+ struct OrExpression : Expression< OrExpression<LeftExpression, RightExpression> >
+ {
+ OrExpression(const LeftExpression& left, const RightExpression& right)
+ : m_left(left)
+ , m_right(right)
+ {
+ }
+
+ template< typename ActualType >
+ bool operator()(const ActualType& actual) const
+ {
+ return (m_left(actual) || m_right(actual));
+ }
+
+ LeftExpression m_left;
+ RightExpression m_right;
+ };
+
+ template< typename LeftExpression, typename RightExpression >
+ struct Stringizer< OrExpression<LeftExpression, RightExpression> >
+ {
+ static std::string ToString(const OrExpression<LeftExpression, RightExpression>& expression)
+ {
+ std::ostringstream builder;
+ builder << snowhouse::Stringize(expression.m_left) << " or " << snowhouse::Stringize(expression.m_right);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/fulfillsconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/fulfillsconstraint.h new file mode 100644 index 00000000..577056c1 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/fulfillsconstraint.h @@ -0,0 +1,51 @@ + +// 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 FULFILLSCONSTRAINT_H +#define FULFILLSCONSTRAINT_H + +#include "./expressions/expression.h" + +namespace snowhouse { + + template< typename MatcherType > + struct FulfillsConstraint : Expression< FulfillsConstraint<MatcherType> > + { + FulfillsConstraint(const MatcherType& matcher) + : m_matcher(matcher) + { + } + + template<typename ActualType> + bool operator()(const ActualType& actual) const + { + return m_matcher.Matches(actual); + } + + MatcherType m_matcher; + }; + + template< typename MatcherType > + inline FulfillsConstraint<MatcherType> Fulfills(const MatcherType& matcher) + { + return FulfillsConstraint<MatcherType>(matcher); + } + + template< typename MatcherType > + struct Stringizer< FulfillsConstraint< MatcherType > > + { + static std::string ToString(const FulfillsConstraint<MatcherType>& constraint) + { + std::ostringstream builder; + builder << snowhouse::Stringize(constraint.m_matcher); + + return builder.str(); + } + }; + +} + +#endif diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/haslengthconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/haslengthconstraint.h new file mode 100644 index 00000000..fb6e7cc9 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/haslengthconstraint.h @@ -0,0 +1,60 @@ +
+// 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_HASLENGTHCONSTRAINT_H
+#define IGLOO_HASLENGTHCONSTRAINT_H
+
+#include "./expressions/expression.h"
+
+namespace snowhouse {
+
+ template <typename ExpectedType>
+ struct HasLengthConstraint : Expression< HasLengthConstraint<ExpectedType> >
+ {
+ HasLengthConstraint(const ExpectedType& expected)
+ : m_expected(expected) {}
+
+ template <typename ActualType>
+ bool operator()(const ActualType& actual) const
+ {
+ typedef typename ActualType::size_type SizeType;
+ SizeType expectedSize = static_cast<SizeType>(m_expected);
+ return (actual.size() == expectedSize);
+ }
+
+ ExpectedType m_expected;
+ };
+
+ template< typename ExpectedType >
+ inline HasLengthConstraint<ExpectedType> HasLength(const ExpectedType& expected)
+ {
+ return HasLengthConstraint<ExpectedType>(expected);
+ }
+
+ inline HasLengthConstraint<int> IsEmpty()
+ {
+ return HasLength<int>(0);
+ }
+
+ inline HasLengthConstraint<std::string> HasLength(const char* expected)
+ {
+ return HasLengthConstraint<std::string>(expected);
+ }
+
+ template< typename ExpectedType >
+ struct Stringizer< HasLengthConstraint< ExpectedType > >
+ {
+ static std::string ToString(const HasLengthConstraint<ExpectedType>& constraint)
+ {
+ std::ostringstream builder;
+ builder << "of length " << snowhouse::Stringize(constraint.m_expected);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/isgreaterthanconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/isgreaterthanconstraint.h new file mode 100644 index 00000000..e7ef01f8 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/isgreaterthanconstraint.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_ISGREATERTHANCONSTRAINT_H
+#define IGLOO_ISGREATERTHANCONSTRAINT_H
+
+#include "./expressions/expression.h"
+
+namespace snowhouse {
+
+ template< typename ExpectedType >
+ struct IsGreaterThanConstraint : Expression< IsGreaterThanConstraint<ExpectedType> >
+ {
+ IsGreaterThanConstraint(const ExpectedType& expected)
+ : m_expected(expected)
+ {
+ }
+
+ template<typename ActualType>
+ bool operator()(const ActualType& actual) const
+ {
+ return (actual > m_expected);
+ }
+
+ ExpectedType m_expected;
+ };
+
+ template< typename ExpectedType >
+ inline IsGreaterThanConstraint<ExpectedType> IsGreaterThan(const ExpectedType& expected)
+ {
+ return IsGreaterThanConstraint<ExpectedType>(expected);
+ }
+
+ inline IsGreaterThanConstraint<std::string> IsGreaterThan(const char* expected)
+ {
+ return IsGreaterThanConstraint<std::string>(expected);
+ }
+
+ template< typename ExpectedType >
+ struct Stringizer< IsGreaterThanConstraint< ExpectedType > >
+ {
+ static std::string ToString(const IsGreaterThanConstraint<ExpectedType>& constraint)
+ {
+ std::ostringstream builder;
+ builder << "greater than " << snowhouse::Stringize(constraint.m_expected);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/islessthanconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/islessthanconstraint.h new file mode 100644 index 00000000..7379dcf7 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/islessthanconstraint.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_ISLESSTHANCONSTRAINT_H
+#define IGLOO_ISLESSTHANCONSTRAINT_H
+
+#include "./expressions/expression.h"
+
+namespace snowhouse {
+
+ template< typename ExpectedType >
+ struct IsLessThanConstraint : Expression< IsLessThanConstraint<ExpectedType> >
+ {
+ IsLessThanConstraint(const ExpectedType& expected)
+ : m_expected(expected)
+ {
+ }
+
+ template<typename ActualType>
+ bool operator()(const ActualType& actual) const
+ {
+ return (actual < m_expected);
+ }
+
+ ExpectedType m_expected;
+ };
+
+ template< typename ExpectedType >
+ inline IsLessThanConstraint<ExpectedType> IsLessThan(const ExpectedType& expected)
+ {
+ return IsLessThanConstraint<ExpectedType>(expected);
+ }
+
+ inline IsLessThanConstraint<std::string> IsLessThan(const char* expected)
+ {
+ return IsLessThanConstraint<std::string>(expected);
+ }
+
+ template< typename ExpectedType >
+ struct Stringizer< IsLessThanConstraint< ExpectedType > >
+ {
+ static std::string ToString(const IsLessThanConstraint<ExpectedType>& constraint)
+ {
+ std::ostringstream builder;
+ builder << "less than " << snowhouse::Stringize(constraint.m_expected);
+
+ return builder.str();
+ }
+ };
+}
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/startswithconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/startswithconstraint.h new file mode 100644 index 00000000..ffdd1696 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/startswithconstraint.h @@ -0,0 +1,52 @@ +
+// 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_STARTSWITHCONSTRAINT_H
+#define IGLOO_STARTSWITHCONSTRAINT_H
+
+#include "./expressions/expression.h"
+
+namespace snowhouse {
+
+ template <typename ExpectedType>
+ struct StartsWithConstraint : Expression< StartsWithConstraint<ExpectedType> >
+ {
+ StartsWithConstraint(const ExpectedType& expected)
+ : m_expected(expected) {}
+
+ bool operator()(const std::string& actual) const
+ {
+ return actual.find(m_expected) == 0;
+ }
+
+ ExpectedType m_expected;
+ };
+
+ template< typename ExpectedType >
+ inline StartsWithConstraint<ExpectedType> StartsWith(const ExpectedType& expected)
+ {
+ return StartsWithConstraint<ExpectedType>(expected);
+ }
+
+ inline StartsWithConstraint<std::string> StartsWith(const char* expected)
+ {
+ return StartsWithConstraint<std::string>(expected);
+ }
+
+ template< typename ExpectedType >
+ struct Stringizer< StartsWithConstraint< ExpectedType > >
+ {
+ static std::string ToString(const StartsWithConstraint<ExpectedType>& constraint)
+ {
+ std::ostringstream builder;
+ builder << "starts with " << snowhouse::Stringize(constraint.m_expected);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/exceptions.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/exceptions.h new file mode 100644 index 00000000..03b879ef --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/exceptions.h @@ -0,0 +1,81 @@ + +// 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_EXCEPTIONS_H +#define IGLOO_EXCEPTIONS_H + +#include "assert.h" + +namespace snowhouse { + + template <typename ExceptionType> + class ExceptionStorage + { + public: + static std::auto_ptr<ExceptionType>& last_exception() + { + static std::auto_ptr<ExceptionType> last; + return last; + } + + void compiler_thinks_i_am_unused() {} + + ~ExceptionStorage() + { + last_exception().reset(NULL); + } + }; + + template <typename ExceptionType> + inline ExceptionType& LastException() + { + if(ExceptionStorage<ExceptionType>::last_exception().get() == NULL) + { + Assert::Failure("No exception was stored"); + } + + return *(ExceptionStorage<ExceptionType>::last_exception().get()); + } +} + +#define IGLOO_CONCAT2(a, b) a##b +#define IGLOO_CONCAT(a, b) IGLOO_CONCAT2(a, b) + +#define AssertThrows(EXCEPTION_TYPE, METHOD) \ +ExceptionStorage<EXCEPTION_TYPE> IGLOO_CONCAT(IGLOO_storage_, __LINE__); IGLOO_CONCAT(IGLOO_storage_, __LINE__).compiler_thinks_i_am_unused(); \ +{ \ + bool wrong_exception = false; \ + bool no_exception = false; \ + try \ + { \ + METHOD; \ + no_exception = true; \ + } \ + catch (const EXCEPTION_TYPE& e) \ + { \ + ExceptionStorage<EXCEPTION_TYPE>::last_exception() = std::auto_ptr<EXCEPTION_TYPE>(new EXCEPTION_TYPE(e)); \ + } \ + catch(...) \ + { \ + wrong_exception = true; \ + } \ + if(no_exception) \ + { \ + std::ostringstream stm; \ + stm << "Expected " << #EXCEPTION_TYPE << ". No exception was thrown."; \ + Assert::Failure(stm.str()); \ + } \ + if(wrong_exception) \ + { \ + std::ostringstream stm; \ + stm << "Expected " << #EXCEPTION_TYPE << ". Wrong exception was thrown."; \ + Assert::Failure(stm.str()); \ + } \ +} + +#endif + + 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..20bf1358 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/expressionbuilder.h @@ -0,0 +1,323 @@ + +// 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 + +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); + } + + 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<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<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..cc9a3aef --- /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 "../../../assertionexception.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 AssertionException(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..31c19b50 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/fluent/operators/constraintoperator.h @@ -0,0 +1,79 @@ + +// 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 + +namespace snowhouse { + + struct InvalidExpressionException + { + InvalidExpressionException(const std::string& message) : m_message(message) + { + } + + const std::string& Message() const + { + return m_message; + } + + std::string m_message; + }; + + struct ConstraintOperator + { + virtual ~ConstraintOperator() {} + + 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/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 diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/snowhouse.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/snowhouse.h new file mode 100644 index 00000000..4c36968e --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/snowhouse.h @@ -0,0 +1,24 @@ +#ifndef _SNOWHOUSE_H_JK_2013_06_28 +#define _SNOWHOUSE_H_JK_2013_06_28 + +#define SNOWHOUSE_VERSION "1.0.2" + +#include <iostream> +#include <map> +#include <vector> +#include <sstream> +#include <stack> +#include <list> +#include <memory> +#include <algorithm> + +#include "stringize.h" +#include "constraints/constraints.h" +#include "fluent/fluent.h" +#include "assertionexception.h" +#include "assert.h" +#include "assertmacro.h" +#include "exceptions.h" + +#endif + diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/stringize.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/stringize.h new file mode 100644 index 00000000..ba2a0175 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/stringize.h @@ -0,0 +1,90 @@ +
+// 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_STRINGIZE_H
+#define IGLOO_STRINGIZE_H
+
+namespace snowhouse {
+ namespace detail {
+
+ // This type soaks up any implicit conversions and makes the following operator<<
+ // less preferred than any other such operator found via ADL.
+ struct any
+ {
+ // Conversion constructor for any type.
+ template <class T>
+ any(T const&);
+ };
+
+ // A tag type returned by operator<< for the any struct in this namespace
+ // when T does not support <<.
+ struct tag {};
+
+ // Fallback operator<< for types T that don't support <<.
+ tag operator<<(std::ostream&, any const&);
+
+ // Two overloads to distinguish whether T supports a certain operator expression.
+ // The first overload returns a reference to a two-element character array and is chosen if
+ // T does not support the expression, such as <<, whereas the second overload returns a char
+ // directly and is chosen if T supports the expression. So using sizeof(check(<expression>))
+ // returns 2 for the first overload and 1 for the second overload.
+ typedef char yes;
+ typedef char (&no)[2];
+
+ no check(tag);
+
+ template <class T>
+ yes check(T const&);
+
+ template <class T>
+ struct is_output_streamable
+ {
+ static const T& x;
+ static const bool value = sizeof(check(std::cout << x)) == sizeof(yes);
+ };
+
+ template<typename T, bool type_is_streamable>
+ struct DefaultStringizer
+ {
+ static std::string ToString(const T& value)
+ {
+ std::ostringstream buf;
+ buf << value;
+ return buf.str();
+ }
+ };
+
+ template<typename T>
+ struct DefaultStringizer<T, false>
+ {
+ static std::string ToString(const T&)
+ {
+ return "[unsupported type]";
+ }
+ };
+ }
+
+ template<typename T>
+ struct Stringizer;
+
+ template<typename T>
+ std::string Stringize(const T& value)
+ {
+ return Stringizer<T>::ToString(value);
+ }
+
+ // NOTE: Specialize snowhouse::Stringizer to customize assertion messages
+ template<typename T>
+ struct Stringizer
+ {
+ static std::string ToString(const T& value)
+ {
+ return detail::DefaultStringizer< T, detail::is_output_streamable<T>::value >::ToString(value);
+ }
+ };
+}
+
+#endif
diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/stringizers.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/stringizers.h new file mode 100644 index 00000000..79a416de --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/stringizers.h @@ -0,0 +1,60 @@ +
+// 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_STRINGIZERS_H
+#define IGLOO_STRINGIZERS_H
+
+namespace snowhouse
+{
+
+ namespace detail
+ {
+
+ template<typename Container>
+ struct SequentialContainerStringizer
+ {
+ static std::string
+ ToString(const Container& cont)
+ {
+ std::ostringstream stm;
+ typedef typename Container::const_iterator Iterator;
+
+ stm << "[ ";
+ for (Iterator it = cont.begin(); it != cont.end();)
+ {
+ stm << snowhouse::Stringize(*it);
+
+ if (++it != cont.end())
+ {
+ stm << ", ";
+ }
+ }
+ stm << " ]";
+ return stm.str();
+ }
+ };
+ }
+
+ template<typename T>
+ struct Stringizer<std::vector<T> > : detail::SequentialContainerStringizer<
+ std::vector<T> >
+ {
+ };
+
+ template<typename T>
+ struct Stringizer<std::deque<T> > : detail::SequentialContainerStringizer<
+ std::deque<T> >
+ {
+ };
+
+ template<typename T>
+ struct Stringizer<std::list<T> > : detail::SequentialContainerStringizer<
+ std::list<T> >
+ {
+ };
+}
+
+#endif
|