diff options
Diffstat (limited to 'vendor/bandit/bandit/assertion_frameworks/snowhouse')
59 files changed, 4450 insertions, 0 deletions
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..ea43226b --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/CMakeLists.txt @@ -0,0 +1,49 @@ +cmake_minimum_required(VERSION 2.8) + +project(snowhouse) + +option(SNOWHOUSE_BUILD_TESTS "Build the Snowhouse tests" ON) +option(SNOWHOUSE_RUN_TESTS "Run the Snowhouse tests" ON) +option(SNOWHOUSE_IS_CPP11 "Whether to build this as a C++11 project" OFF) + +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") + +if(SNOWHOUSE_IS_CPP11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdeprecated") + + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() + endif() + + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() + + if (CMAKE_HOST_APPLE AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") + endif() +endif() + +message(${CMAKE_CXX_FLAGS}) + +if (SNOWHOUSE_BUILD_TESTS) + FILE(GLOB SnowhouseSpecSourceFiles example/*.cpp) + add_executable(snowhouse-tests ${SnowhouseSpecSourceFiles}) +endif() + +if (SNOWHOUSE_BUILD_TESTS AND SNOWHOUSE_RUN_TESTS) + add_custom_command(TARGET snowhouse-tests + POST_BUILD + COMMAND snowhouse-tests + WORKING_DIRECTORY ./bin) +elseif (SNOWHOUSE_RUN_TESTS) + message(WARNING "Unable to run snowhouse tests - set:\n option(SNOWHOUSE_BUILD_TESTS, \"Build the Snowhouse tests\" ON)\nand clear your CMakeCache.txt") +endif() diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/LICENSE_1_0.txt b/vendor/bandit/bandit/assertion_frameworks/snowhouse/LICENSE_1_0.txt new file mode 100644 index 00000000..36b7cd93 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/LICENSE_1_0.txt @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. 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..ecd6e039 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/README.md @@ -0,0 +1,419 @@ +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)); +``` + +####GreaterThanOrEqualTo Constraint + +Used to verify that actual is greater than or equal to a value. + +```cpp +AssertThat(x, IsGreaterThanOrEqualTo(5)); +AssertThat(x, Is().GreaterThanOrEqualTo(5)); +``` + +####LessThanOrEqualTo Constraint + +Used to verify that actual is less than or equal to a value. + +```cpp +AssertThat(x, IsLessThanOrEqualTo(6)); +AssertThat(x, Is().LessThanOrEqualTo(6)); +``` + +### Pointer Constraints + +Used to check for `nullptr` equality. + +```cpp +AssertThat(x, IsNull()); +AssertThat(x, Is().Null()); +``` + +### 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 +AssertThat(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. + +##Getting better output for your types + +Whenever Snowhouse prints an error message for a type, it will use the stream operator for that type, otherwise it will print "[unsupported type]" +as a placeholder. + +```cpp +struct MyType { /*...*/ }; + +AssertThat(myType, Fulfills(MyConstraint()); +``` + +Will output the following if the constraint fails: + +```bash +Expected: To fulfill my constraint +Actual: [unsupported type] +``` + +If we add a stream operator: + +```cpp +std::ostream& operator<<(std::ostream& stream, const MyType& a) +{ + stream << "MyType( x = " << a.x << " )"; + return stream; +} +``` + +the output will be a bit more readable: + +```bash +Expected: To fullfill my constraint +Actual: MyType( x = 23 ) +``` + +##Configurable Failure Handlers + +You can provide Snowhouse with custom failure handlers, for example to call `std::terminate` instead of throwing an exception. See `DefaultFailureHandler` for an example of a failure handler. You can derive your own macros with custom failure handlers using `SNOWHOUSE_ASSERT_THAT` and `SNOWHOUSE_ASSERT_THROWS`. See the definitions of `AssertThat` and `AssertThrows` for examples of these. Define `SNOWHOUSE_NO_MACROS` to disable the unprefixed macros `AssertThat` and `AssertThrows`. + +### Example Use Cases + +#### Assert Program State + +Log an error immediately as we may crash if we try to continue. Don't attempt to unwind the stack as we may be inside a destructor or `nothrow` function. We may want to call `std::terminate`, or attempt to muddle along with the rest of the program. + +#### Assert Program State in Safe Builds + +As above, but only in debug builds. + +#### Test Assert + +Assert that a test behaved as expected. Throw an exception and let our testing framework deal with the test failure. + diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/cross_compile.sh b/vendor/bandit/bandit/assertion_frameworks/snowhouse/cross_compile.sh new file mode 100755 index 00000000..d3a73279 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/cross_compile.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +STATUS="" + +function build_for { + local CC=$1 + local CXX=$2 + local CXX_VERSION=$3 + + echo "Compiling for $CC, $CXX, $CXX_VERSION..." + + if [[ "$CXX_VERSION" == "CXX" ]]; then + local SNOWHOUSE_IS_CPP11=OFF + else + local SNOWHOUSE_IS_CPP11=ON + fi + + echo "SNOWHOUSE_IS_CPP11=$SNOWHOUSE_IS_CPP11" + + BUILD_DIR=build-$CC-$CXX_VERSION + mkdir $BUILD_DIR + pushd $BUILD_DIR + CC=$CC CXX=$CXX cmake -DSNOWHOUSE_IS_CPP11=$SNOWHOUSE_IS_CPP11 ../.. + make + STATUS="$STATUS\n$BUILD_DIR - Status: $?" + popd +} + +if [[ -d builds ]]; then + rm -rf builds +fi + +mkdir builds +pushd builds + +build_for gcc-4.5 g++-4.5 CXX +build_for gcc-4.6 g++-4.6 CXX +build_for gcc-4.6 g++-4.6 CXX11 +build_for gcc-4.7 g++-4.7 CXX +build_for gcc-4.7 g++-4.7 CXX11 +build_for gcc-4.8 g++-4.8 CXX +build_for gcc-4.8 g++-4.8 CXX11 +build_for gcc-4.9 g++-4.9 CXX +build_for gcc-4.9 g++-4.9 CXX11 +build_for clang clang++ CXX +build_for clang clang++ CXX11 +popd + +echo "============================================" +echo -e $STATUS diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/basic_assertions.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/basic_assertions.cpp new file mode 100644 index 00000000..2766ec0a --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/basic_assertions.cpp @@ -0,0 +1,228 @@ +#include <stdexcept> +#include <sstream> +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +void throwRuntimeError() { + throw std::runtime_error("This is expected"); +} + +struct IgnoreErrors { + template <class ExpectedType, class ActualType> + static void Handle(const ExpectedType&, const ActualType&, const char*, int) + { + } + + static void Handle(const std::string&) + { + } +}; + +void BasicAssertions() +{ + std::cout << "================================================" << std::endl; + std::cout << " ASSERTIONS " << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleIntegerEquality" << std::endl; + { + Assert::That(5, Is().EqualTo(5)); + } + + std::cout << "ShouldDetectIntegerInequality" << std::endl; + { + AssertTestFails(Assert::That(5, Is().EqualTo(4)), "equal to 4"); + } + + std::cout << "ShouldDetectIfNotFails" << std::endl; + { + AssertTestFails(Assert::That(5, Is().Not().EqualTo(5)), "Expected: not equal to 5\nActual: 5\n"); + } + + std::cout << "ShouldHandleStrings" << std::endl; + { + Assert::That(std::string("joakim"), Is().EqualTo(std::string("joakim"))); + } + + std::cout << "ShouldHandleStringsWithoutExplicitTemplateSpecialization" << std::endl; + { + Assert::That("kim", Is().EqualTo("kim")); + } + + std::cout << "ShouldHandleGreaterThan" << std::endl; + { + Assert::That(5, Is().GreaterThan(4)); + } + + std::cout << "ShouldDetectWhenGreaterThanFails" << std::endl; + { + AssertTestFails(Assert::That(5, Is().GreaterThan(5)), + "Expected: greater than 5\nActual: 5\n"); + } + + std::cout << "ShouldHandleLessThan" << std::endl; + { + Assert::That(5, Is().LessThan(6)); + } + + std::cout << "ShouldDetectWhenLessThanFails" << std::endl; + { + AssertTestFails(Assert::That(6, Is().LessThan(5)), + "Expected: less than 5\nActual: 6\n"); + } + + std::cout << "ShouldThrowExplicitFailureMessage" << std::endl; + { + AssertTestFails(Assert::Failure("foo"), "foo"); + } + + std::cout << "Should contain location information" << std::endl; + { + int line; + std::string file; + + try + { + Assert::That(5, Equals(2), "filename", 32); + } + catch(const AssertionException& e) + { + line = e.GetLineNumber(); + file = e.GetFilename(); + } + + Assert::That(line, Equals(32)); + Assert::That(file, Equals("filename")); + } + + std::cout << "ShouldEnsureExceptionIsThrown" << std::endl; + { + + AssertThrows(std::runtime_error, throwRuntimeError()); + } + + std::cout << "ShouldIgnoreTheError" << std::endl; + { + ConfigurableAssert<IgnoreErrors>::That(1, Equals(2)); + } + + std::cout << "================================================" << std::endl; + std::cout << " ASSERTIONS EXPRESSION TEMPLATES" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleIntegerEquality" << std::endl; + { + Assert::That(5, Equals(5)); + } + + std::cout << "ShouldDetectIntegerInequality" << std::endl; + { + AssertTestFails(Assert::That(5, Equals(4)), "equal to 4"); + } + + std::cout << "ShouldDetectIfNotFails" << std::endl; + { + AssertTestFails(Assert::That(5, !Equals(5)), + "Expected: not equal to 5\nActual: 5\n"); + } + + std::cout << "ShouldHandleStrings" << std::endl; + { + Assert::That(std::string("joakim"), Equals(std::string("joakim"))); + } + + std::cout << "ShouldHandleStringsWithoutExplicitTemplateSpecialization" + << std::endl; + { + Assert::That("kim", Equals("kim")); + } + + std::cout << "ShouldHandleGreaterThan" << std::endl; + { + Assert::That(5, IsGreaterThan(4)); + } + + std::cout << "ShouldHandleGreaterThanOrEqualTo" << std::endl; + { + Assert::That(4, IsGreaterThanOrEqualTo(4)); + Assert::That(5, IsGreaterThanOrEqualTo(4)); + } + + std::cout << "ShouldDetectWhenGreaterThanFails" << std::endl; + { + AssertTestFails(Assert::That(5, IsGreaterThan(5)), + "Expected: greater than 5\nActual: 5\n"); + } + + std::cout << "ShouldDetectWhenGreaterThanOrEqualToFails" << std::endl; + { + AssertTestFails(Assert::That(4, IsGreaterThanOrEqualTo(5)), + "Expected: greater than or equal to 5\nActual: 4\n"); + } + + std::cout << "ShouldHandleLessThan" << std::endl; + { + Assert::That(5, IsLessThan(6)); + } + + std::cout << "ShouldHandleLessThanOrEqualTo" << std::endl; + { + Assert::That(5, IsLessThanOrEqualTo(6)); + Assert::That(6, IsLessThanOrEqualTo(6)); + } + + std::cout << "ShouldDetectWhenLessThanFails" << std::endl; + { + AssertTestFails(Assert::That(6, IsLessThan(5)), + "Expected: less than 5\nActual: 6\n"); + } + + std::cout << "ShouldDetectWhenLessThanOrEqualToFails" << std::endl; + { + AssertTestFails(Assert::That(6, IsLessThanOrEqualTo(5)), + "Expected: less than or equal to 5\nActual: 6\n"); + } + +#if __cplusplus > 199711L + std::cout << "ShouldHandleNull" << std::endl; + { + Assert::That(nullptr, IsNull()); + } + + std::cout << "ShouldHandleNull" << std::endl; + { + Assert::That(nullptr, Is().Null()); + } + + std::cout << "ShouldHandleNotNull" << std::endl; + { + int anInt = 0; + Assert::That(&anInt, ! IsNull()); + } + + std::cout << "ShouldDetectWhenIsNullFails" << std::endl; + { + int anInt = 0; + std::ostringstream message; + message << "Expected: equal to nullptr\nActual: " << &anInt << "\n"; + AssertTestFails(Assert::That(&anInt, IsNull()), message.str()); + } + + std::cout << "ShouldDetectWhenIsNullFails" << std::endl; + { + int anInt = 0; + std::ostringstream message; + message << "Expected: equal to nullptr\nActual: " << &anInt << "\n"; + AssertTestFails(Assert::That(&anInt, Is().Null()), message.str()); + } + + std::cout << "ShouldDetectWhenIsNotNullFails" << std::endl; + { + std::ostringstream message; + message << "Expected: not equal to nullptr\nActual: nullptr\n"; + + AssertTestFails(Assert::That(nullptr, ! IsNull()), message.str()); + } +#endif +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/boolean_operators.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/boolean_operators.cpp new file mode 100644 index 00000000..3e4577a5 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/boolean_operators.cpp @@ -0,0 +1,48 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +void BooleanOperators() +{ + std::cout << "================================================" << std::endl; + std::cout << " Boolean operators" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleIsFalseOperator" << std::endl; + { + Assert::That(false, IsFalse()); + } + + std::cout << "ShouldHandleWhenIsFalseFails" << std::endl; + { + AssertTestFails(Assert::That(true, IsFalse()), "Expected: false"); + } + + std::cout << "ShouldHandleIsTrueOperator" << std::endl; + { + Assert::That(true, IsTrue()); + } + + std::cout << "ShouldHandleWhenIsTrueFails" << std::endl; + { + AssertTestFails(Assert::That(false, IsTrue()), "Expected: true"); + } + + std::cout << "ShouldHandleFluentIsTrue" << std::endl; + { + Assert::That(true, Is().True()); + AssertTestFails(Assert::That(false, Is().True()), "Expected: true"); + } + + std::cout << "ShouldHandleFluentIsFalse" << std::endl; + { + Assert::That(false, Is().False()); + AssertTestFails(Assert::That(true, Is().False()), "Expected: false"); + } + + std::cout << "ShouldTreatAssertWithoutConstraintAsBooleanConstrains" << std::endl; + { + Assert::That(true); + } +} + diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/container_spec.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/container_spec.cpp new file mode 100644 index 00000000..c668dffa --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/container_spec.cpp @@ -0,0 +1,85 @@ + +// Copyright Joakim Karlsson & Kim Gräsman 2010-2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +struct my_type +{ + my_type(int my_val) + : my_val_(my_val) + {} + + friend bool operator==(const my_type&, const my_type&); + friend bool operator!=(const my_type&, const my_type&); + friend std::ostream& operator<<(std::ostream&, const my_type&); + + int my_val_; +}; + +bool operator==(const my_type& lhs, const my_type& rhs) +{ + return lhs.my_val_ == rhs.my_val_; +} + +bool operator!=(const my_type& lhs, const my_type& rhs) +{ + return !(lhs == rhs); +} + +std::ostream& operator<<(std::ostream& stream, const my_type& item) +{ + stream << "(my_type: my_val_=" << item.my_val_ << " )"; + return stream; +} + +static bool are_my_types_equal(const my_type& lhs, const my_type& rhs) +{ + return lhs.my_val_ == rhs.my_val_; +} + +void ContainerConstraints() +{ + std::cout << "================================================" << std::endl; + std::cout << " ContainerContstraints" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "it_should_be_able_to_compare_containers_of_custom_types" << std::endl; + { + const my_type e[] = {my_type(1), my_type(3)}; + const std::list<my_type> expected(e, e + sizeof(e) / sizeof(e[0])); + std::list<my_type> my_container_; + my_container_.push_back(my_type(1)); + my_container_.push_back(my_type(3)); + + AssertThat(my_container_, EqualsContainer(expected)); + } + + std::cout << "it_should_handle_failing_comparisons" << std::endl; + { + const my_type e[] = {my_type(1), my_type(2)}; + const std::list<my_type> expected(e, e + sizeof(e) / sizeof(e[0])); + std::list<my_type> my_container_; + my_container_.push_back(my_type(1)); + my_container_.push_back(my_type(3)); + + AssertTestFails(Assert::That(my_container_, EqualsContainer(expected)), + "Expected: [ (my_type: my_val_=1 ), (my_type: my_val_=2 ) ]"); + } + + std::cout << "it_should_handle_comparison_with_a_predicate_function" << std::endl; + { + const my_type e[] = {my_type(1), my_type(3)}; + const std::list<my_type> expected(e, e + sizeof(e) / sizeof(e[0])); + std::list<my_type> my_container_; + my_container_.push_back(my_type(1)); + my_container_.push_back(my_type(3)); + + Assert::That(my_container_, EqualsContainer(expected, are_my_types_equal)); + Assert::That(my_container_, Is().EqualToContainer(expected, are_my_types_equal)); + } +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp new file mode 100644 index 00000000..c5437f9f --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/custom_matchers_test.cpp @@ -0,0 +1,69 @@ + +// Copyright Joakim Karlsson & Kim Gräsman 2010-2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +struct IsEvenNumberNoStreamOperator +{ + bool Matches(const int actual) const + { + return (actual % 2) == 0; + } +}; + +struct IsEvenNumberWithStreamOperator +{ + bool Matches(const int actual) const + { + return (actual % 2) == 0; + } + + friend std::ostream& operator<<(std::ostream& stm, + const IsEvenNumberWithStreamOperator& ); +}; + +std::ostream& operator<<(std::ostream& stm, + const IsEvenNumberWithStreamOperator& ) +{ + stm << "An even number"; + return stm; +} + +void CustomMatchers() +{ + std::cout << "================================================" << std::endl; + std::cout << " CustomMatchersNoStreamOperator" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "CanHandleCustomMatcher" << std::endl; + { + Assert::That(2, Fulfills(IsEvenNumberNoStreamOperator())); + } + + std::cout << "CustomMatcherWithFluent" << std::endl; + { + Assert::That(2, Is().Fulfilling(IsEvenNumberNoStreamOperator())); + } + + std::cout << "OutputsCorrectMessageWhenFails" << std::endl; + { + AssertTestFails(Assert::That(3, Fulfills(IsEvenNumberNoStreamOperator())), + "Expected: [unsupported type]\nActual: 3"); + } + + + std::cout << "================================================" << std::endl; + std::cout << "CustomMatcherWithStreamOperator" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ErrorMessageUsesCustomStreamOperatorIfAvailable" << std::endl; + { + AssertTestFails(Assert::That(3, Fulfills(IsEvenNumberWithStreamOperator())), + "Expected: An even number\nActual: 3"); + } +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/exceptions_tests.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/exceptions_tests.cpp new file mode 100644 index 00000000..0f1ac2ab --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/exceptions_tests.cpp @@ -0,0 +1,97 @@ + +// Copyright Joakim Karlsson & Kim Gräsman 2010-2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <snowhouse/snowhouse.h> +#include <stdexcept> +using namespace snowhouse; + +#include "tests.h" + +class ClassWithExceptions +{ +public: + int LogicError() + { + throw std::logic_error("not logical!"); + } + + double RangeError() + { + throw std::range_error("range error!"); + } + + void NoError() + { + } +}; + +void ExceptionTests() +{ + ClassWithExceptions objectUnderTest; + + std::cout << "================================================" << std::endl; + std::cout << " ExceptionTests" << std::endl; + std::cout << "================================================" << std::endl; + + + std::cout << "CanDetectExceptions" << std::endl; + { + AssertThrows(std::exception, objectUnderTest.LogicError()); + } + + std::cout << "CanAssertOnLastException" << std::endl; + { + AssertThrows(std::logic_error, objectUnderTest.LogicError()); + Assert::That(LastException<std::logic_error>().what(), Contains("not logical!")); + } + + std::cout << "CanDetectWhenWrongExceptionIsThrown" << std::endl; + { + AssertTestFails(AssertThrows(std::logic_error, objectUnderTest.RangeError()), "Wrong exception"); + } + + std::cout << "CanPrintExpectedExceptionTypeWhenWrongExceptionIsThrown" << std::endl; + { + AssertTestFails(AssertThrows(std::logic_error, objectUnderTest.RangeError()), "Expected std::logic_error"); + } + + std::cout << "CanHaveSeveralExceptionAssertionsInSameSpec" << std::endl; + { + AssertThrows(std::logic_error, objectUnderTest.LogicError()); + Assert::That(LastException<std::logic_error>().what(), Contains("not logical!")); + + AssertThrows(std::range_error, objectUnderTest.RangeError()); + Assert::That(LastException<std::range_error>().what(), Contains("range error!")); + } + + std::cout << "CanHaveSeveralExceptionAssertionForTheSameExceptionInSameSpec" << std::endl; + { + AssertThrows(std::logic_error, objectUnderTest.LogicError()); + Assert::That(LastException<std::logic_error>().what(), Contains("not logical!")); + + AssertThrows(std::logic_error, objectUnderTest.LogicError()); + Assert::That(LastException<std::logic_error>().what(), Contains("not logical!")); + } + + std::cout << "CanDetectWhenNoExceptionIsThrown" << std::endl; + { + AssertTestFails(AssertThrows(std::logic_error, objectUnderTest.NoError()), "No exception"); + } + + std::cout << "CanPrintExpectedExceptionWhenNoExceptionIsThrown" << std::endl; + { + AssertTestFails(AssertThrows(std::logic_error, objectUnderTest.NoError()), "Expected std::logic_error"); + } + + std::cout << "ExceptionsAreDestoryedWhenWeExitScope" << std::endl; + { + { + AssertThrows(std::logic_error, objectUnderTest.LogicError()); + } + AssertThrows(AssertionException, LastException<std::logic_error>()); + Assert::That(LastException<AssertionException>().GetMessage(), Contains("No exception was stored")); + } +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/expression_error_handling.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/expression_error_handling.cpp new file mode 100644 index 00000000..de96f038 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/expression_error_handling.cpp @@ -0,0 +1,28 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +void ExpressionErrorHandling() +{ + std::cout << "================================================" << std::endl; + std::cout << " ExpressionErrorHandling" << std::endl; + std::cout << "================================================" << std::endl; + + std::vector<int> collection; + collection.push_back(1); + collection.push_back(2); + collection.push_back(3); + + std::cout << "AnInvalidAllOperationShouldBeReportedProperly" << std::endl; + { + AssertTestFails(Assert::That(collection, Has().All()), + "The expression after \"all\" operator does not yield any result"); + } + + std::cout << "AnInvalidAtLeastOperationShouldBeReportedProperly" << std::endl; + { + AssertTestFails(Assert::That(collection, Has().AtLeast(2)), + "The expression after \"at least 2\" operator does not yield any result"); + } + +} 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..616b97ff --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/main.cpp @@ -0,0 +1,43 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +void BooleanOperators(); +void BasicAssertions(); +void ContainerConstraints(); +void CustomMatchers(); +void ExceptionTests(); +void ExpressionErrorHandling(); +void MapTests(); +void OperatorTests(); +void SequenceContainerTests(); +void StringLineTests(); +void StringTests(); +void StringizeTests(); + +int main() +{ + try + { + BasicAssertions(); + BooleanOperators(); + ContainerConstraints(); + CustomMatchers(); + ExceptionTests(); + ExpressionErrorHandling(); + MapTests(); + OperatorTests(); + SequenceContainerTests(); + StringLineTests(); + StringTests(); + StringizeTests(); + } + catch(const AssertionException& e) + { + std::cout << "Tests failed!" << std::endl; + std::cout << e.GetMessage() << std::endl; + return 1; + } + + return 0; +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/map_tests.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/map_tests.cpp new file mode 100644 index 00000000..813b5011 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/map_tests.cpp @@ -0,0 +1,38 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +void MapTests() +{ + std::cout << "================================================" << std::endl; + std::cout << " MapTests" << std::endl; + std::cout << "================================================" << std::endl; + + std::map<std::string, int> ages; + ages["joakim"] = 38; + ages["maria"] = 36; + ages["hanna"] = 6; + ages["moa"] = 4; + + std::cout << "ContainingShouldDetermineIfKeyExists" << std::endl; + { + Assert::That(ages, Is().Containing("joakim")); + } + + std::cout << "ShouldGiveAProperMessageWhenContainingFails" << std::endl; + { + AssertTestFails(Assert::That(ages, Is().Not().Containing("hanna")), + "Expected: not contains hanna"); + } + + std::cout << "ContainingShouldDetermineIfKeyExists" << std::endl; + { + Assert::That(ages, Contains("joakim")); + } + + std::cout << "ShouldGiveAProperMessageWhenContainingFails" << std::endl; + { + AssertTestFails(Assert::That(ages, !Contains("hanna")), + "Expected: not contains hanna"); + } +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/operator_tests.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/operator_tests.cpp new file mode 100644 index 00000000..3d11ae07 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/operator_tests.cpp @@ -0,0 +1,137 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +void OperatorTests() +{ + std::cout << "================================================" << std::endl; + std::cout << " OperatorTests" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleAndOperatorExpressionTemplates" << std::endl; + { + Assert::That(5, IsLessThan(6) && IsGreaterThan(4)); + } + + std::cout << "ShouldHandleAndOperator" << std::endl; + { + Assert::That(5, Is().LessThan(6).And().GreaterThan(4)); + } + + std::cout << "ShouldHandleAndOperatorFailExpressionTemplates" << std::endl; + { + AssertTestFails(Assert::That(5, IsLessThan(7) && IsGreaterThan(5)), + "less than 7 and greater than 5"); + } + + std::cout << "ShouldHandleAndOperatorFail" << std::endl; + { + AssertTestFails(Assert::That(5, Is().LessThan(7).And().GreaterThan(5)), + "less than 7 and greater than 5"); + } + + std::cout << "ShouldHandleOrOperator" << std::endl; + { + Assert::That(12, Is().LessThan(7).Or().GreaterThan(5)); + } + + std::cout << "ShouldHandleOrOperatorExpressionTemplates" << std::endl; + { + Assert::That(12, IsLessThan(7) || IsGreaterThan(5)); + } + + std::cout << "ShouldHandleOrOperatorFails" << std::endl; + { + AssertTestFails(Assert::That(67, Is().LessThan(12).Or().GreaterThan(99)), + "less than 12 or greater than 99"); + } + + std::cout << "ShouldHandleOrOperatorFailsExpressionTemplates" << std::endl; + { + AssertTestFails(Assert::That(67, IsLessThan(12) || IsGreaterThan(99)), + "less than 12 or greater than 99"); + } + + std::cout << "ShouldHandleNotOperators" << std::endl; + { + Assert::That(5, Is().Not().EqualTo(4)); + } + + std::cout << "ShouldHandleNotOperatorsExpressionTemplates" << std::endl; + { + Assert::That(5, !Equals(4)); + } + + std::cout << "ShouldHandleNotOperatorsFails" << std::endl; + { + AssertTestFails(Assert::That(12, Is().Not().EqualTo(12)), "not equal to 12"); + } + + std::cout << "ShouldHandleNotOperatorsFailsExpressionTemplates" << std::endl; + { + AssertTestFails(Assert::That(12, !Equals(12)), "not equal to 12"); + } + + std::cout << "ShouldHandleNotOperatorsForStrings" << std::endl; + { + Assert::That("joakim", Is().Not().EqualTo("harry")); + } + + std::cout << "ShouldHandleNotOperatorsForStringsExpressionTemplates" << std::endl; + { + Assert::That("joakim", !Equals("harry")); + } + + std::cout << "ShouldHandleBothLeftAndRightAssociativeOperators" << std::endl; + { + Assert::That(5, Is().GreaterThan(4).And().Not().LessThan(3)); + } + + std::cout << "ShouldHandleBothLeftAndRightAssociativeOperatorsExpressionTemplates" << std::endl; + { + Assert::That(5, IsGreaterThan(4)&& !IsLessThan(3)); + } + + std::cout << "MalformedExpressionYieldsError" << std::endl; + { + AssertTestFails(Assert::That(4, Is().Not()), + "The expression contains a not operator without any operand"); + } + + std::cout << + "EqualsWithDeltaOperator_should_fail_for_actual_larger_than_delta" + << std::endl; + { + AssertTestFails(Assert::That(3.9, EqualsWithDelta(3, 0.5)), + "Expected: equal to 3 (+/- 0.5)"); + } + + std::cout << "EqualsWithDeltaOperator_should_fail_for_actual_less_than_delta" << std::endl; + { + AssertTestFails(Assert::That(2.49, EqualsWithDelta(3, 0.5)), + "Expected: equal to 3 (+/- 0.5)"); + } + + std::cout << "EqualsWithDeltaOperator_should_succeed" << std::endl; + { + Assert::That(2, EqualsWithDelta(1.9, 0.1)); + } + + std::cout << "Fluent_equals_with_delta_should_fail_for_actual_larger_than_delta" << std::endl; + { + AssertTestFails(Assert::That(3.9, Is().EqualToWithDelta(3, 0.5)), + "Expected: equal to 3 (+/- 0.5)"); + } + + std::cout << "Fluent_EqualsWithDeltaOperator_should_fail_for_actual_less_than_delta" << std::endl; + { + AssertTestFails(Assert::That(2.49, Is().EqualToWithDelta(3, 0.5)), + "Expected: equal to 3 (+/- 0.5)"); + } + + std::cout << "Fluent_EqualsWithDeltaOperator_should_succeed" << std::endl; + { + Assert::That(2, Is().EqualToWithDelta(1.9, 0.1)); + } + +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/sequence_container_tests.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/sequence_container_tests.cpp new file mode 100644 index 00000000..c090cc58 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/sequence_container_tests.cpp @@ -0,0 +1,192 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + + +template <typename T> +void SequenceContainerActual() +{ + const char* ExpectedActual = "\nActual: [ 1, 2, 3, 5, 8 ]"; + + T container; + container.clear(); + container.push_back(1); + container.push_back(2); + container.push_back(3); + container.push_back(5); + container.push_back(8); + + std::cout << "ShouldHandleAllOperator" << std::endl; + { + Assert::That(container, Has().All().GreaterThan(1).Or().LessThan(4)); + } + + std::cout << "ShouldHandleFailingAllOperator" << std::endl; + { + AssertTestFails(Assert::That(container, Has().All().GreaterThan(4)), std::string("Expected: all greater than 4") + ExpectedActual); + } + + std::cout << "SHouldHandleInvalidExpressionAfterAllOperator" << std::endl; + { + AssertTestFails(Assert::That(container, Has().All().Not()), "The expression contains a not operator without any operand"); + } + + std::cout << "ShouldHandleNoExpressionAfterAllOperator" << std::endl; + { + AssertTestFails(Assert::That(container, Has().All()), "The expression after \"all\" operator does not yield any result"); + } + + std::cout << "ShouldHandleAtLeastOperator" << std::endl; + { + Assert::That(container, Has().AtLeast(1).LessThan(5)); + } + + std::cout << "ShouldHandleFailingAtLeastOperator" << std::endl; + { + AssertTestFails(Assert::That(container, Has().AtLeast(2).LessThan(2)), std::string("Expected: at least 2 less than 2") + ExpectedActual); + } + + std::cout << "ShouldHandleExactlyOperator" << std::endl; + { + Assert::That(container, Has().Exactly(1).EqualTo(3)); + } + + std::cout << "ShouldHandleFailingExactlyOperator" << std::endl; + { + AssertTestFails(Assert::That(container, Has().Exactly(2).EqualTo(3)), std::string("Expected: exactly 2 equal to 3") + ExpectedActual); + } + + std::cout << "ShouldHandleAtMostOperator" << std::endl; + { + Assert::That(container, Has().AtMost(1).EqualTo(5)); + } + + std::cout << "ShouldHandleFailingAtMostOperator" << std::endl; + { + AssertTestFails(Assert::That(container, Has().AtMost(1).EqualTo(3).Or().EqualTo(5)), std::string("Expected: at most 1 equal to 3 or equal to 5") + ExpectedActual); + } + + std::cout << "ShouldHandleNoneOperator" << std::endl; + { + Assert::That(container, Has().None().EqualTo(666)); + } + + std::cout << "ShouldHandleFailingNoneOperator" << std::endl; + { + AssertTestFails(Assert::That(container, Has().None().EqualTo(5)), std::string("Expected: none equal to 5") + ExpectedActual); + } + + std::cout << "ShouldHandleContaining" << std::endl; + { + Assert::That(container, Contains(3)); + } + + std::cout << "ShouldDetectFailingContains" << std::endl; + { + AssertTestFails(Assert::That(container, Contains(99)), std::string("contains 99") + ExpectedActual); + } + + std::cout << "ShouldHandleOfLength" << std::endl; + { + Assert::That(container, HasLength(5)); + } + + std::cout << "ShouldHandleFailingOfLength" << std::endl; + { + AssertTestFails(Assert::That(container, HasLength(7)), std::string("of length 7") + ExpectedActual); + } + + std::cout << "ShouldHandleContaining_ExpressionTemplates" << std::endl; + { + Assert::That(container, Contains(3)); + } + + std::cout << "ShouldDetectFailingContains_ExpressionTemplates" << std::endl; + { + AssertTestFails(Assert::That(container, Contains(99)), std::string("contains 99") + ExpectedActual); + } + + std::cout << "ShouldHandleOfLength_ExpressionTemplates" << std::endl; + { + Assert::That(container, HasLength(5)); + } + + std::cout << "ShouldHandleFailingOfLengthForVectors" << std::endl; + { + AssertTestFails(Assert::That(container, HasLength(7)), std::string("of length 7") + ExpectedActual); + } + + std::cout << "ShouldHandleIsEmpty" << std::endl; + { + T is_empty; + + Assert::That(is_empty, IsEmpty()); + } + + std::cout << "ShouldHandleFailingIsEmpty" << std::endl; + { + AssertTestFails(Assert::That(container, IsEmpty()), "of length 0"); + } + + std::cout << "ShouldHandleFluentIsEmpty" << std::endl; + { + T is_empty; + + Assert::That(is_empty, Is().Empty()); + } + + std::cout << "ShouldHandleFailingFluentIsEmpty" << std::endl; + { + AssertTestFails(Assert::That(container, Is().Empty()), "of length 0"); + } + + std::cout << "ShouldHandlerEqualsContainer" << std::endl; + { + std::list<int> expected; + expected.assign(container.begin(), container.end()); + + AssertThat(container, EqualsContainer(expected)); + } + + std::cout << "ShouldHandleEqualsContainer_Fluent" << std::endl; + { + std::list<int> expected; + expected.assign(container.begin(), container.end()); + + AssertThat(container, Is().EqualToContainer(expected)); + } + + std::cout << "ShouldHandleFailingEqualsContainer" << std::endl; + { + const int e[] = {4, 2, 4}; + std::list<int> expected(e, e + sizeof(e) / sizeof(e[0])); + + AssertTestFails(Assert::That(container, EqualsContainer(expected)), "Expected: [ 4, 2, 4 ]"); + } + + std::cout << "ShouldHandleFailingEqualsContainer_Fluent" << std::endl; + { + const int e[] = {4, 2, 4}; + std::list<int> expected(e, e + sizeof(e) / sizeof(e[0])); + + AssertTestFails(Assert::That(container, Is().EqualToContainer(expected)), "Expected: [ 4, 2, 4 ]"); + } +} + +void SequenceContainerTests() +{ + std::cout << "================================================" << std::endl; + std::cout << " SequenceContainerTests(vector)" << std::endl; + std::cout << "================================================" << std::endl; + SequenceContainerActual<std::vector<int> >(); + + std::cout << "================================================" << std::endl; + std::cout << " SequenceContainerTests(list)" << std::endl; + std::cout << "================================================" << std::endl; + SequenceContainerActual<std::list<int> >(); + + std::cout << "================================================" << std::endl; + std::cout << " SequenceContainerTests(deque)" << std::endl; + std::cout << "================================================" << std::endl; + SequenceContainerActual<std::deque<int> >(); +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/string_line_tests.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/string_line_tests.cpp new file mode 100644 index 00000000..8cf90cfb --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/string_line_tests.cpp @@ -0,0 +1,179 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +void StringLineTests() +{ + std::cout << "================================================" << std::endl; + std::cout << " StringLineTests" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "CanAssertThatAtLeastOneLineInAStreamMatches" << std::endl; + { + Assert::That("First line\n", Has().AtLeast(1).EqualTo("First line")); + } + + std::cout << "CanDetectWhenAssertionFails" << std::endl; + { + AssertTestFails(Assert::That("First line\n", Has().AtLeast(1).EqualTo("Second line")), "Expected: at least 1 equal to Second line"); + } + + std::cout << "CanHandleLineMissingNewline" << std::endl; + { + Assert::That("First line", Has().AtLeast(1).EqualTo("First line")); + } + + std::cout << "CanHandleSeveralLines" << std::endl; + { + std::string lines = "First line\nSecond line"; + Assert::That(lines, Has().Exactly(2).EndingWith("line")); + } + + std::cout << "CanHandleWindowsLineEndings" << std::endl; + { + std::string lines = "First line\r\nSecond line\r\nThird line"; + Assert::That(lines, Has().Exactly(3).EndingWith("line")); + } + + std::cout << "CanMatchBeginningOfLinesWithWindowsLineEndings" << std::endl; + { + std::string lines = "First line\nSecond line\r\nThird line"; + Assert::That(lines, Has().Exactly(1).StartingWith("Second")); + } + + std::cout << "CanHandleEmptyLinesWhenUsingWindowsLineEndings" << std::endl; + { + std::string lines = "\r\nSecond line\r\n\r\n"; + Assert::That(lines, Has().Exactly(2).OfLength(0)); + } + + std::cout << "CanHandleLastLineMissingNewlineForWindowsLineEndings" << std::endl; + { + std::string lines = "First line\r\nSecond line"; + Assert::That(lines, Has().Exactly(2).EndingWith("line")); + } + + std::cout << "CanHandleAllEmptyLines" << std::endl; + { + Assert::That("\n\n\n\n\n\n", Has().Exactly(6).OfLength(0)); + } + + std::cout << "CanHandleAllEmptyLinesWithWindowsLineEndings" << std::endl; + { + Assert::That("\r\n\r\n\r\n", Has().Exactly(3).OfLength(0)); + } + + + std::cout << "================================================" << std::endl; + std::cout << " StringLineParserTests" << std::endl; + std::cout << "================================================" << std::endl; + + + std::cout << "CanParseEmptyString" << std::endl; + { + std::vector<std::string> res; + + StringLineParser::Parse("", res); + + Assert::That(res, HasLength(0)); + } + + std::cout << "CanParseSingleLine" << std::endl; + { + std::vector<std::string> res; + + StringLineParser::Parse("Simple line", res); + + Assert::That(res, HasLength(1)); + Assert::That(res, Has().Exactly(1).EqualTo("Simple line")); + } + + std::cout << "CanParseTwoLines" << std::endl; + { + std::vector<std::string> res; + + StringLineParser::Parse("One line\nTwo lines", res); + + Assert::That(res, HasLength(2)); + Assert::That(res, Has().Exactly(1).EqualTo("One line")); + Assert::That(res, Has().Exactly(1).EqualTo("Two lines")); + } + + std::cout << "CanParseThreeLines" << std::endl; + { + std::vector<std::string> res; + + StringLineParser::Parse("One line\nTwo lines\nThree lines", res); + + Assert::That(res, HasLength(3)); + Assert::That(res, Has().Exactly(1).EqualTo("One line")); + Assert::That(res, Has().Exactly(1).EqualTo("Two lines")); + Assert::That(res, Has().Exactly(1).EqualTo("Three lines")); + } + + std::cout << "CanHandleStringEndingWithNewline" << std::endl; + { + std::vector<std::string> res; + StringLineParser::Parse("One line\n", res); + Assert::That(res, HasLength(1)); + Assert::That(res, Has().Exactly(1).EqualTo("One line")); + } + + std::cout << "CanHandleSingleLineWithWindowsLineEnding" << std::endl; + { + std::vector<std::string> res; + StringLineParser::Parse("One line\r\n", res); + Assert::That(res, HasLength(1)); + Assert::That(res, Has().Exactly(1).EqualTo("One line")); + } + + std::cout << "CanHandleTwoLinesWithWindowsLineEndings" << std::endl; + { + std::vector<std::string> res; + StringLineParser::Parse("One line\r\nTwo lines", res); + Assert::That(res, HasLength(2)); + Assert::That(res, Has().Exactly(1).EqualTo("One line")); + Assert::That(res, Has().Exactly(1).EqualTo("Two lines")); + } + + std::cout << "CanHandleEmptyLineWithNewline" << std::endl; + { + std::vector<std::string> res; + StringLineParser::Parse("\n", res); + Assert::That(res, Is().OfLength(1).And().Exactly(1).OfLength(0)); + } + + std::cout << "CanHandleTwoEmptyLines" << std::endl; + { + std::vector<std::string> res; + StringLineParser::Parse("\n\n", res); + Assert::That(res, HasLength(2)); + Assert::That(res, Has().Exactly(2).OfLength(0)); + } + + std::cout << "CanHandleTwoEmptyLinesWithWindowsLineEndings" << std::endl; + { + std::vector<std::string> res; + StringLineParser::Parse("\r\n\r\n", res); + Assert::That(res, HasLength(2)); + Assert::That(res, Has().Exactly(2).OfLength(0)); + } + + std::cout << "CanHandleCarriageReturnOnly" << std::endl; + { + std::vector<std::string> res; + StringLineParser::Parse("One line\rTwo lines", res); + Assert::That(res, HasLength(2)); + Assert::That(res, Has().Exactly(1).EqualTo("One line")); + Assert::That(res, Has().Exactly(1).EqualTo("Two lines")); + } + + std::cout << "CanHandleCarriageReturnOnlyAtEndOfString" << std::endl; + { + std::vector<std::string> res; + StringLineParser::Parse("One line\r\nTwo lines\r", res); + Assert::That(res, HasLength(2)); + Assert::That(res, Has().Exactly(1).EqualTo("One line")); + Assert::That(res, Has().Exactly(1).EqualTo("Two lines")); + } +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/string_tests.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/string_tests.cpp new file mode 100644 index 00000000..989ad42b --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/string_tests.cpp @@ -0,0 +1,65 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +void StringTests() +{ + std::cout << "================================================" << std::endl; + std::cout << " StringTests" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleStringContainsConstraint" << std::endl; + { + Assert::That("abcdef", Contains("bcde")); + } + + std::cout << "StringConstraintShouldHandleMatchAtBeginningOfString" << std::endl; + { + Assert::That("abcdef", Contains("a")); + } + + std::cout << "ShouldDetectFailingContains" << std::endl; + { + AssertTestFails(Assert::That("abcdef", Contains("hello")), "contains hello"); + } + + std::cout << "ShouldHandleStringStartingWithConstraint" << std::endl; + { + Assert::That("abcdef", StartsWith("abc")); + } + + std::cout << "ShouldHandleStringEndingWithConstraint" << std::endl; + { + Assert::That("abcdef", EndsWith("def")); + } + + std::cout << "ShouldHandleOperatorsForStrings" << std::endl; + { + Assert::That("abcdef", StartsWith("ab") && EndsWith("ef")); + } + + std::cout << "ShouldHandleStringsWithMultipleOperators" << std::endl; + { + Assert::That("abcdef", StartsWith("ab") && !EndsWith("qwqw")); + } + + std::cout << "ShouldHandleOfLength" << std::endl; + { + Assert::That("12345", HasLength(5)); + } + + std::cout << "ShouldHandleWeirdLongExpressions" << std::endl; + { + Assert::That("12345", HasLength(5) && StartsWith("123") && !EndsWith("zyxxy")); + } + + std::cout << "ShouldHandleStdStrings" << std::endl; + { + Assert::That("12345", Contains(std::string("23"))); + } + + std::cout << "ShouldHandleSimpleChar" << std::endl; + { + Assert::That("12345", StartsWith('1')); + } +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/stringize_tests.cpp b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/stringize_tests.cpp new file mode 100644 index 00000000..a0971274 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/stringize_tests.cpp @@ -0,0 +1,111 @@ +#include <snowhouse/snowhouse.h> +using namespace snowhouse; +#include "tests.h" + +namespace +{ + // No overload for operator<<(std::ostream&) or specialization of igloo::Stringizer + struct WithoutStreamOperator + { + WithoutStreamOperator(int id) + : m_id(id) + { + } + + bool operator==(const WithoutStreamOperator& rhs) const + { + return m_id == rhs.m_id; + } + + int m_id; + }; + + // Has operator<<(std::ostream&) + struct WithStreamOperator : public WithoutStreamOperator + { + WithStreamOperator(int id) + : WithoutStreamOperator(id) + { + } + }; + + std::ostream& operator<<(std::ostream& stream, const WithStreamOperator& a) + { + stream << a.m_id; + return stream; + } + + // Has no operator<<(std::ostream&), but a specialization of igloo::Stringizer + struct WithoutStreamOperatorButWithStringizer : public WithoutStreamOperator + { + WithoutStreamOperatorButWithStringizer(int id) + : WithoutStreamOperator(id) + { + } + }; +} + +namespace snowhouse { + + template<> + struct Stringizer< WithoutStreamOperatorButWithStringizer > + { + static std::string ToString(const WithoutStreamOperatorButWithStringizer& value) + { + return snowhouse::Stringize(value.m_id); + } + }; +} + +void StringizeTests() +{ + std::cout << "================================================" << std::endl; + std::cout << " StringizeTests" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleTypesWithStreamOperators" << std::endl; + { + WithStreamOperator a(12); + WithStreamOperator b(13); + AssertTestFails(Assert::That(a, Is().EqualTo(b)), "Expected: equal to 13\nActual: 12"); + } + + std::cout << "ShouldHandleTypesWithoutStreamOperators" << std::endl; + { + WithoutStreamOperator a(12); + WithoutStreamOperator b(13); + AssertTestFails(Assert::That(a, Is().EqualTo(b)), "Expected: equal to [unsupported type]\nActual: [unsupported type]"); + } + + std::cout << "ShouldHandleTypesWithTraits" << std::endl; + { + WithoutStreamOperatorButWithStringizer a(12); + WithoutStreamOperatorButWithStringizer b(13); + AssertTestFails(Assert::That(a, Is().EqualTo(b)), "Expected: equal to 13\nActual: 12"); + } + + std::cout << "================================================" << std::endl; + std::cout << " StringizeTestsExpressionTemplates" << std::endl; + std::cout << "================================================" << std::endl; + + std::cout << "ShouldHandleTypesWithStreamOperators" << std::endl; + { + WithStreamOperator a(12); + WithStreamOperator b(13); + AssertTestFails(Assert::That(a, Equals(b)), "Expected: equal to 13\nActual: 12"); + } + + std::cout << "ShouldHandleTypesWithoutStreamOperators" << std::endl; + { + WithoutStreamOperator a(12); + WithoutStreamOperator b(13); + AssertTestFails(Assert::That(a, Equals(b)), "Expected: equal to [unsupported type]\nActual: [unsupported type]"); + } + + std::cout << "ShouldHandleTypesWithTraits" << std::endl; + { + WithoutStreamOperatorButWithStringizer a(12); + WithoutStreamOperatorButWithStringizer b(13); + AssertTestFails(Assert::That(a, Is().EqualTo(b)), "Expected: equal to 13\nActual: 12"); + } +} diff --git a/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/tests.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/tests.h new file mode 100644 index 00000000..9dd1d28c --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/example/tests.h @@ -0,0 +1,16 @@ +#ifndef SNOWHOUSE_EXAMPLES_TEST_H +#define SNOWHOUSE_EXAMPLES_TEST_H + +#define AssertTestFails(assertion, expected_error_text) \ + std::string IGLOO_INTERNAL_expected_error = "Test did not fail"; \ + try \ + { \ + assertion; \ + } \ + catch(const AssertionException& exception_from_igloo_assertion) \ + { \ + IGLOO_INTERNAL_expected_error = exception_from_igloo_assertion.GetMessage(); \ + } \ + Assert::That(IGLOO_INTERNAL_expected_error, Is().Containing(expected_error_text)); + +#endif 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..64981094 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assert.h @@ -0,0 +1,126 @@ + +// 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 { + + struct DefaultFailureHandler + { + template <class ExpectedType, class ActualType> + static void Handle(const ExpectedType& expected, const ActualType& actual, const char* file_name, int line_number) + { + std::ostringstream str; + + str << "Expected: " << snowhouse::Stringize(expected) << std::endl; + str << "Actual: " << snowhouse::Stringize(actual) << std::endl; + + throw AssertionException(str.str(), file_name, line_number); + } + + static void Handle(const std::string& message) + { + throw AssertionException(message); + } + }; + + template<typename FailureHandler> + class ConfigurableAssert + { + public: + + template <typename ActualType, typename ConstraintListType> + static void That(const ActualType& actual, ExpressionBuilder<ConstraintListType> expression) + { + const char* no_file = ""; + int line_number = 0; + + ConfigurableAssert<FailureHandler>::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()) + { + FailureHandler::Handle(expression, actual, file_name, line_number); + } + } + catch (const InvalidExpressionException& e) + { + FailureHandler::Handle("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)) + { + FailureHandler::Handle(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) + { + FailureHandler::Handle("Expected: true\nActual: false"); + } + } + + static void Failure(const std::string& message) + { + FailureHandler::Handle(message); + } + }; + + typedef ConfigurableAssert<DefaultFailureHandler> Assert; +} + +#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..d0747742 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assertionexception.h @@ -0,0 +1,58 @@ + +// 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) + {} + +#if __cplusplus > 199711L + AssertionException(const AssertionException&) = default; +#endif + +#if __cplusplus > 199711L + virtual ~AssertionException() noexcept + { + } +#else + virtual ~AssertionException() throw() + { + } +#endif + + 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..df5b4b34 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/assertmacro.h @@ -0,0 +1,22 @@ + +// 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 SNOWHOUSE_ASSERT_THAT(p1,p2,FAILURE_HANDLER)\ + ::snowhouse::ConfigurableAssert<FAILURE_HANDLER>::That((p1), (p2), __FILE__, __LINE__);\ + +#ifndef SNOWHOUSE_NO_MACROS + +#define AssertThat(p1,p2)\ + SNOWHOUSE_ASSERT_THAT((p1), (p2), ::snowhouse::DefaultFailureHandler);\ + +#endif // SNOWHOUSE_NO_MACROS + +#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..a12433d1 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/constraints.h @@ -0,0 +1,23 @@ +
+// 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 "isgreaterthanorequaltoconstraint.h"
+#include "islessthanconstraint.h"
+#include "islessthanorequaltoconstraint.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..a47f6bf4 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalsconstraint.h @@ -0,0 +1,83 @@ +
+// Copyright Joakim Karlsson & Kim Gräsman 2010-2012.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef IGLOO_EQUALSCONSTRAINT_H
+#define IGLOO_EQUALSCONSTRAINT_H
+
+#include <cstddef>
+
+#include "./expressions/expression.h"
+
+namespace snowhouse {
+
+ template< typename ExpectedType >
+ struct EqualsConstraint : Expression< EqualsConstraint<ExpectedType> >
+ {
+ EqualsConstraint(const ExpectedType& expected)
+ : m_expected(expected)
+ {
+ }
+
+ template<typename ActualType>
+ bool operator()(const ActualType& actual) const
+ {
+ return (m_expected == actual);
+ }
+
+ ExpectedType m_expected;
+ };
+
+ template< typename ExpectedType >
+ inline EqualsConstraint<ExpectedType> Equals(const ExpectedType& expected)
+ {
+ return EqualsConstraint<ExpectedType>(expected);
+ }
+
+ inline EqualsConstraint<std::string> Equals(const char* expected)
+ {
+ return EqualsConstraint<std::string>(expected);
+ }
+
+ inline EqualsConstraint<bool> IsFalse()
+ {
+ return EqualsConstraint<bool>(false);
+ }
+
+ inline EqualsConstraint<bool> IsTrue()
+ {
+ return EqualsConstraint<bool>(true);
+ }
+
+#if __cplusplus > 199711L
+ inline EqualsConstraint<std::nullptr_t> IsNull()
+ {
+ return EqualsConstraint<std::nullptr_t>(nullptr);
+ }
+#endif
+
+ template <>
+ struct Stringizer< EqualsConstraint< bool > >
+ {
+ static std::string ToString(const EqualsConstraint<bool>& constraint)
+ {
+ return constraint.m_expected ? "true" : "false";
+ }
+ };
+
+ template< typename ExpectedType >
+ struct Stringizer< EqualsConstraint< ExpectedType > >
+ {
+ static std::string ToString(const EqualsConstraint<ExpectedType>& constraint)
+ {
+ std::ostringstream builder;
+ builder << "equal to " << snowhouse::Stringize(constraint.m_expected);
+
+ return builder.str();
+ }
+ };
+}
+
+#endif
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..f8650952 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/equalscontainerconstraint.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_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: + +#if __cplusplus > 199711L +#else + EqualsContainerConstraint& operator=(const EqualsContainerConstraint&) { return *this; } +#endif + + }; + + 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/isgreaterthanorequaltoconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/isgreaterthanorequaltoconstraint.h new file mode 100644 index 00000000..3752887b --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/isgreaterthanorequaltoconstraint.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_ISGREATERTHANOREQUALTOCONSTRAINT_H +#define IGLOO_ISGREATERTHANOREQUALTOCONSTRAINT_H + +#include "./expressions/expression.h" + +namespace snowhouse { + + template< typename ExpectedType > + struct IsGreaterThanOrEqualToConstraint : Expression < IsGreaterThanOrEqualToConstraint<ExpectedType> > + { + IsGreaterThanOrEqualToConstraint(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 IsGreaterThanOrEqualToConstraint<ExpectedType> IsGreaterThanOrEqualTo(const ExpectedType& expected) + { + return IsGreaterThanOrEqualToConstraint<ExpectedType>(expected); + } + + inline IsGreaterThanOrEqualToConstraint<std::string> IsGreaterThanOrEqualTo(const char* expected) + { + return IsGreaterThanOrEqualToConstraint<std::string>(expected); + } + + template< typename ExpectedType > + struct Stringizer < IsGreaterThanOrEqualToConstraint< ExpectedType > > + { + static std::string ToString(const IsGreaterThanOrEqualToConstraint<ExpectedType>& constraint) + { + std::ostringstream builder; + builder << "greater than or equal to " << 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/islessthanorequaltoconstraint.h b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/islessthanorequaltoconstraint.h new file mode 100644 index 00000000..36e02ab4 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/constraints/islessthanorequaltoconstraint.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_ISLESSTHANOREQUALTOCONSTRAINT_H +#define IGLOO_ISLESSTHANOREQUALTOCONSTRAINT_H + +#include "./expressions/expression.h" + +namespace snowhouse { + + template< typename ExpectedType > + struct IsLessThanOrEqualToConstraint : Expression < IsLessThanOrEqualToConstraint<ExpectedType> > + { + IsLessThanOrEqualToConstraint(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 IsLessThanOrEqualToConstraint<ExpectedType> IsLessThanOrEqualTo(const ExpectedType& expected) + { + return IsLessThanOrEqualToConstraint<ExpectedType>(expected); + } + + inline IsLessThanOrEqualToConstraint<std::string> IsLessThanOrEqualTo(const char* expected) + { + return IsLessThanOrEqualToConstraint<std::string>(expected); + } + + template< typename ExpectedType > + struct Stringizer < IsLessThanOrEqualToConstraint< ExpectedType > > + { + static std::string ToString(const IsLessThanOrEqualToConstraint<ExpectedType>& constraint) + { + std::ostringstream builder; + builder << "less than or equal to " << 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..22ad11ef --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/exceptions.h @@ -0,0 +1,120 @@ + +// 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 void last_exception(ExceptionType*** e, bool clear=false) + { + static ExceptionType* last = NULL; + if(clear && last) + { + delete last; + return; + } + + *e = &last; + silly_warning_about_unused_arg(e); + } + + static ExceptionType*** silly_warning_about_unused_arg(ExceptionType*** e) + { + return e; + } + + static void store(const ExceptionType& e) + { + ExceptionType** last = NULL; + last_exception(&last); + if(*last) + { + delete *last; + *last = NULL; + } + + *last = new ExceptionType(e); + } + + void compiler_thinks_i_am_unused() {} + + ~ExceptionStorage() + { + ExceptionType** e = NULL; + last_exception(&e); + if(*e) + { + delete *e; + *e = NULL; + } + } + }; + + template <typename ExceptionType> + inline ExceptionType& LastException() + { + ExceptionType** e = NULL; + ExceptionStorage<ExceptionType>::last_exception(&e); + if(*e == NULL) + { + Assert::Failure("No exception was stored"); + } + + return **e; + } +} + +#define IGLOO_CONCAT2(a, b) a##b +#define IGLOO_CONCAT(a, b) IGLOO_CONCAT2(a, b) + +#define SNOWHOUSE_ASSERT_THROWS(EXCEPTION_TYPE, METHOD, FAILURE_HANDLER_TYPE) \ +::snowhouse::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) \ + { \ + ::snowhouse::ExceptionStorage<EXCEPTION_TYPE>::store(e); \ + } \ + catch(...) \ + { \ + wrong_exception = true; \ + } \ + if(no_exception) \ + { \ + std::ostringstream stm; \ + stm << "Expected " << #EXCEPTION_TYPE << ". No exception was thrown."; \ + ::snowhouse::ConfigurableAssert<FAILURE_HANDLER_TYPE>::Failure(stm.str()); \ + } \ + if(wrong_exception) \ + { \ + std::ostringstream stm; \ + stm << "Expected " << #EXCEPTION_TYPE << ". Wrong exception was thrown."; \ + ::snowhouse::ConfigurableAssert<FAILURE_HANDLER_TYPE>::Failure(stm.str()); \ + } \ +} + +#ifndef SNOWHOUSE_NO_MACROS + +#define AssertThrows(EXCEPTION_TYPE, METHOD) SNOWHOUSE_ASSERT_THROWS(EXCEPTION_TYPE, (METHOD), ::snowhouse::DefaultFailureHandler) + +#endif // SNOWHOUSE_NO_MACROS + +#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..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 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..38214aa7 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/snowhouse.h @@ -0,0 +1,33 @@ +#ifndef _SNOWHOUSE_H_JK_2013_06_28 +#define _SNOWHOUSE_H_JK_2013_06_28 + +#define SNOWHOUSE_VERSION "2.1.0" + +#if __cplusplus > 199711L +#ifdef _MSC_VER +// Visual Studio (including 2013) does not support the noexcept keyword +#define _ALLOW_KEYWORD_MACROS +#define noexcept +#endif +#endif + + +#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..42249f57 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/snowhouse/snowhouse/stringize.h @@ -0,0 +1,104 @@ +
+// 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
+
+#include <cstddef>
+
+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);
+ }
+ };
+
+#if __cplusplus > 199711L
+ // We need this because nullptr_t has ambiguous overloads of operator<< in the standard library.
+ template<>
+ struct Stringizer<std::nullptr_t>
+ {
+ static std::string ToString(std::nullptr_t)
+ {
+ return "nullptr";
+ }
+ };
+#endif
+}
+
+#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
|