diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 08b90f415..9dcfeea1e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -75,7 +75,7 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND "boost/hana/fwd/ext/std/tuple.hpp" "boost/hana/ext/std/tuple.hpp") - file(GLOB_RECURSE _ext_std_tuple_tests "ext/std/tuple.cpp") + file(GLOB_RECURSE _ext_std_tuple_tests "ext/std/tuple/*.cpp") list(REMOVE_ITEM BOOST_HANA_TEST_SOURCES ${_ext_std_tuple_tests}) endif() @@ -86,8 +86,8 @@ list(REMOVE_ITEM BOOST_HANA_TEST_SOURCES ${_ext_fusion_broken_tests}) # More adapters are currently broken on Clang 3.5; working on it too. if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "3.7.0") - file(GLOB_RECURSE _ext_other_broken_tests "ext/boost/mpl/vector.cpp" - "ext/std/integer_sequence.cpp") + file(GLOB_RECURSE _ext_other_broken_tests "ext/boost/mpl/vector/*.cpp" + "ext/std/integer_sequence/*.cpp") list(REMOVE_ITEM BOOST_HANA_TEST_SOURCES ${_ext_other_broken_tests}) endif() diff --git a/test/ext/boost/mpl/vector.cpp b/test/ext/boost/mpl/vector.cpp deleted file mode 100644 index 9541d5724..000000000 --- a/test/ext/boost/mpl/vector.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* -@copyright Louis Dionne 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - */ - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -using namespace boost::hana; - - -struct x1; struct x2; struct x3; - -namespace boost { namespace hana { namespace test { - template <> - auto instances = make( - type, - type, - type, - type - ); - - template <> - auto objects = make( - ::boost::mpl::vector<>{}, - ::boost::mpl::vector{}, - ::boost::mpl::vector{}, - ::boost::mpl::vector{} - ); -}}} - - -int main() { - test::check_datatype(); - - // make sure the data type is resolved correctly - { - using mpl_id = boost::mpl::quote1; - - static_assert(std::is_same< - datatype_t>, - ext::boost::mpl::Vector - >{}, ""); - static_assert(std::is_same< - datatype_t::type>, - ext::boost::mpl::Vector - >{}, ""); - static_assert(std::is_same< - datatype_t, mpl_id>::type>, - ext::boost::mpl::Vector - >{}, ""); - - static_assert(std::is_same< - datatype_t>, - ext::boost::mpl::Vector - >{}, ""); - static_assert(std::is_same< - datatype_t::type>, - ext::boost::mpl::Vector - >{}, ""); - static_assert(std::is_same< - datatype_t, mpl_id>::type>, - ext::boost::mpl::Vector - >{}, ""); - - static_assert(std::is_same< - datatype_t>, - ext::boost::mpl::Vector - >{}, ""); - static_assert(std::is_same< - datatype_t::type>, - ext::boost::mpl::Vector - >{}, ""); - static_assert(std::is_same< - datatype_t, mpl_id>::type>, - ext::boost::mpl::Vector - >{}, ""); - } - - // Foldable - { - // unpack - { - auto f = test::injection([]{}); - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(::boost::mpl::vector<>{}, f), - f() - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(::boost::mpl::vector{}, f), - f(type) - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(::boost::mpl::vector{}, f), - f(type, type) - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(::boost::mpl::vector{}, f), - f(type, type, type) - )); - } - } - - // Iterable - { - // head - { - BOOST_HANA_CONSTANT_CHECK(equal( - head(::boost::mpl::vector{}), - type - )); - BOOST_HANA_CONSTANT_CHECK(equal( - head(::boost::mpl::vector{}), - type - )); - BOOST_HANA_CONSTANT_CHECK(equal( - head(::boost::mpl::vector{}), - type - )); - } - - // tail - { - BOOST_HANA_CONSTANT_CHECK(equal( - tail(::boost::mpl::vector{}), - ::boost::mpl::vector<>{} - )); - BOOST_HANA_CONSTANT_CHECK(equal( - tail(::boost::mpl::vector{}), - ::boost::mpl::vector{} - )); - BOOST_HANA_CONSTANT_CHECK(equal( - tail(::boost::mpl::vector{}), - ::boost::mpl::vector{} - )); - } - - // is_empty - { - BOOST_HANA_CONSTANT_CHECK(is_empty(::boost::mpl::vector<>{})); - BOOST_HANA_CONSTANT_CHECK(is_empty(::boost::mpl::vector0<>{})); - - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(::boost::mpl::vector{}))); - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(::boost::mpl::vector1{}))); - - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(::boost::mpl::vector{}))); - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(::boost::mpl::vector2{}))); - } - } -} diff --git a/test/ext/boost/mpl/vector/comparable.cpp b/test/ext/boost/mpl/vector/comparable.cpp new file mode 100644 index 000000000..b07395330 --- /dev/null +++ b/test/ext/boost/mpl/vector/comparable.cpp @@ -0,0 +1,37 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include +#include + +#include + +#include +using namespace boost::hana; +namespace mpl = boost::mpl; + + +struct t1; struct t2; struct t3; struct t4; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto vectors = make( + mpl::vector<>{} + , mpl::vector{} + , mpl::vector{} + , mpl::vector{} + , mpl::vector{} + ); + + ////////////////////////////////////////////////////////////////////////// + // Comparable + ////////////////////////////////////////////////////////////////////////// + { + test::TestComparable{vectors}; + } +} diff --git a/test/ext/boost/mpl/vector/datatype.cpp b/test/ext/boost/mpl/vector/datatype.cpp new file mode 100644 index 000000000..17df31463 --- /dev/null +++ b/test/ext/boost/mpl/vector/datatype.cpp @@ -0,0 +1,67 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include +#include + +#include +#include +#include +#include +#include +using namespace boost::hana; +namespace mpl = boost::mpl; + + +struct t1; struct t2; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Make sure the data type is resolved correctly + ////////////////////////////////////////////////////////////////////////// + { + using mpl_id = mpl::quote1; + + static_assert(std::is_same< + datatype_t>, + ext::boost::mpl::Vector + >{}, ""); + static_assert(std::is_same< + datatype_t::type>, + ext::boost::mpl::Vector + >{}, ""); + static_assert(std::is_same< + datatype_t, mpl_id>::type>, + ext::boost::mpl::Vector + >{}, ""); + + static_assert(std::is_same< + datatype_t>, + ext::boost::mpl::Vector + >{}, ""); + static_assert(std::is_same< + datatype_t::type>, + ext::boost::mpl::Vector + >{}, ""); + static_assert(std::is_same< + datatype_t, mpl_id>::type>, + ext::boost::mpl::Vector + >{}, ""); + + static_assert(std::is_same< + datatype_t>, + ext::boost::mpl::Vector + >{}, ""); + static_assert(std::is_same< + datatype_t::type>, + ext::boost::mpl::Vector + >{}, ""); + static_assert(std::is_same< + datatype_t, mpl_id>::type>, + ext::boost::mpl::Vector + >{}, ""); + } +} diff --git a/test/ext/boost/mpl/vector/foldable.cpp b/test/ext/boost/mpl/vector/foldable.cpp new file mode 100644 index 000000000..3df8e324a --- /dev/null +++ b/test/ext/boost/mpl/vector/foldable.cpp @@ -0,0 +1,66 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include +#include +#include + +#include +#include + +#include +using namespace boost::hana; +namespace mpl = boost::mpl; + + +struct t1; struct t2; struct t3; struct t4; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto vectors = make( + mpl::vector<>{} + , mpl::vector{} + , mpl::vector{} + , mpl::vector{} + , mpl::vector{} + ); + + ////////////////////////////////////////////////////////////////////////// + // Foldable + ////////////////////////////////////////////////////////////////////////// + { + // unpack + { + test::_injection<0> f{}; + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(mpl::vector<>{}, f), + f() + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(mpl::vector{}, f), + f(type) + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(mpl::vector{}, f), + f(type, type) + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(mpl::vector{}, f), + f(type, type, type) + )); + } + + // laws + test::TestFoldable{vectors}; + } +} diff --git a/test/ext/boost/mpl/vector/iterable.cpp b/test/ext/boost/mpl/vector/iterable.cpp new file mode 100644 index 000000000..2d231429f --- /dev/null +++ b/test/ext/boost/mpl/vector/iterable.cpp @@ -0,0 +1,85 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include +#include +#include + +#include + +#include +using namespace boost::hana; +namespace mpl = boost::mpl; + + +struct t1; struct t2; struct t3; struct t4; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto vectors = make( + mpl::vector<>{} + , mpl::vector{} + , mpl::vector{} + , mpl::vector{} + , mpl::vector{} + ); + + ////////////////////////////////////////////////////////////////////////// + // Iterable + ////////////////////////////////////////////////////////////////////////// + { + // head + { + BOOST_HANA_CONSTANT_CHECK(equal( + head(mpl::vector{}), + type + )); + BOOST_HANA_CONSTANT_CHECK(equal( + head(mpl::vector{}), + type + )); + BOOST_HANA_CONSTANT_CHECK(equal( + head(mpl::vector{}), + type + )); + } + + // tail + { + BOOST_HANA_CONSTANT_CHECK(equal( + tail(mpl::vector{}), + mpl::vector<>{} + )); + BOOST_HANA_CONSTANT_CHECK(equal( + tail(mpl::vector{}), + mpl::vector{} + )); + BOOST_HANA_CONSTANT_CHECK(equal( + tail(mpl::vector{}), + mpl::vector{} + )); + } + + // is_empty + { + BOOST_HANA_CONSTANT_CHECK(is_empty(mpl::vector<>{})); + BOOST_HANA_CONSTANT_CHECK(is_empty(mpl::vector0<>{})); + + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(mpl::vector{}))); + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(mpl::vector1{}))); + + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(mpl::vector{}))); + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(mpl::vector2{}))); + } + + // laws + test::TestIterable{vectors}; + } +} diff --git a/test/ext/boost/mpl/vector/searchable.cpp b/test/ext/boost/mpl/vector/searchable.cpp new file mode 100644 index 000000000..813d42176 --- /dev/null +++ b/test/ext/boost/mpl/vector/searchable.cpp @@ -0,0 +1,39 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include +#include + +#include + +#include +using namespace boost::hana; +namespace mpl = boost::mpl; + + +struct t1; struct t2; struct t3; struct t4; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto vectors = make( + mpl::vector<>{} + , mpl::vector{} + , mpl::vector{} + , mpl::vector{} + , mpl::vector{} + ); + + auto keys = tuple_t; + + ////////////////////////////////////////////////////////////////////////// + // Searchable + ////////////////////////////////////////////////////////////////////////// + { + test::TestSearchable{vectors, keys}; + } +} diff --git a/test/ext/boost/tuple/tuple.cpp b/test/ext/boost/tuple/datatype.cpp similarity index 71% rename from test/ext/boost/tuple/tuple.cpp rename to test/ext/boost/tuple/datatype.cpp index e73f13893..602e4c20c 100644 --- a/test/ext/boost/tuple/tuple.cpp +++ b/test/ext/boost/tuple/datatype.cpp @@ -4,45 +4,19 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ +#include #include -#include -#include -#include - -#include -#include -#include - #include + #include using namespace boost::hana; -template -constexpr auto ord = test::cnumeric; - -namespace boost { namespace hana { namespace test { - template <> - auto instances = make( - type - ); - - template <> - auto objects = make( - ::boost::make_tuple(), - ::boost::make_tuple(ord<0>), - ::boost::make_tuple(ord<0>, ord<1>), - ::boost::make_tuple(ord<0>, ord<1>, ord<2>), - ::boost::make_tuple(ord<0>, ord<1>, ord<2>, ord<3>) - ); -}}} - - int main() { - test::check_datatype(); - + ////////////////////////////////////////////////////////////////////////// // make sure the datatype is correct + ////////////////////////////////////////////////////////////////////////// { auto make_cons = [](auto x, auto xs) { return boost::tuples::cons{x, xs}; diff --git a/test/ext/boost/tuple/iterable.cpp b/test/ext/boost/tuple/iterable.cpp new file mode 100644 index 000000000..457b65804 --- /dev/null +++ b/test/ext/boost/tuple/iterable.cpp @@ -0,0 +1,39 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + ::boost::make_tuple() + , ::boost::make_tuple(eq<0>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}) + ); + + ////////////////////////////////////////////////////////////////////////// + // Foldable, Iterable, Traversable + ////////////////////////////////////////////////////////////////////////// + test::TestFoldable{eq_tuples}; + test::TestIterable{eq_tuples}; + test::TestTraversable{}; +} diff --git a/test/ext/boost/tuple/monad.cpp b/test/ext/boost/tuple/monad.cpp new file mode 100644 index 000000000..1f9af2107 --- /dev/null +++ b/test/ext/boost/tuple/monad.cpp @@ -0,0 +1,53 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + ::boost::make_tuple() + , ::boost::make_tuple(eq<0>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{}) + ); + + auto eq_tuples_tuples = make( + ::boost::make_tuple() + , ::boost::make_tuple( + ::boost::make_tuple(eq<0>{})) + , ::boost::make_tuple( + ::boost::make_tuple(eq<0>{}), + ::boost::make_tuple(eq<1>{}, eq<2>{})) + , ::boost::make_tuple( + ::boost::make_tuple(eq<0>{}), + ::boost::make_tuple(eq<1>{}, eq<2>{}), + ::boost::make_tuple(eq<3>{}, eq<4>{})) + ); + + ////////////////////////////////////////////////////////////////////////// + // Functor up to Monad + ////////////////////////////////////////////////////////////////////////// + test::TestFunctor{eq_tuples}; + test::TestApplicative{}; + test::TestMonad{eq_tuples, eq_tuples_tuples}; +} diff --git a/test/ext/boost/tuple/monad_plus.cpp b/test/ext/boost/tuple/monad_plus.cpp new file mode 100644 index 000000000..6f2cdd75c --- /dev/null +++ b/test/ext/boost/tuple/monad_plus.cpp @@ -0,0 +1,35 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + ::boost::make_tuple(eq<0>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}) + ); + + ////////////////////////////////////////////////////////////////////////// + // MonadPlus + ////////////////////////////////////////////////////////////////////////// + test::TestMonadPlus{eq_tuples}; +} diff --git a/test/ext/boost/tuple/orderable.hpp b/test/ext/boost/tuple/orderable.hpp new file mode 100644 index 000000000..502f91e2b --- /dev/null +++ b/test/ext/boost/tuple/orderable.hpp @@ -0,0 +1,49 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +template +using ord = test::ct_ord; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + ::boost::make_tuple() + , ::boost::make_tuple(eq<0>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{}, eq<4>{}) + ); + + auto ord_tuples = make( + ::boost::make_tuple() + , ::boost::make_tuple(ord<0>{}) + , ::boost::make_tuple(ord<0>{}, ord<1>{}) + , ::boost::make_tuple(ord<0>{}, ord<1>{}, ord<2>{}) + , ::boost::make_tuple(ord<0>{}, ord<1>{}, ord<2>{}, ord<3>{}, ord<4>{}) + ); + + ////////////////////////////////////////////////////////////////////////// + // Comparable and Orderable + ////////////////////////////////////////////////////////////////////////// + test::TestComparable{eq_tuples}; + test::TestOrderable{ord_tuples}; +} diff --git a/test/ext/boost/tuple/searchable.cpp b/test/ext/boost/tuple/searchable.cpp new file mode 100644 index 000000000..ae553d258 --- /dev/null +++ b/test/ext/boost/tuple/searchable.cpp @@ -0,0 +1,42 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + ::boost::make_tuple() + , ::boost::make_tuple(eq<0>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}) + , ::boost::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}) + ); + + auto eq_tuple_keys = make( + eq<3>{}, eq<5>{}, eq<7>{} + ); + + ////////////////////////////////////////////////////////////////////////// + // Searchable + ////////////////////////////////////////////////////////////////////////// + { + test::TestSearchable{eq_tuples, eq_tuple_keys}; + } +} diff --git a/test/ext/boost/tuple/sequence.cpp b/test/ext/boost/tuple/sequence.cpp new file mode 100644 index 000000000..b28a4375b --- /dev/null +++ b/test/ext/boost/tuple/sequence.cpp @@ -0,0 +1,20 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +using namespace boost::hana; + + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Sequence + ////////////////////////////////////////////////////////////////////////// + test::TestSequence{}; +} diff --git a/test/ext/std/integer_sequence.cpp b/test/ext/std/integer_sequence.cpp deleted file mode 100644 index fbeeffdee..000000000 --- a/test/ext/std/integer_sequence.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* -@copyright Louis Dionne 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - */ - -#include -#include - -#include -#include -#include - -#include - -// instances -#include -#include - -#include -#include -using namespace boost::hana; - - -using T = int; -using U = long long; - -namespace boost { namespace hana { namespace test { - template <> - auto instances = make( - type, - type - ); - - template <> - auto objects = make( - ::std::integer_sequence{}, - ::std::integer_sequence{}, - - ::std::integer_sequence{}, - ::std::integer_sequence{}, - - ::std::integer_sequence{}, - ::std::integer_sequence{}, - - ::std::integer_sequence{}, - ::std::integer_sequence{} - ); -}}} - - -int main() { - test::check_datatype(); - - // Comparable - { - // equal - { - BOOST_HANA_CONSTANT_CHECK(equal( - std::integer_sequence{}, - std::integer_sequence{} - )); - BOOST_HANA_CONSTANT_CHECK(not_(equal( - std::integer_sequence{}, - std::integer_sequence{} - ))); - BOOST_HANA_CONSTANT_CHECK(not_(equal( - std::integer_sequence{}, - std::integer_sequence{} - ))); - - BOOST_HANA_CONSTANT_CHECK(equal( - std::integer_sequence{}, - std::integer_sequence{} - )); - BOOST_HANA_CONSTANT_CHECK(not_(equal( - std::integer_sequence{}, - std::integer_sequence{} - ))); - BOOST_HANA_CONSTANT_CHECK(not_(equal( - std::integer_sequence{}, - std::integer_sequence{} - ))); - - BOOST_HANA_CONSTANT_CHECK(equal( - std::integer_sequence{}, - std::integer_sequence{} - )); - BOOST_HANA_CONSTANT_CHECK(not_(equal( - std::integer_sequence{}, - std::integer_sequence{} - ))); - } - } - - // Iterable - { - // head - { - BOOST_HANA_CONSTANT_CHECK(equal( - head(std::index_sequence<0>{}), - std::integral_constant{} - )); - BOOST_HANA_CONSTANT_CHECK(equal( - head(std::index_sequence<0, 1>{}), - std::integral_constant{} - )); - } - - // is_empty - { - BOOST_HANA_CONSTANT_CHECK(is_empty(std::index_sequence<>{})); - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(std::index_sequence<0>{}))); - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(std::index_sequence<1>{}))); - } - - // tail - { - BOOST_HANA_CONSTANT_CHECK(equal( - tail(std::index_sequence<0>{}), - std::index_sequence<>{} - )); - BOOST_HANA_CONSTANT_CHECK(equal( - tail(std::index_sequence<0, 1>{}), - std::index_sequence<1>{} - )); - BOOST_HANA_CONSTANT_CHECK(equal( - tail(std::index_sequence<0, 1, 2>{}), - std::index_sequence<1, 2>{} - )); - } - } -} diff --git a/test/ext/std/integer_sequence/comparable.cpp b/test/ext/std/integer_sequence/comparable.cpp new file mode 100644 index 000000000..49f03681f --- /dev/null +++ b/test/ext/std/integer_sequence/comparable.cpp @@ -0,0 +1,84 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include +#include + +#include + +#include +using namespace boost::hana; + + +using T = int; +using U = long long; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto sequences = make( + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{} + ); + + ////////////////////////////////////////////////////////////////////////// + // Comparable + ////////////////////////////////////////////////////////////////////////// + { + // equal + { + BOOST_HANA_CONSTANT_CHECK(equal( + std::integer_sequence{}, + std::integer_sequence{} + )); + BOOST_HANA_CONSTANT_CHECK(not_(equal( + std::integer_sequence{}, + std::integer_sequence{} + ))); + BOOST_HANA_CONSTANT_CHECK(not_(equal( + std::integer_sequence{}, + std::integer_sequence{} + ))); + + BOOST_HANA_CONSTANT_CHECK(equal( + std::integer_sequence{}, + std::integer_sequence{} + )); + BOOST_HANA_CONSTANT_CHECK(not_(equal( + std::integer_sequence{}, + std::integer_sequence{} + ))); + BOOST_HANA_CONSTANT_CHECK(not_(equal( + std::integer_sequence{}, + std::integer_sequence{} + ))); + + BOOST_HANA_CONSTANT_CHECK(equal( + std::integer_sequence{}, + std::integer_sequence{} + )); + BOOST_HANA_CONSTANT_CHECK(not_(equal( + std::integer_sequence{}, + std::integer_sequence{} + ))); + } + + // laws + test::TestComparable{sequences}; + } +} diff --git a/test/ext/std/integer_sequence/foldable.cpp b/test/ext/std/integer_sequence/foldable.cpp new file mode 100644 index 000000000..ca6948bc6 --- /dev/null +++ b/test/ext/std/integer_sequence/foldable.cpp @@ -0,0 +1,44 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include +#include + +#include + +#include +using namespace boost::hana; + + +using T = int; +using U = long long; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto sequences = make( + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{} + ); + + ////////////////////////////////////////////////////////////////////////// + // Foldable + ////////////////////////////////////////////////////////////////////////// + { + // laws + test::TestFoldable{sequences}; + } +} diff --git a/test/ext/std/integer_sequence/iterable.cpp b/test/ext/std/integer_sequence/iterable.cpp new file mode 100644 index 000000000..047d59d76 --- /dev/null +++ b/test/ext/std/integer_sequence/iterable.cpp @@ -0,0 +1,81 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include +#include + +#include +#include + +#include + +#include +#include +using namespace boost::hana; + + +using T = int; +using U = long long; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto sequences = make( + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{} + ); + + ////////////////////////////////////////////////////////////////////////// + // Iterable + ////////////////////////////////////////////////////////////////////////// + // head + { + BOOST_HANA_CONSTANT_CHECK(equal( + head(std::index_sequence<0>{}), + std::integral_constant{} + )); + BOOST_HANA_CONSTANT_CHECK(equal( + head(std::index_sequence<0, 1>{}), + std::integral_constant{} + )); + } + + // is_empty + { + BOOST_HANA_CONSTANT_CHECK(is_empty(std::index_sequence<>{})); + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(std::index_sequence<0>{}))); + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(std::index_sequence<1>{}))); + } + + // tail + { + BOOST_HANA_CONSTANT_CHECK(equal( + tail(std::index_sequence<0>{}), + std::index_sequence<>{} + )); + BOOST_HANA_CONSTANT_CHECK(equal( + tail(std::index_sequence<0, 1>{}), + std::index_sequence<1>{} + )); + BOOST_HANA_CONSTANT_CHECK(equal( + tail(std::index_sequence<0, 1, 2>{}), + std::index_sequence<1, 2>{} + )); + } + + // laws + test::TestIterable{sequences}; +} diff --git a/test/ext/std/integer_sequence/searchable.cpp b/test/ext/std/integer_sequence/searchable.cpp new file mode 100644 index 000000000..dcf32d786 --- /dev/null +++ b/test/ext/std/integer_sequence/searchable.cpp @@ -0,0 +1,49 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include +#include +#include + +#include + +#include +using namespace boost::hana; + + +using T = int; +using U = long long; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto sequences = make( + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{}, + + std::integer_sequence{}, + std::integer_sequence{} + ); + + auto keys = make( + integral_constant, integral_constant + ); + + ////////////////////////////////////////////////////////////////////////// + // Searchable + ////////////////////////////////////////////////////////////////////////// + { + // laws + test::TestSearchable{sequences, keys}; + } +} diff --git a/test/ext/std/tuple.cpp b/test/ext/std/tuple.cpp deleted file mode 100644 index 59eb01136..000000000 --- a/test/ext/std/tuple.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* -@copyright Louis Dionne 2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) - */ - -#include - -#include -#include - -#include -#include -#include - -#include -using namespace boost::hana; - - -template -constexpr auto ord = test::cnumeric; - -namespace boost { namespace hana { namespace test { - template <> - auto instances = make( - type - ); - - template <> - auto objects = make( - ::std::make_tuple(), - ::std::make_tuple(ord<0>), - ::std::make_tuple(ord<0>, ord<1>), - ::std::make_tuple(ord<0>, ord<1>, ord<2>), - ::std::make_tuple(ord<0>, ord<1>, ord<2>, ord<3>) - ); -}}} - - -int main() { - test::check_datatype(); -} diff --git a/test/ext/std/tuple/iterable.cpp b/test/ext/std/tuple/iterable.cpp new file mode 100644 index 000000000..eb683be9e --- /dev/null +++ b/test/ext/std/tuple/iterable.cpp @@ -0,0 +1,39 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + std::make_tuple() + , std::make_tuple(eq<0>{}) + , std::make_tuple(eq<0>{}, eq<1>{}) + , std::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}) + ); + + ////////////////////////////////////////////////////////////////////////// + // Foldable, Iterable, Traversable + ////////////////////////////////////////////////////////////////////////// + test::TestFoldable{eq_tuples}; + test::TestIterable{eq_tuples}; + test::TestTraversable{}; +} diff --git a/test/ext/std/tuple/monad.cpp b/test/ext/std/tuple/monad.cpp new file mode 100644 index 000000000..e09a835be --- /dev/null +++ b/test/ext/std/tuple/monad.cpp @@ -0,0 +1,53 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + std::make_tuple() + , std::make_tuple(eq<0>{}) + , std::make_tuple(eq<0>{}, eq<1>{}) + , std::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{}) + ); + + auto eq_tuples_tuples = make( + std::make_tuple() + , std::make_tuple( + std::make_tuple(eq<0>{})) + , std::make_tuple( + std::make_tuple(eq<0>{}), + std::make_tuple(eq<1>{}, eq<2>{})) + , std::make_tuple( + std::make_tuple(eq<0>{}), + std::make_tuple(eq<1>{}, eq<2>{}), + std::make_tuple(eq<3>{}, eq<4>{})) + ); + + ////////////////////////////////////////////////////////////////////////// + // Functor up to Monad + ////////////////////////////////////////////////////////////////////////// + test::TestFunctor{eq_tuples}; + test::TestApplicative{}; + test::TestMonad{eq_tuples, eq_tuples_tuples}; +} diff --git a/test/ext/std/tuple/monad_plus.cpp b/test/ext/std/tuple/monad_plus.cpp new file mode 100644 index 000000000..2ced05d20 --- /dev/null +++ b/test/ext/std/tuple/monad_plus.cpp @@ -0,0 +1,35 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + std::make_tuple(eq<0>{}) + , std::make_tuple(eq<0>{}, eq<1>{}) + , std::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}) + ); + + ////////////////////////////////////////////////////////////////////////// + // MonadPlus + ////////////////////////////////////////////////////////////////////////// + test::TestMonadPlus{eq_tuples}; +} diff --git a/test/ext/std/tuple/orderable.cpp b/test/ext/std/tuple/orderable.cpp new file mode 100644 index 000000000..b73be13b2 --- /dev/null +++ b/test/ext/std/tuple/orderable.cpp @@ -0,0 +1,49 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +template +using ord = test::ct_ord; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + std::make_tuple() + , std::make_tuple(eq<0>{}) + , std::make_tuple(eq<0>{}, eq<1>{}) + , std::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}) + , std::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}, eq<3>{}, eq<4>{}) + ); + + auto ord_tuples = make( + std::make_tuple() + , std::make_tuple(ord<0>{}) + , std::make_tuple(ord<0>{}, ord<1>{}) + , std::make_tuple(ord<0>{}, ord<1>{}, ord<2>{}) + , std::make_tuple(ord<0>{}, ord<1>{}, ord<2>{}, ord<3>{}, ord<4>{}) + ); + + ////////////////////////////////////////////////////////////////////////// + // Comparable and Orderable + ////////////////////////////////////////////////////////////////////////// + test::TestComparable{eq_tuples}; + test::TestOrderable{ord_tuples}; +} diff --git a/test/ext/std/tuple/searchable.cpp b/test/ext/std/tuple/searchable.cpp new file mode 100644 index 000000000..90f1ddbc6 --- /dev/null +++ b/test/ext/std/tuple/searchable.cpp @@ -0,0 +1,42 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +#include + +#include +using namespace boost::hana; + + +template +using eq = test::ct_eq; + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto eq_tuples = make( + std::make_tuple() + , std::make_tuple(eq<0>{}) + , std::make_tuple(eq<0>{}, eq<1>{}) + , std::make_tuple(eq<0>{}, eq<1>{}, eq<2>{}) + ); + + auto eq_tuple_keys = make( + eq<3>{}, eq<5>{}, eq<7>{} + ); + + ////////////////////////////////////////////////////////////////////////// + // Searchable + ////////////////////////////////////////////////////////////////////////// + { + test::TestSearchable{eq_tuples, eq_tuple_keys}; + } +} diff --git a/test/ext/std/tuple/sequence.cpp b/test/ext/std/tuple/sequence.cpp new file mode 100644 index 000000000..99c0559e1 --- /dev/null +++ b/test/ext/std/tuple/sequence.cpp @@ -0,0 +1,20 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include + +#include +using namespace boost::hana; + + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Sequence + ////////////////////////////////////////////////////////////////////////// + test::TestSequence{}; +} diff --git a/test/string/foldable.cpp b/test/string/foldable.cpp new file mode 100644 index 000000000..9466b38e3 --- /dev/null +++ b/test/string/foldable.cpp @@ -0,0 +1,86 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include +#include +#include + +#include +#include +using namespace boost::hana; + + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto strings = make( + BOOST_HANA_STRING(""), + BOOST_HANA_STRING("a"), + BOOST_HANA_STRING("ab"), + BOOST_HANA_STRING("abc"), + BOOST_HANA_STRING("abcd"), + BOOST_HANA_STRING("abcde"), + BOOST_HANA_STRING("ba"), + BOOST_HANA_STRING("afcd") + ); + + ////////////////////////////////////////////////////////////////////////// + // Foldable + ////////////////////////////////////////////////////////////////////////// + { + test::_injection<0> f{}; + + // unpack + { + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(BOOST_HANA_STRING(""), f), + f() + )); + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(BOOST_HANA_STRING("a"), f), + f(char_<'a'>) + )); + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(BOOST_HANA_STRING("ab"), f), + f(char_<'a'>, char_<'b'>) + )); + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(BOOST_HANA_STRING("abc"), f), + f(char_<'a'>, char_<'b'>, char_<'c'>) + )); + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(BOOST_HANA_STRING("abcd"), f), + f(char_<'a'>, char_<'b'>, char_<'c'>, char_<'d'>) + )); + BOOST_HANA_CONSTANT_CHECK(equal( + unpack(BOOST_HANA_STRING("abcde"), f), + f(char_<'a'>, char_<'b'>, char_<'c'>, char_<'d'>, char_<'e'>) + )); + } + + // length + { + BOOST_HANA_CONSTANT_CHECK(equal( + length(BOOST_HANA_STRING("")), size_t<0> + )); + BOOST_HANA_CONSTANT_CHECK(equal( + length(BOOST_HANA_STRING("a")), size_t<1> + )); + BOOST_HANA_CONSTANT_CHECK(equal( + length(BOOST_HANA_STRING("ab")), size_t<2> + )); + BOOST_HANA_CONSTANT_CHECK(equal( + length(BOOST_HANA_STRING("abc")), size_t<3> + )); + } + + // laws + test::TestFoldable{strings}; + } +} diff --git a/test/string/iterable.cpp b/test/string/iterable.cpp new file mode 100644 index 000000000..45c206525 --- /dev/null +++ b/test/string/iterable.cpp @@ -0,0 +1,133 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include +#include +#include +#include + +#include +using namespace boost::hana; + + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto strings = make( + BOOST_HANA_STRING(""), + BOOST_HANA_STRING("a"), + BOOST_HANA_STRING("ab"), + BOOST_HANA_STRING("abc"), + BOOST_HANA_STRING("abcd"), + BOOST_HANA_STRING("abcde"), + BOOST_HANA_STRING("ba"), + BOOST_HANA_STRING("afcd") + ); + + ////////////////////////////////////////////////////////////////////////// + // Iterable + ////////////////////////////////////////////////////////////////////////// + { + // head + { + BOOST_HANA_CONSTANT_CHECK(equal( + head(BOOST_HANA_STRING("a")), + char_<'a'> + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + head(BOOST_HANA_STRING("ab")), + char_<'a'> + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + head(BOOST_HANA_STRING("abc")), + char_<'a'> + )); + } + + // tail + { + BOOST_HANA_CONSTANT_CHECK(equal( + tail(BOOST_HANA_STRING("a")), + BOOST_HANA_STRING("") + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + tail(BOOST_HANA_STRING("ab")), + BOOST_HANA_STRING("b") + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + tail(BOOST_HANA_STRING("abc")), + BOOST_HANA_STRING("bc") + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + tail(BOOST_HANA_STRING("abcdefghijk")), + BOOST_HANA_STRING("bcdefghijk") + )); + } + + // is_empty + { + BOOST_HANA_CONSTANT_CHECK(is_empty(BOOST_HANA_STRING(""))); + BOOST_HANA_CONSTANT_CHECK(is_empty(string<>)); + + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(BOOST_HANA_STRING("a")))); + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(BOOST_HANA_STRING("ab")))); + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(BOOST_HANA_STRING("abc")))); + BOOST_HANA_CONSTANT_CHECK(not_(is_empty(string<'a'>))); + } + + // at + { + BOOST_HANA_CONSTANT_CHECK(equal( + at(int_<0>, BOOST_HANA_STRING("a")), + char_<'a'> + )); + BOOST_HANA_CONSTANT_CHECK(equal( + at(int_<0>, BOOST_HANA_STRING("ab")), + char_<'a'> + )); + BOOST_HANA_CONSTANT_CHECK(equal( + at(int_<0>, BOOST_HANA_STRING("abc")), + char_<'a'> + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + at(int_<1>, BOOST_HANA_STRING("ab")), + char_<'b'> + )); + BOOST_HANA_CONSTANT_CHECK(equal( + at(int_<1>, BOOST_HANA_STRING("abc")), + char_<'b'> + )); + BOOST_HANA_CONSTANT_CHECK(equal( + at(int_<1>, BOOST_HANA_STRING("abcd")), + char_<'b'> + )); + + BOOST_HANA_CONSTANT_CHECK(equal( + at(int_<2>, BOOST_HANA_STRING("abc")), + char_<'c'> + )); + BOOST_HANA_CONSTANT_CHECK(equal( + at(int_<2>, BOOST_HANA_STRING("abcd")), + char_<'c'> + )); + } + + // operators + static_assert(has_operator{}, ""); + + // laws + test::TestIterable{strings}; + } +} diff --git a/test/string/orderable.cpp b/test/string/orderable.cpp new file mode 100644 index 000000000..09f4f9a8a --- /dev/null +++ b/test/string/orderable.cpp @@ -0,0 +1,122 @@ +/* +@copyright Louis Dionne 2015 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#include + +#include +#include +#include + +#include +#include + +#include +using namespace boost::hana; + + +int main() { + ////////////////////////////////////////////////////////////////////////// + // Setup for the laws below + ////////////////////////////////////////////////////////////////////////// + auto strings = make( + BOOST_HANA_STRING(""), + BOOST_HANA_STRING("a"), + BOOST_HANA_STRING("ab"), + BOOST_HANA_STRING("abc"), + BOOST_HANA_STRING("abcd"), + BOOST_HANA_STRING("abcde"), + BOOST_HANA_STRING("ba"), + BOOST_HANA_STRING("afcd") + ); + + ////////////////////////////////////////////////////////////////////////// + // Comparable + ////////////////////////////////////////////////////////////////////////// + { + // equal + BOOST_HANA_CONSTANT_CHECK(equal( + BOOST_HANA_STRING("abcd"), + BOOST_HANA_STRING("abcd") + )); + + BOOST_HANA_CONSTANT_CHECK(not_(equal( + BOOST_HANA_STRING("abcd"), + BOOST_HANA_STRING("abcde") + ))); + + BOOST_HANA_CONSTANT_CHECK(not_(equal( + BOOST_HANA_STRING("abcd"), + BOOST_HANA_STRING("") + ))); + + BOOST_HANA_CONSTANT_CHECK(not_(equal( + BOOST_HANA_STRING(""), + BOOST_HANA_STRING("abcde") + ))); + + BOOST_HANA_CONSTANT_CHECK(equal( + BOOST_HANA_STRING(""), + BOOST_HANA_STRING("") + )); + + // operators + static_assert(has_operator{}, ""); + static_assert(has_operator{}, ""); + + // laws + test::TestComparable{strings}; + } + + ////////////////////////////////////////////////////////////////////////// + // Orderable + ////////////////////////////////////////////////////////////////////////// + { + // less + BOOST_HANA_CONSTANT_CHECK(not_(less( + BOOST_HANA_STRING(""), + BOOST_HANA_STRING("") + ))); + + BOOST_HANA_CONSTANT_CHECK(less( + BOOST_HANA_STRING(""), + BOOST_HANA_STRING("a") + )); + + BOOST_HANA_CONSTANT_CHECK(not_(less( + BOOST_HANA_STRING("a"), + BOOST_HANA_STRING("") + ))); + + BOOST_HANA_CONSTANT_CHECK(less( + BOOST_HANA_STRING("a"), + BOOST_HANA_STRING("ab") + )); + + BOOST_HANA_CONSTANT_CHECK(not_(less( + BOOST_HANA_STRING("ab"), + BOOST_HANA_STRING("ab") + ))); + + BOOST_HANA_CONSTANT_CHECK(less( + BOOST_HANA_STRING("abc"), + BOOST_HANA_STRING("abcde") + )); + + BOOST_HANA_CONSTANT_CHECK(less( + BOOST_HANA_STRING("abcde"), + BOOST_HANA_STRING("abfde") + )); + + // operators + static_assert(has_operator{}, ""); + static_assert(has_operator{}, ""); + static_assert(has_operator{}, ""); + static_assert(has_operator{}, ""); + + // laws + test::TestOrderable{strings}; + } +} diff --git a/test/string/string.cpp b/test/string/string.cpp index 2c9085bd1..b9622d5f8 100644 --- a/test/string/string.cpp +++ b/test/string/string.cpp @@ -5,19 +5,7 @@ Distributed under the Boost Software License, Version 1.0. */ #include - -#include #include -#include -#include -#include -#include - -#include -#include -#include -#include -#include #include using namespace boost::hana; @@ -35,261 +23,4 @@ int main() { decltype(s1), decltype(s2) >::value, ""); } - - ////////////////////////////////////////////////////////////////////////// - // Setup for the laws below - ////////////////////////////////////////////////////////////////////////// - auto strings = make( - BOOST_HANA_STRING(""), - BOOST_HANA_STRING("a"), - BOOST_HANA_STRING("ab"), - BOOST_HANA_STRING("abc"), - BOOST_HANA_STRING("abcd"), - BOOST_HANA_STRING("abcde"), - BOOST_HANA_STRING("ba"), - BOOST_HANA_STRING("afcd") - ); - - ////////////////////////////////////////////////////////////////////////// - // Comparable - ////////////////////////////////////////////////////////////////////////// - { - // equal - BOOST_HANA_CONSTANT_CHECK(equal( - BOOST_HANA_STRING("abcd"), - BOOST_HANA_STRING("abcd") - )); - - BOOST_HANA_CONSTANT_CHECK(not_(equal( - BOOST_HANA_STRING("abcd"), - BOOST_HANA_STRING("abcde") - ))); - - BOOST_HANA_CONSTANT_CHECK(not_(equal( - BOOST_HANA_STRING("abcd"), - BOOST_HANA_STRING("") - ))); - - BOOST_HANA_CONSTANT_CHECK(not_(equal( - BOOST_HANA_STRING(""), - BOOST_HANA_STRING("abcde") - ))); - - BOOST_HANA_CONSTANT_CHECK(equal( - BOOST_HANA_STRING(""), - BOOST_HANA_STRING("") - )); - - // operators - static_assert(has_operator{}, ""); - static_assert(has_operator{}, ""); - - // laws - test::TestComparable{strings}; - } - - ////////////////////////////////////////////////////////////////////////// - // Orderable - ////////////////////////////////////////////////////////////////////////// - { - // less - BOOST_HANA_CONSTANT_CHECK(not_(less( - BOOST_HANA_STRING(""), - BOOST_HANA_STRING("") - ))); - - BOOST_HANA_CONSTANT_CHECK(less( - BOOST_HANA_STRING(""), - BOOST_HANA_STRING("a") - )); - - BOOST_HANA_CONSTANT_CHECK(not_(less( - BOOST_HANA_STRING("a"), - BOOST_HANA_STRING("") - ))); - - BOOST_HANA_CONSTANT_CHECK(less( - BOOST_HANA_STRING("a"), - BOOST_HANA_STRING("ab") - )); - - BOOST_HANA_CONSTANT_CHECK(not_(less( - BOOST_HANA_STRING("ab"), - BOOST_HANA_STRING("ab") - ))); - - BOOST_HANA_CONSTANT_CHECK(less( - BOOST_HANA_STRING("abc"), - BOOST_HANA_STRING("abcde") - )); - - BOOST_HANA_CONSTANT_CHECK(less( - BOOST_HANA_STRING("abcde"), - BOOST_HANA_STRING("abfde") - )); - - // operators - static_assert(has_operator{}, ""); - static_assert(has_operator{}, ""); - static_assert(has_operator{}, ""); - static_assert(has_operator{}, ""); - - // laws - test::TestOrderable{strings}; - } - - ////////////////////////////////////////////////////////////////////////// - // Foldable - ////////////////////////////////////////////////////////////////////////// - { - test::_injection<0> f{}; - - // unpack - { - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(BOOST_HANA_STRING(""), f), - f() - )); - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(BOOST_HANA_STRING("a"), f), - f(char_<'a'>) - )); - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(BOOST_HANA_STRING("ab"), f), - f(char_<'a'>, char_<'b'>) - )); - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(BOOST_HANA_STRING("abc"), f), - f(char_<'a'>, char_<'b'>, char_<'c'>) - )); - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(BOOST_HANA_STRING("abcd"), f), - f(char_<'a'>, char_<'b'>, char_<'c'>, char_<'d'>) - )); - BOOST_HANA_CONSTANT_CHECK(equal( - unpack(BOOST_HANA_STRING("abcde"), f), - f(char_<'a'>, char_<'b'>, char_<'c'>, char_<'d'>, char_<'e'>) - )); - } - - // length - { - BOOST_HANA_CONSTANT_CHECK(equal( - length(BOOST_HANA_STRING("")), size_t<0> - )); - BOOST_HANA_CONSTANT_CHECK(equal( - length(BOOST_HANA_STRING("a")), size_t<1> - )); - BOOST_HANA_CONSTANT_CHECK(equal( - length(BOOST_HANA_STRING("ab")), size_t<2> - )); - BOOST_HANA_CONSTANT_CHECK(equal( - length(BOOST_HANA_STRING("abc")), size_t<3> - )); - } - - // laws - test::TestFoldable{strings}; - } - - ////////////////////////////////////////////////////////////////////////// - // Iterable - ////////////////////////////////////////////////////////////////////////// - { - // head - { - BOOST_HANA_CONSTANT_CHECK(equal( - head(BOOST_HANA_STRING("a")), - char_<'a'> - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - head(BOOST_HANA_STRING("ab")), - char_<'a'> - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - head(BOOST_HANA_STRING("abc")), - char_<'a'> - )); - } - - // tail - { - BOOST_HANA_CONSTANT_CHECK(equal( - tail(BOOST_HANA_STRING("a")), - BOOST_HANA_STRING("") - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - tail(BOOST_HANA_STRING("ab")), - BOOST_HANA_STRING("b") - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - tail(BOOST_HANA_STRING("abc")), - BOOST_HANA_STRING("bc") - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - tail(BOOST_HANA_STRING("abcdefghijk")), - BOOST_HANA_STRING("bcdefghijk") - )); - } - - // is_empty - { - BOOST_HANA_CONSTANT_CHECK(is_empty(BOOST_HANA_STRING(""))); - BOOST_HANA_CONSTANT_CHECK(is_empty(string<>)); - - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(BOOST_HANA_STRING("a")))); - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(BOOST_HANA_STRING("ab")))); - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(BOOST_HANA_STRING("abc")))); - BOOST_HANA_CONSTANT_CHECK(not_(is_empty(string<'a'>))); - } - - // at - { - BOOST_HANA_CONSTANT_CHECK(equal( - at(int_<0>, BOOST_HANA_STRING("a")), - char_<'a'> - )); - BOOST_HANA_CONSTANT_CHECK(equal( - at(int_<0>, BOOST_HANA_STRING("ab")), - char_<'a'> - )); - BOOST_HANA_CONSTANT_CHECK(equal( - at(int_<0>, BOOST_HANA_STRING("abc")), - char_<'a'> - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - at(int_<1>, BOOST_HANA_STRING("ab")), - char_<'b'> - )); - BOOST_HANA_CONSTANT_CHECK(equal( - at(int_<1>, BOOST_HANA_STRING("abc")), - char_<'b'> - )); - BOOST_HANA_CONSTANT_CHECK(equal( - at(int_<1>, BOOST_HANA_STRING("abcd")), - char_<'b'> - )); - - BOOST_HANA_CONSTANT_CHECK(equal( - at(int_<2>, BOOST_HANA_STRING("abc")), - char_<'c'> - )); - BOOST_HANA_CONSTANT_CHECK(equal( - at(int_<2>, BOOST_HANA_STRING("abcd")), - char_<'c'> - )); - } - - // operators - static_assert(has_operator{}, ""); - - // laws - test::TestIterable{strings}; - } }