From 486d0d55a665f0beae816463cf8abe4212bbccc1 Mon Sep 17 00:00:00 2001 From: Yamashta Daisuke Date: Sat, 2 Mar 2019 16:01:03 +0900 Subject: [PATCH] [basic_string] Added basic_string, wstring - Added classes basic_string and wstring. - Added macros BOOST_HANA_BASIC_STRING and BOOST_HANA_AUTO_STRING - Added user defined literal _s for basic_string if BOOST_HANA_CONFIG_ENABLE_BASIC_STRING_UDL directive is defined. - Added following integral_constant type aliases. wchar_, char16_, char32_, basic_char - Added following integral_constant constants. wchar_c, char16_c, char32_c, basic_char_c - Added unit test codes for basic_string and wstring. --- include/boost/hana/basic_string.hpp | 404 +++++++++++++++++++ include/boost/hana/fwd/basic_string.hpp | 276 +++++++++++++ include/boost/hana/fwd/integral_constant.hpp | 36 ++ include/boost/hana/wstring.hpp | 33 ++ test/basic_string/any_of.cpp | 43 ++ test/basic_string/at.cpp | 71 ++++ test/basic_string/c_str.cpp | 63 +++ test/basic_string/cnstr.c_str.cpp | 112 +++++ test/basic_string/cnstr.copy.cpp | 29 ++ test/basic_string/cnstr.default.cpp | 26 ++ test/basic_string/contains.cpp | 46 +++ test/basic_string/drop_front_exactly.cpp | 72 ++++ test/basic_string/equal.cpp | 87 ++++ test/basic_string/find.cpp | 65 +++ test/basic_string/find_if.cpp | 61 +++ test/basic_string/front.cpp | 47 +++ test/basic_string/hash.cpp | 53 +++ test/basic_string/is_empty.cpp | 31 ++ test/basic_string/laws_basic.hpp | 94 +++++ test/basic_string/laws_char.cpp | 28 ++ test/basic_string/laws_char16.cpp | 28 ++ test/basic_string/laws_char32.cpp | 28 ++ test/basic_string/laws_wchar.cpp | 28 ++ test/basic_string/length.cpp | 41 ++ test/basic_string/less.cpp | 88 ++++ test/basic_string/macro.cpp | 65 +++ test/basic_string/make.cpp | 74 ++++ test/basic_string/plus.cpp | 56 +++ test/basic_string/test_basic_string.hpp | 113 ++++++ test/basic_string/to.cpp | 60 +++ test/basic_string/udl.cpp | 59 +++ test/basic_string/unpack.cpp | 69 ++++ test/basic_string/zero.cpp | 26 ++ test/wstring/any_of.cpp | 37 ++ test/wstring/at.cpp | 81 ++++ test/wstring/c_str.cpp | 51 +++ test/wstring/cnstr.c_str.cpp | 81 ++++ test/wstring/cnstr.copy.cpp | 16 + test/wstring/cnstr.default.cpp | 13 + test/wstring/contains.cpp | 48 +++ test/wstring/drop_front_exactly.cpp | 55 +++ test/wstring/equal.cpp | 74 ++++ test/wstring/find.cpp | 41 ++ test/wstring/find_if.cpp | 46 +++ test/wstring/front.cpp | 38 ++ test/wstring/hash.cpp | 38 ++ test/wstring/is_empty.cpp | 22 + test/wstring/laws.cpp | 95 +++++ test/wstring/length.cpp | 30 ++ test/wstring/less.cpp | 70 ++++ test/wstring/macro.cpp | 36 ++ test/wstring/make.cpp | 47 +++ test/wstring/plus.cpp | 43 ++ test/wstring/test_wstring.hpp | 17 + test/wstring/to.cpp | 52 +++ test/wstring/udl.cpp | 24 ++ test/wstring/unpack.cpp | 48 +++ test/wstring/zero.cpp | 17 + 58 files changed, 3532 insertions(+) create mode 100644 include/boost/hana/basic_string.hpp create mode 100644 include/boost/hana/fwd/basic_string.hpp create mode 100644 include/boost/hana/wstring.hpp create mode 100644 test/basic_string/any_of.cpp create mode 100644 test/basic_string/at.cpp create mode 100644 test/basic_string/c_str.cpp create mode 100644 test/basic_string/cnstr.c_str.cpp create mode 100644 test/basic_string/cnstr.copy.cpp create mode 100644 test/basic_string/cnstr.default.cpp create mode 100644 test/basic_string/contains.cpp create mode 100644 test/basic_string/drop_front_exactly.cpp create mode 100644 test/basic_string/equal.cpp create mode 100644 test/basic_string/find.cpp create mode 100644 test/basic_string/find_if.cpp create mode 100644 test/basic_string/front.cpp create mode 100644 test/basic_string/hash.cpp create mode 100644 test/basic_string/is_empty.cpp create mode 100644 test/basic_string/laws_basic.hpp create mode 100644 test/basic_string/laws_char.cpp create mode 100644 test/basic_string/laws_char16.cpp create mode 100644 test/basic_string/laws_char32.cpp create mode 100644 test/basic_string/laws_wchar.cpp create mode 100644 test/basic_string/length.cpp create mode 100644 test/basic_string/less.cpp create mode 100644 test/basic_string/macro.cpp create mode 100644 test/basic_string/make.cpp create mode 100644 test/basic_string/plus.cpp create mode 100644 test/basic_string/test_basic_string.hpp create mode 100644 test/basic_string/to.cpp create mode 100644 test/basic_string/udl.cpp create mode 100644 test/basic_string/unpack.cpp create mode 100644 test/basic_string/zero.cpp create mode 100644 test/wstring/any_of.cpp create mode 100644 test/wstring/at.cpp create mode 100644 test/wstring/c_str.cpp create mode 100644 test/wstring/cnstr.c_str.cpp create mode 100644 test/wstring/cnstr.copy.cpp create mode 100644 test/wstring/cnstr.default.cpp create mode 100644 test/wstring/contains.cpp create mode 100644 test/wstring/drop_front_exactly.cpp create mode 100644 test/wstring/equal.cpp create mode 100644 test/wstring/find.cpp create mode 100644 test/wstring/find_if.cpp create mode 100644 test/wstring/front.cpp create mode 100644 test/wstring/hash.cpp create mode 100644 test/wstring/is_empty.cpp create mode 100644 test/wstring/laws.cpp create mode 100644 test/wstring/length.cpp create mode 100644 test/wstring/less.cpp create mode 100644 test/wstring/macro.cpp create mode 100644 test/wstring/make.cpp create mode 100644 test/wstring/plus.cpp create mode 100644 test/wstring/test_wstring.hpp create mode 100644 test/wstring/to.cpp create mode 100644 test/wstring/udl.cpp create mode 100644 test/wstring/unpack.cpp create mode 100644 test/wstring/zero.cpp diff --git a/include/boost/hana/basic_string.hpp b/include/boost/hana/basic_string.hpp new file mode 100644 index 0000000000..ddb1e3db5e --- /dev/null +++ b/include/boost/hana/basic_string.hpp @@ -0,0 +1,404 @@ +/*! +@file +Defines `boost::hana::basic_string`. + +@copyright Louis Dionne 2013-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_HANA_BASIC_STRING_HPP +#define BOOST_HANA_BASIC_STRING_HPP + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +BOOST_HANA_NAMESPACE_BEGIN + ////////////////////////////////////////////////////////////////////////// + // basic_string + ////////////////////////////////////////////////////////////////////////// + //! @cond + namespace detail { + template + constexpr CharT const basic_string_storage[sizeof...(s) + 1] = { + s..., static_cast('\0') + }; + } + + template + struct basic_string + : detail::operators::adl> + , detail::iterable_operators> + { + //using value_type = CharT; + static constexpr CharT const* c_str() { + return &detail::basic_string_storage[0]; + } + }; + //! @endcond + + template + struct tag_of> { + using type = basic_string_tag; + }; + + ////////////////////////////////////////////////////////////////////////// + // make + ////////////////////////////////////////////////////////////////////////// + template + struct make_impl> { + template + static constexpr auto apply(Chars const& ...) { + return hana::basic_string()...>(); + } + }; + + ////////////////////////////////////////////////////////////////////////// + // BOOST_HANA_STRING + ////////////////////////////////////////////////////////////////////////// + namespace basic_string_detail { + template + struct CastChar { + template + constexpr static CharTo apply = static_cast( + static_cast>(Value) + ); + }; + template + struct CastChar { + template + constexpr static CharT apply = Value; + }; + + template + constexpr auto + prepare_impl(S, std::integer_sequence) + -> basic_string< + std::decay_t)>, + Cast::template apply...> + { return {}; } + + template + constexpr decltype(auto) prepare(S s) { + return prepare_impl>( + s, + std::make_index_sequence< + sizeof(S::get())/sizeof(decltype(*S::get())) - 1 + >{} + ); + } + } + +#define BOOST_HANA_AUTO_STRING(s) \ + (::boost::hana::basic_string_detail::prepare< \ + std::decay_t, std::decay_t \ + >([]{ \ + struct tmp { \ + static constexpr decltype(auto) get() { return s; } \ + }; \ + return tmp{}; \ + }())) + +#define BOOST_HANA_BASIC_STRING(type, s) \ + (::boost::hana::basic_string_detail::prepare< \ + type, std::decay_t \ + >([]{ \ + struct tmp { \ + static constexpr decltype(auto) get() { return s; } \ + }; \ + return tmp{}; \ + }())) +/**/ + +#ifdef BOOST_HANA_CONFIG_ENABLE_BASIC_STRING_UDL + ////////////////////////////////////////////////////////////////////////// + // _s user-defined literal + ////////////////////////////////////////////////////////////////////////// + namespace literals { + template + constexpr auto operator"" _s() { + return hana::basic_string_c; + } + } +#endif + + ////////////////////////////////////////////////////////////////////////// + // Operators + ////////////////////////////////////////////////////////////////////////// + namespace detail { + template + struct comparable_operators> { + static constexpr bool value = true; + }; + template + struct orderable_operators> { + static constexpr bool value = true; + }; + } + + ////////////////////////////////////////////////////////////////////////// + // to + ////////////////////////////////////////////////////////////////////////// + template + struct to_impl> { + template + static constexpr CharT const* apply(basic_string const&) + { return basic_string::c_str(); } + }; + + ////////////////////////////////////////////////////////////////////////// + // to + ////////////////////////////////////////////////////////////////////////// + namespace detail { + template + constexpr std::size_t cx_bs_strlen(CharT const* s) { + std::size_t n = 0u; + while (*s != static_cast('\0')) + ++s, ++n; + return n; + } + + template + constexpr hana::basic_string()[I]...> + bs_expand(std::index_sequence) + { return {}; } + } + + template + struct to_impl, IC, hana::when< + hana::Constant::value && + std::is_convertible::value + >> { + template + static constexpr auto apply(S const&) { + constexpr CharT const* s = hana::value(); + constexpr std::size_t len = detail::cx_bs_strlen(s); + return detail::bs_expand(std::make_index_sequence{}); + } + }; + + ////////////////////////////////////////////////////////////////////////// + // Comparable + ////////////////////////////////////////////////////////////////////////// + template + struct equal_impl, basic_string_tag> { + template + static constexpr auto apply(S const&, S const&) + { return hana::true_c; } + + template + static constexpr auto apply(S1 const&, S2 const&) + { return hana::false_c; } + }; + + ////////////////////////////////////////////////////////////////////////// + // Orderable + ////////////////////////////////////////////////////////////////////////// + template + struct less_impl, basic_string_tag> { + template + static constexpr auto + apply(basic_string const&, + basic_string const&) { + constexpr CharT const c_str1[] = { s1..., + static_cast('\0') }; + constexpr CharT const c_str2[] = { s2..., + static_cast('\0') }; + return hana::bool_c; + } + }; + + ////////////////////////////////////////////////////////////////////////// + // Monoid + ////////////////////////////////////////////////////////////////////////// + template + struct plus_impl, basic_string_tag> { + template + static constexpr auto + apply(basic_string const&, + basic_string const&) { + return basic_string{}; + } + }; + + template + struct zero_impl> { + static constexpr auto apply() { + return basic_string{}; + } + }; + + template + constexpr auto operator+( + basic_string const&, basic_string const& + ) { + return hana::basic_string{}; + } + + ////////////////////////////////////////////////////////////////////////// + // Foldable + ////////////////////////////////////////////////////////////////////////// + template + struct unpack_impl> { + template + static constexpr decltype(auto) apply( + basic_string const&, F&&f + ) { + return static_cast(f)(basic_char_{}...); + } + }; + + template + struct length_impl> { + template + static constexpr auto apply(basic_string const&) { + return hana::size_c; + } + }; + + ////////////////////////////////////////////////////////////////////////// + // Iterable + ////////////////////////////////////////////////////////////////////////// + template + struct front_impl> { + template + static constexpr auto apply(basic_string const&) { + return hana::basic_char_c; + } + }; + + template + struct drop_front_impl> { + template + static constexpr auto helper( + basic_string const&, std::index_sequence + ) { + constexpr CharT s[] = { xs... }; + return hana::basic_string_c; + } + + template + static constexpr auto apply( + basic_string const& s, N const& + ) { + return helper(s, std::make_index_sequence< + N::value < sizeof...(xs) ? sizeof...(xs) - N::value : 0>{}); + } + + template + static constexpr auto apply(basic_string const& s, N const&) { + return s; + } + }; + + template + struct is_empty_impl> { + template + static constexpr auto apply(basic_string const&) { + return hana::bool_c; + } + }; + + template + struct at_impl> { + template + static constexpr auto apply( + basic_string const&, N const& + ) { + constexpr CharT characters[] = { s..., static_cast('\0') }; + constexpr auto n = N::value; + return hana::basic_char_c; + } + }; + + ////////////////////////////////////////////////////////////////////////// + // Searchable + ////////////////////////////////////////////////////////////////////////// + template + struct contains_impl> { + template + static constexpr auto + helper(basic_string const&, C const&, hana::true_) { + constexpr CharT const characters[] = { s..., + static_cast('\0') }; + constexpr CharT c = hana::value(); + return hana::bool_c< + detail::find(characters, characters + sizeof...(s), c) + != characters + sizeof...(s) + >; + } + + template + static constexpr auto helper(S const&, C const&, hana::false_) { + return hana::false_c; + } + + template + static constexpr auto apply(S const& s, C const& c) { + return helper(s, c, hana::bool_c::value>); + } + }; + + template + struct find_impl> { + template + static constexpr auto apply( + basic_string const& str, Ch const& c + ) { + return hana::if_( + contains_impl>::apply(str, c), + hana::just(c), + hana::nothing + ); + } + }; + + ////////////////////////////////////////////////////////////////////////// + // Hashable + ////////////////////////////////////////////////////////////////////////// + template + struct hash_impl> { + template + static constexpr auto apply(String const&) { + return hana::type_c; + } + }; +BOOST_HANA_NAMESPACE_END + +#endif // !BOOST_HANA_BASIC_STRING_HPP diff --git a/include/boost/hana/fwd/basic_string.hpp b/include/boost/hana/fwd/basic_string.hpp new file mode 100644 index 0000000000..fc66a73c1d --- /dev/null +++ b/include/boost/hana/fwd/basic_string.hpp @@ -0,0 +1,276 @@ +/*! +@file +Forward declares `boost::hana::basic_string`. + +@copyright Louis Dionne 2013-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_HANA_FWD_BASIC_STRING_HPP +#define BOOST_HANA_FWD_BASIC_STRING_HPP + +#include +#include +#include + + +BOOST_HANA_NAMESPACE_BEGIN +#ifdef BOOST_HANA_DOXYGEN_INVOKED + //! @ingroup group-datatypes + //! Compile-time basic_string. + //! + //! Conceptually, a `hana::string` is like a tuple holding + //! `integral_constant`s of underlying type `char`. However, the + //! interface of `hana::string` is not as rich as that of a tuple, + //! because a string can only hold compile-time characters as opposed + //! to any kind of object. + //! + //! Compile-time strings are used for simple purposes like being keys in a + //! `hana::map` or tagging the members of a `Struct`. However, you might + //! find that `hana::string` does not provide enough functionality to be + //! used as a full-blown compile-time string implementation (e.g. regexp + //! matching or substring finding). Indeed, providing a comprehensive + //! string interface is a lot of job, and it is out of the scope of the + //! library for the time being. + //! + //! + //! @note + //! The representation of `hana::basic_string` takes character type + //! template parameters are `char`s. + //! The proper way to access the contents of + //! a `hana::string` as character constants is to use `hana::unpack`, + //! `.c_str()` or `hana::to`, as documented below. More + //! details [in the tutorial](@ref tutorial-containers-types). + //! + //! + //! Modeled concepts + //! ---------------- + //! For most purposes, a `hana::basic_string` is functionally + //! equivalent to a tuple holding `Constant`s of underlying type `ChT`. + //! + //! 1. `Comparable`\n + //! Two strings are equal if and only if they have the same number of + //! characters and characters at corresponding indices are equal. + //! @include example/string/comparable.cpp + //! + //! 2. `Orderable`\n + //! The total order implemented for `Orderable` is the usual + //! lexicographical comparison of strings. + //! @include example/string/orderable.cpp + //! + //! 3. `Monoid`\n + //! Strings form a monoid under concatenation, with the neutral element + //! being the empty string. + //! @include example/string/monoid.cpp + //! + //! 4. `Foldable`\n + //! Folding a string is equivalent to folding the sequence of its + //! characters. + //! @include example/string/foldable.cpp + //! + //! 5. `Iterable`\n + //! Iterating over a string is equivalent to iterating over the sequence + //! of its characters. Also note that `operator[]` can be used instead of + //! the `at` function. + //! @include example/string/iterable.cpp + //! + //! 6. `Searchable`\n + //! Searching through a string is equivalent to searching through the + //! sequence of its characters. + //! @include example/string/searchable.cpp + //! + //! 7. `Hashable`\n + //! The hash of a compile-time string is a type uniquely representing + //! that string. + //! @include example/string/hashable.cpp + //! + //! + //! Conversion to `char const*` + //! --------------------------- + //! A `hana::string` can be converted to a `constexpr` null-delimited + //! string of type `char const*` by using the `c_str()` method or + //! `hana::to`. This makes it easy to turn a compile-time + //! string into a runtime string. However, note that this conversion is + //! not an embedding, because `char const*` does not model the same + //! concepts as `hana::string` does. + //! @include example/string/to.cpp + //! + //! Conversion from any Constant holding a `char const*` + //! ---------------------------------------------------- + //! A `hana::string` can be created from any `Constant` whose underlying + //! value is convertible to a `char const*` by using `hana::to`. The + //! contents of the `char const*` are used to build the content of the + //! `hana::string`. + //! @include example/string/from_c_str.cpp + //! + //! Rationale for `hana::string` not being a `Constant` itself + //! ---------------------------------------------------------- + //! The underlying type held by a `hana::string` could be either `char const*` + //! or some other constexpr-enabled string-like container. In the first case, + //! `hana::string` can not be a `Constant` because the models of several + //! concepts would not be respected by the underlying type, causing `value` + //! not to be structure-preserving. Providing an underlying value of + //! constexpr-enabled string-like container type like `std::string_view` + //! would be great, but that's a bit complicated for the time being. + template + struct basic_string { + // Default-construct a `hana::basic_string`; no-op since `hana::basic_string` is stateless. + constexpr basic_string() = default; + + // Copy-construct a `hana::basic_string`; no-op since `hana::basic_string` is stateless. + constexpr basic_string(basic_string const&) = default; + + //! Equivalent to `hana::equal` + template + friend constexpr auto operator==(X&& x, Y&& y); + + //! Equivalent to `hana::not_equal` + template + friend constexpr auto operator!=(X&& x, Y&& y); + + //! Equivalent to `hana::less` + template + friend constexpr auto operator<(X&& x, Y&& y); + + //! Equivalent to `hana::greater` + template + friend constexpr auto operator>(X&& x, Y&& y); + + //! Equivalent to `hana::less_equal` + template + friend constexpr auto operator<=(X&& x, Y&& y); + + //! Equivalent to `hana::greater_equal` + template + friend constexpr auto operator>=(X&& x, Y&& y); + + //! Performs concatenation; equivalent to `hana::plus` + template + friend constexpr auto operator+(X&& x, Y&& y); + + //! Equivalent to `hana::at` + template + constexpr decltype(auto) operator[](N&& n); + + //! Returns a null-delimited C-style string. + static constexpr Ch const* c_str(); + }; +#else + template + struct basic_string; +#endif + + //! Tag representing a compile-time string. + //! @relates hana::string + template + struct basic_string_tag { }; + +#ifdef BOOST_HANA_DOXYGEN_INVOKED + //! Create a compile-time `hana::string` from a parameter pack of `char` + //! `integral_constant`s. + //! @relates hana::string + //! + //! Given zero or more `integral_constant`s of underlying type `char`, + //! `make` creates a `hana::string` containing those characters. + //! This is provided mostly for consistency with the rest of the library, + //! as `hana::string_c` is more convenient to use in most cases. + //! + //! + //! Example + //! ------- + //! @include example/string/make.cpp + template + constexpr auto make> = [](auto&& ...chars) { + return basic_string{}; + }; +#endif + + //! Alias to `make`; provided for convenience. + //! @relates hana::string + template + constexpr auto make_basic_string = make>; + + //! Equivalent to `to`; provided for convenience. + //! @relates hana::string + template + constexpr auto to_basic_string = to>; + + //! Create a compile-time string from a parameter pack of characters. + //! @relates hana::string + //! + //! + //! Example + //! ------- + //! @include example/string/string_c.cpp +#ifdef BOOST_HANA_DOXYGEN_INVOKED + template + constexpr basic_string basic_string_c{}; +#else + template + constexpr basic_string basic_string_c{}; +#endif + + //! Create a compile-time string from a string literal. + //! @relates hana::basic_string + //! + //! This macro is a more convenient alternative to `basic_string_c` + //! for creating compile-time strings. However, since this macro uses + //! a lambda internally, it can't be used in an unevaluated context, + //! or where a constant expression is expected before C++17. + //! + //! + //! Example + //! ------- + //! @include example/basic_string/macro.cpp +#ifdef BOOST_HANA_DOXYGEN_INVOKED + auto BOOST_HANA_BASIC_STRING(type, s) = see documentation; + #define BOOST_HANA_BASIC_STRING(type, s) see documentation + + // Note: + // The trick above seems to exploit a bug in Doxygen, which makes the + // BOOST_HANA_STRING macro appear in the related objects of hana::string + // (as we want it to). +#else + // defined in +#endif + +#ifdef BOOST_HANA_CONFIG_ENABLE_BASIC_STRING_UDL + namespace literals { + //! Creates a compile-time string from a string literal. + //! @relatesalso boost::hana::string + //! + //! The string literal is parsed at compile-time and the result is + //! returned as a `hana::string`. This feature is an extension that + //! is disabled by default; see below for details. + //! + //! @note + //! Only narrow string literals are supported right now; support for + //! fancier types of string literals like wide or UTF-XX might be + //! added in the future if there is a demand for it. See [this issue] + //! [Hana.issue80] if you need this. + //! + //! @warning + //! This user-defined literal is an extension which requires a special + //! string literal operator that is not part of the standard yet. + //! That operator is supported by both Clang and GCC, and several + //! proposals were made for it to enter C++17. However, since it is + //! not standard, it is disabled by default and defining the + //! `BOOST_HANA_CONFIG_ENABLE_STRING_UDL` config macro is required + //! to get this operator. Hence, if you want to stay safe, just use + //! the `BOOST_HANA_STRING` macro instead. If you want to be fast and + //! furious (I do), define `BOOST_HANA_CONFIG_ENABLE_STRING_UDL`. + //! + //! + //! Example + //! ------- + //! @include example/string/literal.cpp + //! + //! [Hana.issue80]: https://github.com/boostorg/hana/issues/80 + template + constexpr auto operator"" _s(); + } +#endif +BOOST_HANA_NAMESPACE_END + +#endif // !BOOST_HANA_FWD_BASIC_STRING_HPP diff --git a/include/boost/hana/fwd/integral_constant.hpp b/include/boost/hana/fwd/integral_constant.hpp index 6ef1272d80..fd07d42dbd 100644 --- a/include/boost/hana/fwd/integral_constant.hpp +++ b/include/boost/hana/fwd/integral_constant.hpp @@ -69,6 +69,42 @@ BOOST_HANA_NAMESPACE_BEGIN constexpr char_ char_c{}; + //! @relates hana::integral_constant + template + using wchar_ = integral_constant; + + //! @relates hana::integral_constant + template + constexpr wchar_ wchar_c{}; + + + //! @relates hana::integral_constant + template + using char16_ = integral_constant; + + //! @relates hana::integral_constant + template + constexpr char16_ char16_c{}; + + + //! @relates hana::integral_constant + template + using char32_ = integral_constant; + + //! @relates hana::integral_constant + template + constexpr char32_ char32_c{}; + + + //! @relates hana::integral_constant + template + using basic_char_ = integral_constant; + + //! @relates hana::integral_constant + template + constexpr basic_char_ basic_char_c{}; + + //! @relates hana::integral_constant template using short_ = integral_constant; diff --git a/include/boost/hana/wstring.hpp b/include/boost/hana/wstring.hpp new file mode 100644 index 0000000000..e0b7b3b741 --- /dev/null +++ b/include/boost/hana/wstring.hpp @@ -0,0 +1,33 @@ +/*! +@file +Defines `boost::hana::wstring`. + +@copyright Louis Dionne 2013-2018 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_HANA_WSTRING_HPP +#define BOOST_HANA_WSTRING_HPP + +#include +#include +#include + +BOOST_HANA_NAMESPACE_BEGIN + +template +using wstring = basic_string; + +using wstring_tag = basic_string_tag; + +constexpr auto make_wstring = make; + +constexpr auto to_wstring = to; + +template +constexpr wstring wstring_c{}; + +BOOST_HANA_NAMESPACE_END + +#endif // !BOOST_HANA_WSTRING_HPP diff --git a/test/basic_string/any_of.cpp b/test/basic_string/any_of.cpp new file mode 100644 index 0000000000..9f94ee15f4 --- /dev/null +++ b/test/basic_string/any_of.cpp @@ -0,0 +1,43 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::equal.to(hana::basic_char_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + BOOST_HANA_BASIC_STRING(C, ""), + hana::always(hana::true_c) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::equal.to(hana::basic_char_c) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + BOOST_HANA_BASIC_STRING(C, "abc\x80" "d"), + hana::equal.to(hana::basic_char_c) + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/at.cpp b/test/basic_string/at.cpp new file mode 100644 index 0000000000..39e9502c93 --- /dev/null +++ b/test/basic_string/at.cpp @@ -0,0 +1,71 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_BASIC_STRING(C, "abcd")[hana::size_c<2>], + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "a"), hana::size_c<0>), + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "ab"), hana::size_c<0>), + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "abc"), hana::size_c<0>), + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "\xff" "abc"), hana::size_c<0>), + hana::basic_char_c + )); + + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "ab"), hana::size_c<1>), + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "abc"), hana::size_c<1>), + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "abcd"), hana::size_c<1>), + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "a\xc0" "bcd"), hana::size_c<1>), + hana::basic_char_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "abc"), hana::size_c<2>), + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "abcd"), hana::size_c<2>), + hana::basic_char_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_BASIC_STRING(C, "ab\x80" "cd"), hana::size_c<2>), + hana::basic_char_c + )); +} + +int main() { + test(); +} diff --git a/test/basic_string/c_str.cpp b/test/basic_string/c_str.cpp new file mode 100644 index 0000000000..d2d7469104 --- /dev/null +++ b/test/basic_string/c_str.cpp @@ -0,0 +1,63 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_BASIC_STRING(C, "").c_str(), + static_cast(CONVERT_STR("")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_BASIC_STRING(C, "a").c_str(), + static_cast(CONVERT_STR("a")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_BASIC_STRING(C, "ab").c_str(), + static_cast(CONVERT_STR("ab")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_BASIC_STRING(C, "abc").c_str(), + static_cast(CONVERT_STR("abc")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_BASIC_STRING(C, "abcd").c_str(), + static_cast(CONVERT_STR("abcd")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_BASIC_STRING(C, "a\xaa" "bc").c_str(), + static_cast(CONVERT_STR("a\xaa" "bc")) + ) == 0); + + // make sure we can turn a non-constexpr hana::basic_string + // into a constexpr C const* + { + auto str = BOOST_HANA_BASIC_STRING(C, "abc\x88" "def"); + constexpr C const* c_str = str.c_str(); + (void)c_str; + } + + // make sure c_str is actually a static member function + { + constexpr C const* c_str = hana::basic_string::c_str(); + (void)c_str; + } +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/cnstr.c_str.cpp b/test/basic_string/cnstr.c_str.cpp new file mode 100644 index 0000000000..28c4cbbf26 --- /dev/null +++ b/test/basic_string/cnstr.c_str.cpp @@ -0,0 +1,112 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" + +namespace hana = boost::hana; + +template +constexpr C const empty[] = { CONVERT_C('\0') }; +template +constexpr C const a[] = { CONVERT_C('a'), CONVERT_C('\0') }; +template +constexpr C const ab[] = { CONVERT_C('a'), CONVERT_C('b'), CONVERT_C('\0') }; +template +constexpr C const abc[] = { CONVERT_C('a'), CONVERT_C('b'), CONVERT_C('c'), CONVERT_C('\0') }; +template +constexpr C const abcd[] = { CONVERT_C('a'), CONVERT_C('b'), CONVERT_C('c'), CONVERT_C('d'), CONVERT_C('\0') }; +template +constexpr C const abxc[] = { CONVERT_C('a'), CONVERT_C('b'), CONVERT_C('\xa0'), CONVERT_C('c'), CONVERT_C('\0') }; + +template +void test() { + { + auto string = hana::to>( + hana::integral_constant>{} + ); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::basic_string_c)); + } + + { + auto string = hana::to>( + hana::integral_constant>{} + ); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::basic_string_c('a')>)); + } + + { + auto string = hana::to>( + hana::integral_constant>{} + ); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::basic_string_c('a'), + cast_c('b')>)); + } + + { + auto string = hana::to>( + hana::integral_constant>{} + ); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::basic_string_c('a'), + cast_c('b'), + cast_c('c') + >)); + } + + { + auto string = hana::to>( + hana::integral_constant>{} + ); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::basic_string_c('a'), + cast_c('b'), + cast_c('c'), + cast_c('d') + >)); + } + + { + auto string = hana::to>( + hana::integral_constant>{} + ); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::basic_string_c('a'), + cast_c('b'), + cast_c('\xa0'), + cast_c('c') + >)); + } + + // Make sure it also works with std::integral_constant, for example + { + auto string = hana::to>( + std::integral_constant>{} + ); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::basic_string_c)); + } + // Make sure the `to_string` shortcut works + { + auto string = hana::to_basic_string( + hana::integral_constant>{} + ); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::basic_string_c)); + } +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/cnstr.copy.cpp b/test/basic_string/cnstr.copy.cpp new file mode 100644 index 0000000000..b87b03d996 --- /dev/null +++ b/test/basic_string/cnstr.copy.cpp @@ -0,0 +1,29 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + using Str = decltype(hana::basic_string_c('a'), + cast_c('b'), + cast_c('\xff'), + cast_c('d')>); + Str s1{}; + Str s2(s1); + Str s3 = s1; + + (void)s2; (void)s3; +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/cnstr.default.cpp b/test/basic_string/cnstr.default.cpp new file mode 100644 index 0000000000..c93db3cf4e --- /dev/null +++ b/test/basic_string/cnstr.default.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + using Str = decltype(hana::basic_string_c('a'), + cast_c('b'), + cast_c('\xff'), + cast_c('d')>); + Str s{}; + (void)s; +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/contains.cpp b/test/basic_string/contains.cpp new file mode 100644 index 0000000000..4b930121ba --- /dev/null +++ b/test/basic_string/contains.cpp @@ -0,0 +1,46 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + + +struct invalid { }; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::contains( + BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::basic_char_c('a')> + )); + BOOST_HANA_CONSTANT_CHECK(hana::contains( + BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::basic_char_c('c')> + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::contains( + BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::basic_char_c('e')> + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::contains( + BOOST_HANA_BASIC_STRING(C, "abcd"), + invalid{} + ))); + BOOST_HANA_CONSTANT_CHECK(hana::contains( + BOOST_HANA_BASIC_STRING(C, "ab\xb0" "de"), + hana::basic_char_c('\xb0')> + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/drop_front_exactly.cpp b/test/basic_string/drop_front_exactly.cpp new file mode 100644 index 0000000000..43e1e9fadd --- /dev/null +++ b/test/basic_string/drop_front_exactly.cpp @@ -0,0 +1,72 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "a")), + BOOST_HANA_BASIC_STRING(C, "") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "ab")), + BOOST_HANA_BASIC_STRING(C, "b") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "abc")), + BOOST_HANA_BASIC_STRING(C, "bc") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "abcdefghijk")), + BOOST_HANA_BASIC_STRING(C, "bcdefghijk") + )); + + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "abc"), hana::size_c<2>), + BOOST_HANA_BASIC_STRING(C, "c") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "abcdefghijk"), hana::size_c<3>), + BOOST_HANA_BASIC_STRING(C, "defghijk") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "\xa0" "bc")), + BOOST_HANA_BASIC_STRING(C, "bc") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "a\xbb" "c")), + BOOST_HANA_BASIC_STRING(C, "\xbb" "c") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "\xa0\xb0" "c"), hana::size_c<2>), + BOOST_HANA_BASIC_STRING(C, "c") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_BASIC_STRING(C, "a\xb0" "\xc4"), hana::size_c<2>), + BOOST_HANA_BASIC_STRING(C, "\xc4") + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/equal.cpp b/test/basic_string/equal.cpp new file mode 100644 index 0000000000..730856bb8c --- /dev/null +++ b/test/basic_string/equal.cpp @@ -0,0 +1,87 @@ +// Copyright Louis Dionne 2013-2017 +// 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 // for operator != +namespace hana = boost::hana; + +template +void test() { + // equal + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_BASIC_STRING(C, "abcd"), + BOOST_HANA_BASIC_STRING(C, "abcd") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_BASIC_STRING(C, "\xffz\xc0"), + BOOST_HANA_BASIC_STRING(C, "\xffz\xc0") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_BASIC_STRING(C, "abcd"), + BOOST_HANA_BASIC_STRING(C, "abcde") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_BASIC_STRING(C, "abcd"), + BOOST_HANA_BASIC_STRING(C, "") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "abcde") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_BASIC_STRING(C, "\xa0"), + BOOST_HANA_BASIC_STRING(C, "abcde") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_BASIC_STRING(C, "\xa0"), + BOOST_HANA_BASIC_STRING(C, "") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "") + )); + + // check operators + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "abcd") + == + BOOST_HANA_BASIC_STRING(C, "abcd") + ); + + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "abcd") + != + BOOST_HANA_BASIC_STRING(C, "abc") + ); + + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "ab\xc0h") + == + BOOST_HANA_BASIC_STRING(C, "ab\xc0h") + ); + + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "ab\xc0\xd0h") + != + BOOST_HANA_BASIC_STRING(C, "ab\xc0h") + ); + +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/find.cpp b/test/basic_string/find.cpp new file mode 100644 index 0000000000..64a70cad8b --- /dev/null +++ b/test/basic_string/find.cpp @@ -0,0 +1,65 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + + +struct invalid { }; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::basic_char_c('a')>), + hana::just(hana::basic_char_c('a')>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::basic_char_c('c')>), + hana::just(hana::basic_char_c('c')>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_BASIC_STRING(C, "abc\xdcX"), + hana::basic_char_c('X')>), + hana::just(hana::basic_char_c('X')>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_BASIC_STRING(C, "abc\xff"), + hana::basic_char_c('\xff')>), + hana::just(hana::basic_char_c('\xff')>) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_BASIC_STRING(C, "abcd"), invalid{}), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_BASIC_STRING(C, "abcd\x80"), invalid{}), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_BASIC_STRING(C, "abcd\xe0"), + hana::basic_char_c('e')>), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::basic_char_c('\xaa')>), + hana::nothing + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/find_if.cpp b/test/basic_string/find_if.cpp new file mode 100644 index 0000000000..4bdd54f2f8 --- /dev/null +++ b/test/basic_string/find_if.cpp @@ -0,0 +1,61 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_BASIC_STRING(C, ""), + hana::always(hana::true_c)), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::equal.to(hana::basic_char_c('a')>)), + hana::just(hana::basic_char_c('a')>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::equal.to(hana::basic_char_c('c')>)), + hana::just(hana::basic_char_c('c')>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_BASIC_STRING(C, "abcd"), + hana::equal.to(hana::basic_char_c('d')>)), + hana::just(hana::basic_char_c('d')>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_BASIC_STRING(C, "\xa0" "bc"), + hana::equal.to(hana::basic_char_c('c')>)), + hana::just(hana::basic_char_c('c')>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_BASIC_STRING(C, "ab\xcc"), + hana::equal.to(hana::basic_char_c('\xcc')>)), + hana::just(hana::basic_char_c('\xcc')>) + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/front.cpp b/test/basic_string/front.cpp new file mode 100644 index 0000000000..0cf9be392f --- /dev/null +++ b/test/basic_string/front.cpp @@ -0,0 +1,47 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_BASIC_STRING(C, "a")), + hana::basic_char_c('a')> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_BASIC_STRING(C, "ab")), + hana::basic_char_c('a')> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_BASIC_STRING(C, "abc")), + hana::basic_char_c('a')> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_BASIC_STRING(C, "\xaa" "bc")), + hana::basic_char_c('\xaa')> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_BASIC_STRING(C, "\xaa\xbb" "c")), + hana::basic_char_c('\xaa')> + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/hash.cpp b/test/basic_string/hash.cpp new file mode 100644 index 0000000000..957c2d4d7c --- /dev/null +++ b/test/basic_string/hash.cpp @@ -0,0 +1,53 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::basic_string_c), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::basic_string_c), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::basic_string_c), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::basic_string_c), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::basic_string_c), + hana::type_c> + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/is_empty.cpp b/test/basic_string/is_empty.cpp new file mode 100644 index 0000000000..212ac1280c --- /dev/null +++ b/test/basic_string/is_empty.cpp @@ -0,0 +1,31 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::is_empty(BOOST_HANA_BASIC_STRING(C, ""))); + BOOST_HANA_CONSTANT_CHECK(hana::is_empty(hana::basic_string_c)); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(BOOST_HANA_BASIC_STRING(C, "a")))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(BOOST_HANA_BASIC_STRING(C, "ab")))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(BOOST_HANA_BASIC_STRING(C, "abc")))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(hana::basic_string_c))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(hana::basic_string_c))); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/laws_basic.hpp b/test/basic_string/laws_basic.hpp new file mode 100644 index 0000000000..0310846da1 --- /dev/null +++ b/test/basic_string/laws_basic.hpp @@ -0,0 +1,94 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void testComparable() { + auto strings = hana::make_tuple( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "a"), + BOOST_HANA_BASIC_STRING(C, "ab"), + BOOST_HANA_BASIC_STRING(C, "abcd"), + BOOST_HANA_BASIC_STRING(C, "abcde"), + BOOST_HANA_BASIC_STRING(C, "b\xaa" "a"), + BOOST_HANA_BASIC_STRING(C, "\x80\xaa" "c") + ); + + hana::test::TestComparable>{strings}; + hana::test::TestHashable>{strings}; +} + +template +void testMonoid() { + auto strings = hana::make_tuple( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "a"), + BOOST_HANA_BASIC_STRING(C, "ab"), + BOOST_HANA_BASIC_STRING(C, "abcd"), + BOOST_HANA_BASIC_STRING(C, "abcde"), + BOOST_HANA_BASIC_STRING(C, "b\xaa" "a"), + BOOST_HANA_BASIC_STRING(C, "\x80\xaa" "c") + ); + + hana::test::TestMonoid>{strings}; +} + +template +void testFoldable() { + auto strings = hana::make_tuple( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "a"), + BOOST_HANA_BASIC_STRING(C, "ab"), + BOOST_HANA_BASIC_STRING(C, "abcde"), + BOOST_HANA_BASIC_STRING(C, "ba"), + BOOST_HANA_BASIC_STRING(C, "afcd"), + BOOST_HANA_BASIC_STRING(C, "b\xaa" "a"), + BOOST_HANA_BASIC_STRING(C, "\x80\xaa" "c") + ); + + hana::test::TestFoldable>{strings}; + hana::test::TestIterable>{strings}; +} + +template +void testOrderable() { + auto strings = hana::make_tuple( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "a"), + BOOST_HANA_BASIC_STRING(C, "ab"), + BOOST_HANA_BASIC_STRING(C, "abc"), + BOOST_HANA_BASIC_STRING(C, "ba"), + BOOST_HANA_BASIC_STRING(C, "b\xaa" "a"), + BOOST_HANA_BASIC_STRING(C, "\x80\xaa" "c") + ); + + hana::test::TestOrderable>{strings}; +} + +template +void testSearchable() { + auto keys = hana::tuple_c('\x80'), cast_c('\xaa')>; + auto strings = hana::make_tuple( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "a"), + BOOST_HANA_BASIC_STRING(C, "abcd"), + BOOST_HANA_BASIC_STRING(C, "ba"), + BOOST_HANA_BASIC_STRING(C, "b\xaa" "a"), + BOOST_HANA_BASIC_STRING(C, "\x80\xaa" "c") + ); + + hana::test::TestSearchable>{strings, keys}; +} diff --git a/test/basic_string/laws_char.cpp b/test/basic_string/laws_char.cpp new file mode 100644 index 0000000000..1b0bdbbc54 --- /dev/null +++ b/test/basic_string/laws_char.cpp @@ -0,0 +1,28 @@ +#include "laws_basic.hpp" + +int main() { + // Comparable and Hashable + { + testComparable(); + } + + // Monoid + { + testMonoid(); + } + + // Foldable and Iterable + { + testFoldable(); + } + + // Orderable + { + testOrderable(); + } + + // Searchable + { + testSearchable(); + } +} diff --git a/test/basic_string/laws_char16.cpp b/test/basic_string/laws_char16.cpp new file mode 100644 index 0000000000..4b3e3283e4 --- /dev/null +++ b/test/basic_string/laws_char16.cpp @@ -0,0 +1,28 @@ +#include "laws_basic.hpp" + +int main() { + // Comparable and Hashable + { + testComparable(); + } + + // Monoid + { + testMonoid(); + } + + // Foldable and Iterable + { + testFoldable(); + } + + // Orderable + { + testOrderable(); + } + + // Searchable + { + testSearchable(); + } +} diff --git a/test/basic_string/laws_char32.cpp b/test/basic_string/laws_char32.cpp new file mode 100644 index 0000000000..dad8d64ed8 --- /dev/null +++ b/test/basic_string/laws_char32.cpp @@ -0,0 +1,28 @@ +#include "laws_basic.hpp" + +int main() { + // Comparable and Hashable + { + testComparable(); + } + + // Monoid + { + testMonoid(); + } + + // Foldable and Iterable + { + testFoldable(); + } + + // Orderable + { + testOrderable(); + } + + // Searchable + { + testSearchable(); + } +} diff --git a/test/basic_string/laws_wchar.cpp b/test/basic_string/laws_wchar.cpp new file mode 100644 index 0000000000..2ec8bb2d45 --- /dev/null +++ b/test/basic_string/laws_wchar.cpp @@ -0,0 +1,28 @@ +#include "laws_basic.hpp" + +int main() { + // Comparable and Hashable + { + testComparable(); + } + + // Monoid + { + testMonoid(); + } + + // Foldable and Iterable + { + testFoldable(); + } + + // Orderable + { + testOrderable(); + } + + // Searchable + { + testSearchable(); + } +} diff --git a/test/basic_string/length.cpp b/test/basic_string/length.cpp new file mode 100644 index 0000000000..8665c3e50e --- /dev/null +++ b/test/basic_string/length.cpp @@ -0,0 +1,41 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_BASIC_STRING(C, "")), + hana::size_c<0> + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_BASIC_STRING(C, "a")), + hana::size_c<1> + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_BASIC_STRING(C, "ab")), + hana::size_c<2> + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_BASIC_STRING(C, "abc")), + hana::size_c<3> + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_BASIC_STRING(C, "abc\xdd")), + hana::size_c<4> + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/less.cpp b/test/basic_string/less.cpp new file mode 100644 index 0000000000..034bdecaac --- /dev/null +++ b/test/basic_string/less.cpp @@ -0,0 +1,88 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "a") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + BOOST_HANA_BASIC_STRING(C, "a"), + BOOST_HANA_BASIC_STRING(C, "") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_BASIC_STRING(C, "a"), + BOOST_HANA_BASIC_STRING(C, "ab") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + BOOST_HANA_BASIC_STRING(C, "ab"), + BOOST_HANA_BASIC_STRING(C, "ab") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_BASIC_STRING(C, "abc"), + BOOST_HANA_BASIC_STRING(C, "abcde") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_BASIC_STRING(C, "abcde"), + BOOST_HANA_BASIC_STRING(C, "abfde") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_BASIC_STRING(C, "abc\xdc"), + BOOST_HANA_BASIC_STRING(C, "abc\xdd") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_BASIC_STRING(C, "abc"), + BOOST_HANA_BASIC_STRING(C, "abc\xdd" "e") + )); + + // check operators + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "abc") < BOOST_HANA_BASIC_STRING(C, "abcd") + ); + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "abc") <= BOOST_HANA_BASIC_STRING(C, "abcd") + ); + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "abc") <= BOOST_HANA_BASIC_STRING(C, "abcd") + ); + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "abc") <= BOOST_HANA_BASIC_STRING(C, "abcd\xdf") + ); + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "abcd") > BOOST_HANA_BASIC_STRING(C, "abc") + ); + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_BASIC_STRING(C, "abc\xd0") >= BOOST_HANA_BASIC_STRING(C, "abc") + ); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/macro.cpp b/test/basic_string/macro.cpp new file mode 100644 index 0000000000..9561e61286 --- /dev/null +++ b/test/basic_string/macro.cpp @@ -0,0 +1,65 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + // make sure string_c and BOOST_HANA_STRING give the same result + + { + auto const s1 = BOOST_HANA_BASIC_STRING(C, ""); + auto const s2 = hana::basic_string_c; + static_assert(std::is_same::value, ""); + } + { + auto const s1 = BOOST_HANA_BASIC_STRING(C, "a"); + auto const s2 = hana::basic_string_c; + static_assert(std::is_same::value, ""); + } + { + auto const s1 = BOOST_HANA_BASIC_STRING(C, "abcd"); + auto const s2 = hana::basic_string_c; + static_assert(std::is_same::value, ""); + } +} + +void test_auto() { + { + auto const s1 = BOOST_HANA_AUTO_STRING("abc"); + auto const s2 = hana::basic_string_c; + static_assert(std::is_same::value, ""); + } + { + auto const s1 = BOOST_HANA_AUTO_STRING(L"ab\xabcd"); + auto const s2 = hana::basic_string_c; + static_assert(std::is_same::value, ""); + } + { + auto const s1 = BOOST_HANA_AUTO_STRING(u"ab\xabcd"); + auto const s2 = hana::basic_string_c; + static_assert(std::is_same::value, ""); + } + { + auto const s1 = BOOST_HANA_AUTO_STRING(U"ab\xabcdef12"); + auto const s2 = hana::basic_string_c; + static_assert(std::is_same::value, ""); + } +} + +int main() { + test(); + test(); + test(); + test(); + + test_auto(); +} diff --git a/test/basic_string/make.cpp b/test/basic_string/make.cpp new file mode 100644 index 0000000000..fa2031cb9e --- /dev/null +++ b/test/basic_string/make.cpp @@ -0,0 +1,74 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make>(), + hana::basic_string_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make>( + hana::basic_char_c('a')>), + hana::basic_string_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make>( + hana::basic_char_c('a')>, + hana::basic_char_c('b')>), + hana::basic_string_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make>( + hana::basic_char_c('a')>, + hana::basic_char_c('b')>, + hana::basic_char_c('c')>), + hana::basic_string_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make>( + hana::basic_char_c('a')>, + hana::basic_char_c('b')>, + hana::basic_char_c('c')>, + hana::basic_char_c('d')>), + hana::basic_string_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make>( + hana::basic_char_c('a')>, + hana::basic_char_c('b')>, + hana::basic_char_c('c')>, + hana::basic_char_c('\xdd')>), + hana::basic_string_c + )); + + // make sure make_basic_string == make> + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_basic_string( + hana::basic_char_c('a')>, + hana::basic_char_c('b')>, + hana::basic_char_c('c')>), + hana::make>( + hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c) + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/plus.cpp b/test/basic_string/plus.cpp new file mode 100644 index 0000000000..dfab5b3bcf --- /dev/null +++ b/test/basic_string/plus.cpp @@ -0,0 +1,56 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "")), + BOOST_HANA_BASIC_STRING(C, "") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_BASIC_STRING(C, "abcd"), + BOOST_HANA_BASIC_STRING(C, "")), + BOOST_HANA_BASIC_STRING(C, "abcd") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_BASIC_STRING(C, ""), + BOOST_HANA_BASIC_STRING(C, "abcd")), + BOOST_HANA_BASIC_STRING(C, "abcd") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_BASIC_STRING(C, "abcd"), + BOOST_HANA_BASIC_STRING(C, "efg")), + BOOST_HANA_BASIC_STRING(C, "abcdefg") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_BASIC_STRING(C, "ab\xcc"), + BOOST_HANA_BASIC_STRING(C, "de\xff")), + BOOST_HANA_BASIC_STRING(C, "ab\xcc" "de\xff") + )); + + // check operator + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_BASIC_STRING(C, "abc") + BOOST_HANA_BASIC_STRING(C, "def"), + BOOST_HANA_BASIC_STRING(C, "abcdef") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_BASIC_STRING(C, "ab\xcc") + + BOOST_HANA_BASIC_STRING(C, "de\xff"), + BOOST_HANA_BASIC_STRING(C, "ab\xcc" "de\xff") + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/test_basic_string.hpp b/test/basic_string/test_basic_string.hpp new file mode 100644 index 0000000000..e953ac336a --- /dev/null +++ b/test/basic_string/test_basic_string.hpp @@ -0,0 +1,113 @@ +/*! +@file +Defines `unit test`. + +@copyright Louis Dionne 2013-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ +template +int basic_strcmp(C const* l, C const* r) { + for (;*l != static_cast('\0'); l++, r++) { + if (*l != *r) { + return *l < *r ? -1 : 1; + } + } + return *r == static_cast('\0') ? 0 : -1; +} + +struct CharChooser { + char a_char; + wchar_t a_wchar; + char16_t a_char16; + char32_t a_char32; + + constexpr CharChooser( + char a_char, + wchar_t a_wchar, + char16_t a_char16, + char32_t a_char32 + ) : a_char{a_char}, + a_wchar{a_wchar}, + a_char16{a_char16}, + a_char32{a_char32} + { + } + + template + constexpr operator Ch() const noexcept; +}; + +template <> +constexpr CharChooser::operator char() const noexcept { + return a_char; +} + +template <> +constexpr CharChooser::operator wchar_t() const noexcept { + return a_wchar; +} + +template <> +constexpr CharChooser::operator char16_t() const noexcept { + return a_char16; +} + +template <> +constexpr CharChooser::operator char32_t() const noexcept { + return a_char32; +} + +struct LiteralChooser { + char const* char_literal; + wchar_t const* wchar_literal; + char16_t const* char16_literal; + char32_t const* char32_literal; + + constexpr LiteralChooser( + char const* char_literal, + wchar_t const* wchar_literal, + char16_t const* char16_literal, + char32_t const* char32_literal + ) : char_literal(char_literal), + wchar_literal(wchar_literal), + char16_literal(char16_literal), + char32_literal(char32_literal) + { + } + template + constexpr operator Ch const *() const noexcept; +}; + +template <> +constexpr LiteralChooser::operator char const*() const noexcept { + return char_literal; +} + +template <> +constexpr LiteralChooser::operator wchar_t const*() const noexcept { + return wchar_literal; +} + +template <> +constexpr LiteralChooser::operator char16_t const*() const noexcept { + return char16_literal; +} + +template <> +constexpr LiteralChooser::operator char32_t const*() const noexcept { + return char32_literal; +} + +#define CNV_CHTYPE(CH, PREFIX) (PREFIX ## CH) +#define CONVERT_C(CH) \ + CharChooser{ CH, CNV_CHTYPE(CH,L), CNV_CHTYPE(CH,u), CNV_CHTYPE(CH,U) } +#define CAST_C(TYPE, CH) \ + static_cast(static_cast>(CH)) +#define CONVERT_STR(CH) \ + LiteralChooser{ CH, CNV_CHTYPE(CH,L), CNV_CHTYPE(CH,u), CNV_CHTYPE(CH,U) } + +template +constexpr C cast_c(char c) { + return static_cast(static_cast>(c)); +} diff --git a/test/basic_string/to.cpp b/test/basic_string/to.cpp new file mode 100644 index 0000000000..b41f6535a5 --- /dev/null +++ b/test/basic_string/to.cpp @@ -0,0 +1,60 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + + +template +void test() { + static_assert(hana::is_convertible, C const*>{}, ""); + static_assert(!hana::is_embedded, C const*>{}, ""); + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_BASIC_STRING(C, "")), + static_cast(CONVERT_STR("")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_BASIC_STRING(C, "a")), + static_cast(CONVERT_STR("a")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_BASIC_STRING(C, "ab")), + static_cast(CONVERT_STR("ab")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_BASIC_STRING(C, "abc")), + static_cast(CONVERT_STR("abc")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_BASIC_STRING(C, "abcd")), + static_cast(CONVERT_STR("abcd")) + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_BASIC_STRING(C, "ab\x80\xff" "cd")), + static_cast(CONVERT_STR("ab\x80\xff" "cd")) + ) == 0); + + + // make sure we can turn a non-constexpr hana::basic_string + // into a constexpr C const* + auto str = BOOST_HANA_BASIC_STRING(C, "abcdef\xc0" "ghi"); + constexpr C const* c_str = hana::to(str); + (void)c_str; +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/udl.cpp b/test/basic_string/udl.cpp new file mode 100644 index 0000000000..e813da5d15 --- /dev/null +++ b/test/basic_string/udl.cpp @@ -0,0 +1,59 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +#ifdef BOOST_HANA_CONFIG_ENABLE_BASIC_STRING_UDL +template +struct str1; + +template <> +struct str1 { + using namespace hana::literals; + constexpr static auto value = "abcd"_s; +}; + +template <> +struct str1 { + using namespace hana::literals; + constexpr static auto value = L"abcd"_s; +}; + +template <> +struct str1 { + using namespace hana::literals; + constexpr static auto value = u"abcd"_s; +}; + +template <> +struct str1 { + using namespace hana::literals; + constexpr static auto value = U"abcd"_s; +}; +#endif + +template +void test() { + // Check the _s user-defined literal +#ifdef BOOST_HANA_CONFIG_ENABLE_BASIC_STRING_UDL + + constexpr auto s1 = str1::value; + constexpr auto s2 = hana::string_c; + static_assert(std::is_same::value, ""); +#endif +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/unpack.cpp b/test/basic_string/unpack.cpp new file mode 100644 index 0000000000..15bb8eac10 --- /dev/null +++ b/test/basic_string/unpack.cpp @@ -0,0 +1,69 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_basic_string.hpp" +namespace hana = boost::hana; + +template +void test() { + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_BASIC_STRING(C, ""), f), + f() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_BASIC_STRING(C, "a"), f), + f(hana::basic_char_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_BASIC_STRING(C, "ab"), f), + f(hana::basic_char_c, + hana::basic_char_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_BASIC_STRING(C, "abc"), f), + f(hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_BASIC_STRING(C, "abcd"), f), + f(hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_BASIC_STRING(C, "abcde"), f), + f(hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_BASIC_STRING(C, "ab\xcc" "de\xff"), f), + f(hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c, + hana::basic_char_c) + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/basic_string/zero.cpp b/test/basic_string/zero.cpp new file mode 100644 index 0000000000..d214e0a2bd --- /dev/null +++ b/test/basic_string/zero.cpp @@ -0,0 +1,26 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +template +void test() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zero>(), + BOOST_HANA_BASIC_STRING(C, "") + )); +} + +int main() { + test(); + test(); + test(); + test(); +} diff --git a/test/wstring/any_of.cpp b/test/wstring/any_of.cpp new file mode 100644 index 0000000000..d1347eb939 --- /dev/null +++ b/test/wstring/any_of.cpp @@ -0,0 +1,37 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + BOOST_HANA_AUTO_STRING(L"abcd"), + hana::equal.to(hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::any_of( + BOOST_HANA_AUTO_STRING(L"\xabcd\xef12\x3456"), + hana::equal.to(hana::wchar_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + BOOST_HANA_AUTO_STRING(L""), + hana::always(hana::true_c) + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + BOOST_HANA_AUTO_STRING(L"abcd"), + hana::equal.to(hana::wchar_c) + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::any_of( + BOOST_HANA_AUTO_STRING(L"\xabcd\xef12\x3456"), + hana::equal.to(hana::wchar_c) + ))); +} diff --git a/test/wstring/at.cpp b/test/wstring/at.cpp new file mode 100644 index 0000000000..3fdb061675 --- /dev/null +++ b/test/wstring/at.cpp @@ -0,0 +1,81 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_AUTO_STRING(L"abcd")[hana::size_c<2>], + hana::wchar_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"a"), hana::size_c<0>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"ab"), hana::size_c<0>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"abc"), hana::size_c<0>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"\xabcd"), hana::size_c<0>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"\xabcd" L"e"), hana::size_c<0>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"\xabcd\xef12"), hana::size_c<0>), + hana::wchar_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"ab"), hana::size_c<1>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"abc"), hana::size_c<1>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"abcd"), hana::size_c<1>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"\xabcd" L"e"), hana::size_c<1>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"\xabcd\xef12"), hana::size_c<1>), + hana::wchar_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"abc"), hana::size_c<2>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"abcd"), hana::size_c<2>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"\xabcd" L"ef"), hana::size_c<2>), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at(BOOST_HANA_AUTO_STRING(L"\xabcd\xef12\x3456"), hana::size_c<2>), + hana::wchar_c + )); +} diff --git a/test/wstring/c_str.cpp b/test/wstring/c_str.cpp new file mode 100644 index 0000000000..7a5c25914c --- /dev/null +++ b/test/wstring/c_str.cpp @@ -0,0 +1,51 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_wstring.hpp" +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_AUTO_STRING(L"").c_str(), + L"" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_AUTO_STRING(L"a").c_str(), + L"a" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_AUTO_STRING(L"ab").c_str(), + L"ab" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_AUTO_STRING(L"abc").c_str(), + L"abc" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + BOOST_HANA_AUTO_STRING(L"abcd").c_str(), + L"abcd" + ) == 0); + + // make sure we can turn a non-constexpr hana::string + // into a constexpr char const* + { + auto str = BOOST_HANA_AUTO_STRING(L"abcdef"); + constexpr wchar_t const* c_str = str.c_str(); + (void)c_str; + } + + // make sure c_str is actually a static member function + { + constexpr wchar_t const* c_str = hana::wstring<'f', 'o', 'o'>::c_str(); + (void)c_str; + } +} diff --git a/test/wstring/cnstr.c_str.cpp b/test/wstring/cnstr.c_str.cpp new file mode 100644 index 0000000000..51a6e42b22 --- /dev/null +++ b/test/wstring/cnstr.c_str.cpp @@ -0,0 +1,81 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +constexpr wchar_t const empty[] = L""; +constexpr wchar_t const a[] = L"a"; +constexpr wchar_t const ab[] = L"ab"; +constexpr wchar_t const abc[] = L"abc"; +constexpr wchar_t const abcd[] = L"abcd"; +constexpr wchar_t const xa[] = L"\xaaaa"; +constexpr wchar_t const xabc[] = L"\xaaaa\xbbbb\xcccc"; + +int main() { + { + auto string = hana::to(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c<>)); + } + + { + auto string = hana::to(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + { + auto string = hana::to(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + { + auto string = hana::to(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + { + auto string = hana::to(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + { + auto string = hana::to(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + { + auto string = hana::to(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + // Make sure it also works with std::integral_constant, for example + { + auto string = hana::to(std::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + { + auto string = hana::to(std::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + // Make sure the `to_wstring` shortcut works + { + auto string = hana::to_wstring(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } + + { + auto string = hana::to_wstring(hana::integral_constant{}); + BOOST_HANA_CONSTANT_CHECK(hana::equal(string, hana::wstring_c)); + } +} diff --git a/test/wstring/cnstr.copy.cpp b/test/wstring/cnstr.copy.cpp new file mode 100644 index 0000000000..0df5a5cdf0 --- /dev/null +++ b/test/wstring/cnstr.copy.cpp @@ -0,0 +1,16 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + using Str = decltype(hana::wstring_c); + Str s1{}; + Str s2(s1); + Str s3 = s1; + + (void)s2; (void)s3; +} diff --git a/test/wstring/cnstr.default.cpp b/test/wstring/cnstr.default.cpp new file mode 100644 index 0000000000..c8af9b8b5c --- /dev/null +++ b/test/wstring/cnstr.default.cpp @@ -0,0 +1,13 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + using Str = decltype(hana::wstring_c); + Str s{}; + (void)s; +} diff --git a/test/wstring/contains.cpp b/test/wstring/contains.cpp new file mode 100644 index 0000000000..52793565cc --- /dev/null +++ b/test/wstring/contains.cpp @@ -0,0 +1,48 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +struct invalid { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::contains( + BOOST_HANA_AUTO_STRING(L"abcd"), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::contains( + BOOST_HANA_AUTO_STRING(L"abcd"), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::contains( + BOOST_HANA_AUTO_STRING(L"abcd\xef01"), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::contains( + BOOST_HANA_AUTO_STRING(L"abcd\xef01"), + hana::wchar_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::contains( + BOOST_HANA_AUTO_STRING(L"abcd"), + hana::wchar_c + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::contains( + BOOST_HANA_AUTO_STRING(L"abcd"), + invalid{} + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::contains( + BOOST_HANA_AUTO_STRING(L"abcd\xefab"), + hana::wchar_c + ))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::contains( + BOOST_HANA_AUTO_STRING(L"abcd\xef01"), + invalid{} + ))); +} diff --git a/test/wstring/drop_front_exactly.cpp b/test/wstring/drop_front_exactly.cpp new file mode 100644 index 0000000000..7639575158 --- /dev/null +++ b/test/wstring/drop_front_exactly.cpp @@ -0,0 +1,55 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_AUTO_STRING(L"a")), + BOOST_HANA_AUTO_STRING(L"") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_AUTO_STRING(L"ab")), + BOOST_HANA_AUTO_STRING(L"b") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_AUTO_STRING(L"abc")), + BOOST_HANA_AUTO_STRING(L"bc") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_AUTO_STRING(L"abcdefghijk")), + BOOST_HANA_AUTO_STRING(L"bcdefghijk") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_AUTO_STRING(L"\xabcd" L"efg")), + BOOST_HANA_AUTO_STRING(L"efg") + )); + + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_AUTO_STRING(L"abc"), hana::size_c<2>), + BOOST_HANA_AUTO_STRING(L"c") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_AUTO_STRING(L"abcdefghijk"), hana::size_c<3>), + BOOST_HANA_AUTO_STRING(L"defghijk") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::drop_front_exactly(BOOST_HANA_AUTO_STRING(L"a\xbcde\xf012" L"abc"), hana::size_c<2>), + BOOST_HANA_AUTO_STRING(L"\xf012" L"abc") + )); + +} diff --git a/test/wstring/equal.cpp b/test/wstring/equal.cpp new file mode 100644 index 0000000000..9d969df5e0 --- /dev/null +++ b/test/wstring/equal.cpp @@ -0,0 +1,74 @@ +// Copyright Louis Dionne 2013-2017 +// 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 // for operator != +#include +namespace hana = boost::hana; + + +int main() { + // equal + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_AUTO_STRING(L"abcd"), + BOOST_HANA_AUTO_STRING(L"abcd") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_AUTO_STRING(L"\xabcd\xef01"), + BOOST_HANA_AUTO_STRING(L"\xabcd\xef01") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_AUTO_STRING(L"abcd"), + BOOST_HANA_AUTO_STRING(L"abcde") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_AUTO_STRING(L"abcd"), + BOOST_HANA_AUTO_STRING(L"") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_AUTO_STRING(L"\xaa00"), + BOOST_HANA_AUTO_STRING(L"") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"abcde") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"") + )); + + // check operators + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_AUTO_STRING(L"abcd") + == + BOOST_HANA_AUTO_STRING(L"abcd") + ); + + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_AUTO_STRING(L"\xabcd") + == + BOOST_HANA_AUTO_STRING(L"\xabcd") + ); + + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_AUTO_STRING(L"abcd") + != + BOOST_HANA_AUTO_STRING(L"abc") + ); + + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_AUTO_STRING(L"\xabcd") + != + BOOST_HANA_AUTO_STRING(L"\xabc0") + ); +} diff --git a/test/wstring/find.cpp b/test/wstring/find.cpp new file mode 100644 index 0000000000..12c59819e3 --- /dev/null +++ b/test/wstring/find.cpp @@ -0,0 +1,41 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +struct invalid { }; + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_AUTO_STRING(L"abcd"), hana::wchar_c), + hana::just(hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_AUTO_STRING(L"abcd"), hana::wchar_c), + hana::just(hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_AUTO_STRING(L"\x9876" L"abcd"), hana::wchar_c), + hana::just(hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_AUTO_STRING(L"\x9876" L"abcd"), hana::wchar_c), + hana::just(hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_AUTO_STRING(L"abcd"), invalid{}), + hana::nothing + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find(BOOST_HANA_AUTO_STRING(L"\xabcd"), invalid{}), + hana::nothing + )); +} diff --git a/test/wstring/find_if.cpp b/test/wstring/find_if.cpp new file mode 100644 index 0000000000..a6531edf6d --- /dev/null +++ b/test/wstring/find_if.cpp @@ -0,0 +1,46 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_AUTO_STRING(L""), hana::always(hana::true_c)), + hana::nothing + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_AUTO_STRING(L"abcd"), hana::equal.to(hana::wchar_c)), + hana::just(hana::wchar_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_AUTO_STRING(L"abcd"), hana::equal.to(hana::wchar_c)), + hana::just(hana::wchar_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_AUTO_STRING(L"abcd"), hana::equal.to(hana::wchar_c)), + hana::just(hana::wchar_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_AUTO_STRING(L"abcd\xef01"), hana::equal.to(hana::wchar_c)), + hana::just(hana::wchar_c) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::find_if(BOOST_HANA_AUTO_STRING(L"abcd\xef01"), hana::equal.to(hana::wchar_c)), + hana::nothing + )); +} diff --git a/test/wstring/front.cpp b/test/wstring/front.cpp new file mode 100644 index 0000000000..d348cdde12 --- /dev/null +++ b/test/wstring/front.cpp @@ -0,0 +1,38 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_AUTO_STRING(L"a")), + hana::wchar_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_AUTO_STRING(L"ab")), + hana::wchar_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_AUTO_STRING(L"abc")), + hana::wchar_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_AUTO_STRING(L"a\xbcde")), + hana::wchar_c + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::front(BOOST_HANA_AUTO_STRING(L"\xabcd" L"efgh")), + hana::wchar_c + )); +} diff --git a/test/wstring/hash.cpp b/test/wstring/hash.cpp new file mode 100644 index 0000000000..6bc9f2a473 --- /dev/null +++ b/test/wstring/hash.cpp @@ -0,0 +1,38 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::wstring_c<>), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::wstring_c), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::wstring_c), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::wstring_c), + hana::type_c> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::hash(hana::wstring_c), + hana::type_c> + )); +} diff --git a/test/wstring/is_empty.cpp b/test/wstring/is_empty.cpp new file mode 100644 index 0000000000..4a4f450d69 --- /dev/null +++ b/test/wstring/is_empty.cpp @@ -0,0 +1,22 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::is_empty(BOOST_HANA_AUTO_STRING(L""))); + BOOST_HANA_CONSTANT_CHECK(hana::is_empty(hana::wstring_c<>)); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(BOOST_HANA_AUTO_STRING(L"a")))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(BOOST_HANA_AUTO_STRING(L"ab")))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(BOOST_HANA_AUTO_STRING(L"abc")))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(hana::wstring_c))); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(hana::wstring_c))); +} diff --git a/test/wstring/laws.cpp b/test/wstring/laws.cpp new file mode 100644 index 0000000000..b8d76b3b43 --- /dev/null +++ b/test/wstring/laws.cpp @@ -0,0 +1,95 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + // Comparable and Hashable + { + auto strings = hana::make_tuple( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"a"), + BOOST_HANA_AUTO_STRING(L"ab"), + BOOST_HANA_AUTO_STRING(L"abc\xdef0"), + BOOST_HANA_AUTO_STRING(L"abcd\xef01"), + BOOST_HANA_AUTO_STRING(L"abcde\xf012"), + BOOST_HANA_AUTO_STRING(L"ba\xbcde") + ); + + hana::test::TestComparable{strings}; + hana::test::TestHashable{strings}; + } + + // Monoid + { + auto strings = hana::make_tuple( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"a"), + BOOST_HANA_AUTO_STRING(L"ab"), + BOOST_HANA_AUTO_STRING(L"abc\xdef0"), + BOOST_HANA_AUTO_STRING(L"abcd\xef01"), + BOOST_HANA_AUTO_STRING(L"abcde\xf012"), + BOOST_HANA_AUTO_STRING(L"ba\xbcde") + ); + + hana::test::TestMonoid{strings}; + } + + // Foldable and Iterable + { + auto strings = hana::make_tuple( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"a"), + BOOST_HANA_AUTO_STRING(L"ab"), + BOOST_HANA_AUTO_STRING(L"abc\xdef0"), + BOOST_HANA_AUTO_STRING(L"abcd\xef01"), + BOOST_HANA_AUTO_STRING(L"abcde\xf012"), + BOOST_HANA_AUTO_STRING(L"ba\xbcde"), + BOOST_HANA_AUTO_STRING(L"afcd\xef01") + ); + + hana::test::TestFoldable{strings}; + hana::test::TestIterable{strings}; + } + + // Orderable + { + auto strings = hana::make_tuple( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"a"), + BOOST_HANA_AUTO_STRING(L"ab"), + BOOST_HANA_AUTO_STRING(L"abc\xdef0"), + BOOST_HANA_AUTO_STRING(L"ba\xbcde"), + BOOST_HANA_AUTO_STRING(L"abd\xef01") + ); + + hana::test::TestOrderable{strings}; + } + + // Searchable + { + auto keys = hana::tuple_c; + auto strings = hana::make_tuple( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"a"), + BOOST_HANA_AUTO_STRING(L"ab"), + BOOST_HANA_AUTO_STRING(L"abcd\xef01"), + BOOST_HANA_AUTO_STRING(L"ba\xbcde"), + BOOST_HANA_AUTO_STRING(L"afcd") + ); + + hana::test::TestSearchable{strings, keys}; + } +} diff --git a/test/wstring/length.cpp b/test/wstring/length.cpp new file mode 100644 index 0000000000..0aa627b925 --- /dev/null +++ b/test/wstring/length.cpp @@ -0,0 +1,30 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_AUTO_STRING(L"")), + hana::size_c<0> + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_AUTO_STRING(L"a")), + hana::size_c<1> + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_AUTO_STRING(L"ab")), + hana::size_c<2> + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::length(BOOST_HANA_AUTO_STRING(L"abc")), + hana::size_c<3> + )); +} diff --git a/test/wstring/less.cpp b/test/wstring/less.cpp new file mode 100644 index 0000000000..190d7d7633 --- /dev/null +++ b/test/wstring/less.cpp @@ -0,0 +1,70 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_AUTO_STRING(L""), + BOOST_HANA_AUTO_STRING(L"a") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + BOOST_HANA_AUTO_STRING(L"a"), + BOOST_HANA_AUTO_STRING(L"") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_AUTO_STRING(L"a"), + BOOST_HANA_AUTO_STRING(L"ab") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::less( + BOOST_HANA_AUTO_STRING(L"ab"), + BOOST_HANA_AUTO_STRING(L"ab") + ))); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_AUTO_STRING(L"abc"), + BOOST_HANA_AUTO_STRING(L"abcde") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_AUTO_STRING(L"abcde"), + BOOST_HANA_AUTO_STRING(L"abfde") + )); + + BOOST_HANA_CONSTANT_CHECK(hana::less( + BOOST_HANA_AUTO_STRING(L"\xabcd"), + BOOST_HANA_AUTO_STRING(L"\xabcd\xabcd") + )); + + // check operators + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_AUTO_STRING(L"abc") < BOOST_HANA_AUTO_STRING(L"abcd") + ); + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_AUTO_STRING(L"abc") <= BOOST_HANA_AUTO_STRING(L"abcd") + ); + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_AUTO_STRING(L"abcd") > BOOST_HANA_AUTO_STRING(L"abc") + ); + BOOST_HANA_CONSTANT_CHECK( + BOOST_HANA_AUTO_STRING(L"abcd") >= BOOST_HANA_AUTO_STRING(L"abc") + ); +} diff --git a/test/wstring/macro.cpp b/test/wstring/macro.cpp new file mode 100644 index 0000000000..ad66829889 --- /dev/null +++ b/test/wstring/macro.cpp @@ -0,0 +1,36 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + // make sure wstring_c and BOOST_HANA_AUTO_STRING give the same result + + { + auto const s1 = BOOST_HANA_AUTO_STRING(L""); + auto const s2 = hana::wstring_c<>; + static_assert(std::is_same::value, ""); + } + { + auto const s1 = BOOST_HANA_AUTO_STRING(L"a"); + auto const s2 = hana::wstring_c; + static_assert(std::is_same::value, ""); + } + { + auto const s1 = BOOST_HANA_AUTO_STRING(L"abcd"); + auto const s2 = hana::wstring_c; + static_assert(std::is_same::value, ""); + } + { + auto const s1 = BOOST_HANA_AUTO_STRING(L"\xabcd\xef01"); + auto const s2 = hana::wstring_c; + static_assert(std::is_same::value, ""); + } +} diff --git a/test/wstring/make.cpp b/test/wstring/make.cpp new file mode 100644 index 0000000000..63f8ee400b --- /dev/null +++ b/test/wstring/make.cpp @@ -0,0 +1,47 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(), + hana::wstring_c<> + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(hana::wchar_c), + hana::wstring_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(hana::wchar_c, hana::wchar_c), + hana::wstring_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(hana::wchar_c, hana::wchar_c, hana::wchar_c), + hana::wstring_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(hana::wchar_c, hana::wchar_c, hana::wchar_c, hana::wchar_c), + hana::wstring_c + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make(hana::wchar_c, hana::wchar_c), + hana::wstring_c + )); + + // make sure make_string == make + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_wstring(hana::wchar_c, hana::wchar_c, hana::wchar_c), + hana::make(hana::wchar_c, hana::wchar_c, hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::make_wstring(hana::wchar_c, hana::wchar_c), + hana::make(hana::wchar_c, hana::wchar_c) + )); +} diff --git a/test/wstring/plus.cpp b/test/wstring/plus.cpp new file mode 100644 index 0000000000..944e52ea44 --- /dev/null +++ b/test/wstring/plus.cpp @@ -0,0 +1,43 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_AUTO_STRING(L""), BOOST_HANA_AUTO_STRING(L"")), + BOOST_HANA_AUTO_STRING(L"") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_AUTO_STRING(L"abcd"), BOOST_HANA_AUTO_STRING(L"")), + BOOST_HANA_AUTO_STRING(L"abcd") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_AUTO_STRING(L""), BOOST_HANA_AUTO_STRING(L"abcd")), + BOOST_HANA_AUTO_STRING(L"abcd") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_AUTO_STRING(L"abcd"), BOOST_HANA_AUTO_STRING(L"efg")), + BOOST_HANA_AUTO_STRING(L"abcdefg") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::plus(BOOST_HANA_AUTO_STRING(L"\xabcd"), BOOST_HANA_AUTO_STRING(L"\xef01")), + BOOST_HANA_AUTO_STRING(L"\xabcd\xef01") + )); + + // check operator + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_AUTO_STRING(L"abc") + BOOST_HANA_AUTO_STRING(L"def"), + BOOST_HANA_AUTO_STRING(L"abcdef") + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + BOOST_HANA_AUTO_STRING(L"\xabcd") + BOOST_HANA_AUTO_STRING(L"\xef01"), + BOOST_HANA_AUTO_STRING(L"\xabcd\xef01") + )); +} diff --git a/test/wstring/test_wstring.hpp b/test/wstring/test_wstring.hpp new file mode 100644 index 0000000000..3aa66a0e66 --- /dev/null +++ b/test/wstring/test_wstring.hpp @@ -0,0 +1,17 @@ +/*! +@file +Defines `unit test`. + +@copyright Louis Dionne 2013-2017 +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + */ +template +int basic_strcmp(C const* l, C const* r) { + for (;*l != static_cast('\0'); l++, r++) { + if (*l != *r) { + return *l < *r ? -1 : 1; + } + } + return *r == static_cast('\0') ? 0 : -1; +} diff --git a/test/wstring/to.cpp b/test/wstring/to.cpp new file mode 100644 index 0000000000..8fe20421c4 --- /dev/null +++ b/test/wstring/to.cpp @@ -0,0 +1,52 @@ +// Copyright Louis Dionne 2013-2017 +// 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 "test_wstring.hpp" +namespace hana = boost::hana; + + +static_assert(hana::is_convertible{}, ""); +static_assert(!hana::is_embedded{}, ""); + +int main() { + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_AUTO_STRING(L"")), + L"" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_AUTO_STRING(L"a")), + L"a" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_AUTO_STRING(L"ab")), + L"ab" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_AUTO_STRING(L"abc")), + L"abc" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_AUTO_STRING(L"abcd")), + L"abcd" + ) == 0); + + BOOST_HANA_RUNTIME_CHECK(basic_strcmp( + hana::to(BOOST_HANA_AUTO_STRING(L"\xabcd\xef01")), + L"\xabcd\xef01" + ) == 0); + + // make sure we can turn a non-constexpr hana::string + // into a constexpr char const* + auto str = BOOST_HANA_AUTO_STRING(L"abcdef\xabcd"); + constexpr wchar_t const* c_str = hana::to(str); + (void)c_str; +} diff --git a/test/wstring/udl.cpp b/test/wstring/udl.cpp new file mode 100644 index 0000000000..17a5df2f05 --- /dev/null +++ b/test/wstring/udl.cpp @@ -0,0 +1,24 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + // Check the _s user-defined literal +#ifdef BOOST_HANA_CONFIG_ENABLE_BASIC_STRING_UDL + + using namespace hana::literals; + + constexpr auto s1 = L"abcd\xef01"_s; + constexpr auto s2 = hana::wstring_c; + + static_assert(std::is_same::value, ""); +#endif +} diff --git a/test/wstring/unpack.cpp b/test/wstring/unpack.cpp new file mode 100644 index 0000000000..b8e6d31aaf --- /dev/null +++ b/test/wstring/unpack.cpp @@ -0,0 +1,48 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + hana::test::_injection<0> f{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_AUTO_STRING(L""), f), + f() + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_AUTO_STRING(L"a"), f), + f(hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_AUTO_STRING(L"ab"), f), + f(hana::wchar_c, hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_AUTO_STRING(L"abc"), f), + f(hana::wchar_c, hana::wchar_c, hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_AUTO_STRING(L"abcd"), f), + f(hana::wchar_c, hana::wchar_c, + hana::wchar_c, hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_AUTO_STRING(L"abcde"), f), + f(hana::wchar_c, hana::wchar_c, + hana::wchar_c, hana::wchar_c, hana::wchar_c) + )); + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::unpack(BOOST_HANA_AUTO_STRING(L"\xabcd\xef01"), f), + f(hana::wchar_c, hana::wchar_c) + )); +} diff --git a/test/wstring/zero.cpp b/test/wstring/zero.cpp new file mode 100644 index 0000000000..e0ce53dfdf --- /dev/null +++ b/test/wstring/zero.cpp @@ -0,0 +1,17 @@ +// Copyright Louis Dionne 2013-2017 +// 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 +namespace hana = boost::hana; + + +int main() { + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::zero(), + BOOST_HANA_AUTO_STRING(L"") + )); +}