diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/metaparse/test | |
parent | Initial commit. (diff) | |
download | ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/metaparse/test')
112 files changed, 6681 insertions, 0 deletions
diff --git a/src/boost/libs/metaparse/test/BOOST_METAPARSE_STRING.cpp b/src/boost/libs/metaparse/test/BOOST_METAPARSE_STRING.cpp new file mode 100644 index 000000000..f48d2863a --- /dev/null +++ b/src/boost/libs/metaparse/test/BOOST_METAPARSE_STRING.cpp @@ -0,0 +1,63 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 4 + +#include <boost/type_traits/is_same.hpp> + +#include "common.hpp" +#include "test_case.hpp" +#include "string_macros.hpp" + +#include <boost/metaparse/string.hpp> + +#ifndef BOOST_METAPARSE_V1_CONFIG_NO_BOOST_METAPARSE_STRING + +using boost::metaparse::string; +using boost::is_same; + +BOOST_METAPARSE_TEST_CASE(string_macro) +{ + BOOST_MPL_ASSERT(( + is_same<string<'a', 'b', 'c', 'd'>, BOOST_METAPARSE_STRING("abcd")> + )); +} + +#undef BOOST_METAPARSE_LIMIT_STRING_SIZE +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 8 + +BOOST_METAPARSE_TEST_CASE(string_macro_redefined_length_limit) +{ + BOOST_MPL_ASSERT(( + is_same<string<'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'>, + BOOST_METAPARSE_STRING("abcdefgh")> + )); +} + +#undef BOOST_METAPARSE_LIMIT_STRING_SIZE +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 127 + +BOOST_METAPARSE_TEST_CASE(creating_long_string_with_macro) +{ + BOOST_MPL_ASSERT(( + is_same< + string< + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_10, + BOOST_METAPARSE_TEST_CHARS_10, + '0', '1', '2', '3', '4', '5', '6' + >, + BOOST_METAPARSE_STRING( + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_10 + BOOST_METAPARSE_TEST_STRING_10 + "0123456" + ) + > + )); +} + +#endif + diff --git a/src/boost/libs/metaparse/test/Jamfile.v2 b/src/boost/libs/metaparse/test/Jamfile.v2 new file mode 100644 index 000000000..aa8eee886 --- /dev/null +++ b/src/boost/libs/metaparse/test/Jamfile.v2 @@ -0,0 +1,114 @@ +import testing ; + +project metaparse : + requirements + <toolset>gcc:<cxxflags>"-ftemplate-depth-300" + <toolset>clang:<cxxflags>"-ftemplate-depth-300" + + <library>/boost/test//boost_unit_test_framework/<link>static + ; + +test-suite metaparse-unit-tests : + [ compile BOOST_METAPARSE_STRING.cpp ] + [ compile accept.cpp ] + [ compile accept_when.cpp ] + [ compile back_inserter.cpp ] + [ compile all_headers.cpp ] + [ compile alphanum.cpp ] + [ compile always_c.cpp ] + [ compile always.cpp ] + [ compile at_c.cpp ] + [ compile build_parser.cpp ] + [ compile change_error_message.cpp ] + [ compile concat.cpp ] + [ run define_error.cpp ] + [ compile digit.cpp ] + [ compile digit_to_int.cpp ] + [ compile digit_val.cpp ] + [ compile empty.cpp ] + [ run empty_string.cpp ] + [ compile entire_input.cpp ] + [ compile except.cpp ] + [ compile fail_at_first_char_expected.cpp ] + [ compile fail.cpp ] + [ compile fail_tag.cpp ] + [ compile first_of.cpp ] + [ compile foldl1.cpp ] + [ compile foldl.cpp ] + [ compile foldl_reject_incomplete1.cpp ] + [ compile foldl_reject_incomplete.cpp ] + [ compile foldl_reject_incomplete_start_with_parser.cpp ] + [ compile foldl_start_with_parser.cpp ] + [ compile foldr1.cpp ] + [ compile foldr.cpp ] + [ compile foldr_reject_incomplete1.cpp ] + [ compile foldr_reject_incomplete.cpp ] + [ compile foldr_start_with_parser.cpp ] + [ compile front_inserter.cpp ] + [ compile grammar.cpp ] + [ compile has_type.cpp ] + [ compile if_.cpp ] + [ compile in_range_c.cpp ] + [ compile in_range.cpp ] + [ compile int_.cpp ] + [ compile int_to_digit.cpp ] + [ compile is_char_c.cpp ] + [ compile is_digit.cpp ] + [ compile is_error.cpp ] + [ compile is_lcase_letter.cpp ] + [ compile is_letter.cpp ] + [ compile is_ucase_letter.cpp ] + [ compile is_whitespace.cpp ] + [ compile iterate_c.cpp ] + [ compile iterate.cpp ] + [ compile keyword.cpp ] + [ compile last_of.cpp ] + [ compile letter.cpp ] + [ compile lit_c.cpp ] + [ compile lit.cpp ] + [ compile look_ahead.cpp ] + [ compile long_string.cpp ] + [ compile middle_of.cpp ] + [ compile next_digit.cpp ] + [ compile nth_of.cpp ] + [ compile one_char.cpp ] + [ compile one_char_except_c.cpp ] + [ compile one_char_except.cpp ] + [ compile one_of_c.cpp ] + [ compile one_of.cpp ] + [ compile optional.cpp ] + [ compile pop_back.cpp ] + [ compile pop_front.cpp ] + [ compile push_back_c.cpp ] + [ compile push_front_c.cpp ] + [ compile range_c.cpp ] + [ compile range.cpp ] + [ compile reject.cpp ] + [ compile repeated1.cpp ] + [ compile repeated.cpp ] + [ compile repeated_one_of1.cpp ] + [ compile repeated_one_of.cpp ] + [ compile repeated_reject_incomplete1.cpp ] + [ compile repeated_reject_incomplete.cpp ] + [ compile return_.cpp ] + [ compile returns.cpp ] + [ compile sequence.cpp ] + [ compile sequence_apply.cpp ] + [ compile size.cpp ] + [ compile source_position.cpp ] + [ compile space.cpp ] + [ compile spaces.cpp ] + [ run string.cpp ] + [ compile string_iterator_tag.cpp ] + [ compile string_tag.cpp ] + [ compile swap.cpp ] + [ compile token.cpp ] + [ compile-fail too_long_string.cpp ] + [ compile transform.cpp ] + [ compile transform_error.cpp ] + [ compile transform_error_message.cpp ] + [ compile unless_error.cpp ] + [ compile unpaired.cpp ] + [ compile update_c.cpp ] + [ compile version.cpp ] + ; diff --git a/src/boost/libs/metaparse/test/accept.cpp b/src/boost/libs/metaparse/test/accept.cpp new file mode 100644 index 000000000..e091ee63a --- /dev/null +++ b/src/boost/libs/metaparse/test/accept.cpp @@ -0,0 +1,71 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/accept.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +namespace +{ + template <class T> + struct returns + { + typedef T type; + }; + + template <class T> + struct gets_foo + { + typedef typename T::foo type; + }; +} + +BOOST_METAPARSE_TEST_CASE(accept) +{ + using boost::metaparse::accept; + using boost::metaparse::start; + using boost::metaparse::string; + using boost::metaparse::get_result; + using boost::metaparse::get_position; + using boost::metaparse::get_remaining; + + using boost::is_same; + + typedef string<'H','e','l','l','o'> s; + + // test_accept_is_metaprogramming_value + BOOST_MPL_ASSERT(( + is_same<accept<int, s, start>, accept<int, s, start>::type> + )); + + // test_accept_is_not_lazy + BOOST_MPL_ASSERT(( + is_same< + accept<gets_foo<int>, s, start>, + accept<gets_foo<int>, returns<s>, returns<start> >::type + > + )); + + // test_get_result_of_accept + BOOST_MPL_ASSERT((is_same<int, get_result<accept<int, s, start> >::type>)); + + // test_get_remaining_of_accept + BOOST_MPL_ASSERT((is_same<s, get_remaining<accept<int, s, start> >::type>)); + + // test_get_position_of_accept + BOOST_MPL_ASSERT(( + is_same<start, get_position<accept<int, s, start> >::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/accept_when.cpp b/src/boost/libs/metaparse/test/accept_when.cpp new file mode 100644 index 000000000..c705597ca --- /dev/null +++ b/src/boost/libs/metaparse/test/accept_when.cpp @@ -0,0 +1,69 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/accept_when.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/util/is_digit.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/metaparse/util/is_digit.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(accept_when) +{ + using boost::metaparse::is_error; + using boost::metaparse::accept_when; + using boost::metaparse::one_char; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::metaparse::util::is_digit; + + using boost::mpl::apply; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_with_text + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + accept_when<one_char, is_digit<>, test_failure>, + str_hello, + start + > + > + )); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + accept_when<one_char, is_digit<>, test_failure>, + str_1983, + start + > + >::type, + char_1 + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<accept_when<one_char, is_digit<>, test_failure>, str_, start> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/all_headers.cpp b/src/boost/libs/metaparse/test/all_headers.cpp new file mode 100644 index 000000000..14dedd04b --- /dev/null +++ b/src/boost/libs/metaparse/test/all_headers.cpp @@ -0,0 +1,8 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse.hpp> +#include <boost/metaparse.hpp> + diff --git a/src/boost/libs/metaparse/test/alphanum.cpp b/src/boost/libs/metaparse/test/alphanum.cpp new file mode 100644 index 000000000..2febacb46 --- /dev/null +++ b/src/boost/libs/metaparse/test/alphanum.cpp @@ -0,0 +1,50 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/alphanum.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/digit.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(alphanum) +{ + using boost::metaparse::get_result; + using boost::metaparse::alphanum; + using boost::metaparse::start; + using boost::metaparse::digit; + using boost::metaparse::is_error; + + using boost::mpl::list_c; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + typedef list_c<char, '.', '.', ','> other_string; + + // test_with_text + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<alphanum, str_hello, start> >::type, char_h> + )); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<digit, str_1983, start> >::type, char_1> + )); + + // test_with_non_alphanum + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, other_string, start> >)); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/always.cpp b/src/boost/libs/metaparse/test/always.cpp new file mode 100644 index 000000000..ae93f996b --- /dev/null +++ b/src/boost/libs/metaparse/test/always.cpp @@ -0,0 +1,43 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/digit.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(always) +{ + using boost::metaparse::get_result; + using boost::metaparse::always; + using boost::metaparse::digit; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + typedef always<digit, int13> always_digit_13; + + // test_result + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<always_digit_13, str_1, start> >::type, + int13 + > + )); + + // test_fail + BOOST_MPL_ASSERT((is_error<apply_wrap2<always_digit_13, str_a, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/always_c.cpp b/src/boost/libs/metaparse/test/always_c.cpp new file mode 100644 index 000000000..f0801b3bf --- /dev/null +++ b/src/boost/libs/metaparse/test/always_c.cpp @@ -0,0 +1,41 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/always_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(always_c) +{ + using boost::metaparse::get_result; + using boost::metaparse::always_c; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_result + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<always_c<'1', int13>, str_1, start> >::type, + int13 + > + )); + + // test_fail + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<always_c<'1', int13>, str_a, start> > + )); +} + diff --git a/src/boost/libs/metaparse/test/at_c.cpp b/src/boost/libs/metaparse/test/at_c.cpp new file mode 100644 index 000000000..2323a711e --- /dev/null +++ b/src/boost/libs/metaparse/test/at_c.cpp @@ -0,0 +1,35 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/at_c.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(at_c) +{ + using boost::metaparse::v1::impl::at_c; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_first_char + BOOST_MPL_ASSERT((equal_to<char_<'h'>, at_c<hello, 0>::type>)); + + // test_middle_char + BOOST_MPL_ASSERT((equal_to<char_<'l'>, at_c<hello, 2>::type>)); + + // test_last_char + BOOST_MPL_ASSERT((equal_to<char_<'o'>, at_c<hello, 4>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/back_inserter.cpp b/src/boost/libs/metaparse/test/back_inserter.cpp new file mode 100644 index 000000000..333c9cd40 --- /dev/null +++ b/src/boost/libs/metaparse/test/back_inserter.cpp @@ -0,0 +1,26 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/deque.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(back_inserter) +{ + using boost::metaparse::v1::impl::back_inserter; + + using boost::mpl::equal; + using boost::mpl::deque; + + // test_inserts_at_the_back + BOOST_MPL_ASSERT(( + equal<deque<int, char>, back_inserter::apply<deque<int>, char>::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/build_parser.cpp b/src/boost/libs/metaparse/test/build_parser.cpp new file mode 100644 index 000000000..e2f27ffea --- /dev/null +++ b/src/boost/libs/metaparse/test/build_parser.cpp @@ -0,0 +1,7 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/build_parser.hpp> + diff --git a/src/boost/libs/metaparse/test/change_error_message.cpp b/src/boost/libs/metaparse/test/change_error_message.cpp new file mode 100644 index 000000000..6c9eb6d40 --- /dev/null +++ b/src/boost/libs/metaparse/test/change_error_message.cpp @@ -0,0 +1,7 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/change_error_message.hpp> + diff --git a/src/boost/libs/metaparse/test/common.hpp b/src/boost/libs/metaparse/test/common.hpp new file mode 100644 index 000000000..21dccb499 --- /dev/null +++ b/src/boost/libs/metaparse/test/common.hpp @@ -0,0 +1,110 @@ +#ifndef BOOST_PARSER_TEST_COMMON_H +#define BOOST_PARSER_TEST_COMMON_H + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/lit.hpp> +#include <boost/metaparse/lit_c.hpp> + +#include <boost/mpl/list.hpp> +#include <boost/mpl/list_c.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/equal.hpp> + +#include <string> + +typedef boost::mpl::list_c<char> str_; +typedef boost::mpl::list_c<char, '0'> str_0; +typedef boost::mpl::list_c<char, '1'> str_1; +typedef boost::mpl::list_c<char, '1', '9', '8', '3'> str_1983; +typedef boost::mpl::list_c<char, 'a'> str_a; +typedef boost::mpl::list_c<char, 'a', 'b'> str_ab; +typedef boost::mpl::list_c<char, 'a', 'a', 'a', 'a', 'b'> str_aaaab; +typedef boost::mpl::list_c<char, 'a', 'c'> str_ac; +typedef boost::mpl::list_c<char, 'b'> str_b; +typedef boost::mpl::list_c<char, 'b', 'a'> str_ba; +typedef boost::mpl::list_c<char, 'b', 'a', 'a', 'a', 'a'> str_baaaa; +typedef boost::mpl::list_c<char, 'c'> str_c; +typedef boost::mpl::list_c<char, 'c', 'a'> str_ca; +typedef boost::mpl::list_c<char, 'h'> str_h; +typedef boost::mpl::list_c<char, 'e'> str_e; +typedef boost::mpl::list_c<char, 'l'> str_l; +typedef boost::mpl::list_c<char, 'b', 'e', 'l', 'l', 'o'> str_bello; +typedef boost::mpl::list_c<char, 'h', 'e', 'l', 'l', 'o'> str_hello; +typedef boost::mpl::list_c<char, ' ', 'e', 'l', 'l', 'o'> str__ello; + +typedef boost::mpl::list_c<char, '0', 'e', 'l', 'l', 'o'> chars0; +typedef boost::mpl::list_c<char, 'h', '0', 'l', 'l', 'o'> chars1; +typedef boost::mpl::list_c<char, 'h', 'e', '0', 'l', 'o'> chars2; +typedef boost::mpl::list_c<char, 'h', 'e', 'l', '0', 'o'> chars3; +typedef boost::mpl::list_c<char, 'h', 'e', 'l', 'l', '0'> chars4; +typedef boost::mpl::list_c<char, 'h', 'e', 'l', 'l', 'o'> chars5; + +typedef boost::mpl::char_<'0'> char_0; +typedef boost::mpl::char_<'1'> char_1; +typedef boost::mpl::char_<'7'> char_7; +typedef boost::mpl::char_<'9'> char_9; +typedef boost::mpl::char_<'a'> char_a; +typedef boost::mpl::char_<'b'> char_b; +typedef boost::mpl::char_<'e'> char_e; +typedef boost::mpl::char_<'h'> char_h; +typedef boost::mpl::char_<'k'> char_k; +typedef boost::mpl::char_<'K'> char_K; +typedef boost::mpl::char_<'l'> char_l; +typedef boost::mpl::char_<'o'> char_o; +typedef boost::mpl::char_<'x'> char_x; + +typedef boost::mpl::char_<' '> char_space; +typedef boost::mpl::char_<'\t'> char_tab; +typedef boost::mpl::char_<'\n'> char_new_line; +typedef boost::mpl::char_<'\r'> char_cret; + +typedef boost::mpl::int_<0> int0; +typedef boost::mpl::int_<1> int1; +typedef boost::mpl::int_<2> int2; +typedef boost::mpl::int_<3> int3; +typedef boost::mpl::int_<9> int9; +typedef boost::mpl::int_<10> int10; +typedef boost::mpl::int_<11> int11; +typedef boost::mpl::int_<12> int12; +typedef boost::mpl::int_<13> int13; +typedef boost::mpl::int_<14> int14; +typedef boost::mpl::int_<28> int28; + +typedef boost::metaparse::lit<char_e> lit_e; +typedef boost::metaparse::lit<char_h> lit_h; +typedef boost::metaparse::lit<char_l> lit_l; +typedef boost::metaparse::lit<char_x> lit_x; + +typedef boost::metaparse::lit_c<'e'> lit_c_e; +typedef boost::metaparse::lit_c<'h'> lit_c_h; + +typedef boost::mpl::list< > empty_list; + +typedef + boost::mpl::at<boost::mpl::vector<int, double>, int11> + can_not_be_instantiated; + +struct test_failure +{ + typedef test_failure type; + + static std::string get_value() { return "fail"; } +}; + +struct equal_sequences +{ + typedef equal_sequences type; + + template <class A, class B> + struct apply : boost::mpl::equal<typename A::type, typename B::type> {}; +}; + +#endif + diff --git a/src/boost/libs/metaparse/test/concat.cpp b/src/boost/libs/metaparse/test/concat.cpp new file mode 100644 index 000000000..c5af6b2fb --- /dev/null +++ b/src/boost/libs/metaparse/test/concat.cpp @@ -0,0 +1,48 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> + +#if BOOST_METAPARSE_STD >= 2011 + +#include <boost/metaparse/v1/cpp11/impl/concat.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(concat) +{ + using boost::metaparse::v1::impl::concat; + using boost::metaparse::string; + + using boost::mpl::equal_to; + + typedef string<> empty; + typedef string<'h','e','l','l','o'> hello; + + // test_empty_empty + BOOST_MPL_ASSERT((equal_to<empty, concat<empty, empty>::type>)); + + // test_empty_hello + BOOST_MPL_ASSERT((equal_to<hello, concat<empty, hello>::type>)); + + // test_hello_empty + BOOST_MPL_ASSERT((equal_to<hello, concat<hello, empty>::type>)); + + // test_hello_hello + BOOST_MPL_ASSERT(( + equal_to< + string<'h','e','l','l','o','h','e','l','l','o'>, + concat<hello, hello>::type + > + )); +} + +#endif + diff --git a/src/boost/libs/metaparse/test/define_error.cpp b/src/boost/libs/metaparse/test/define_error.cpp new file mode 100644 index 000000000..c61ec5d0c --- /dev/null +++ b/src/boost/libs/metaparse/test/define_error.cpp @@ -0,0 +1,28 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MODULE define_error + +#include <boost/metaparse/define_error.hpp> + +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/test/unit_test.hpp> + +namespace +{ + BOOST_METAPARSE_DEFINE_ERROR(test_error, "test error"); +} + +BOOST_AUTO_TEST_CASE(test_define_error) +{ + using boost::is_same; + + BOOST_MPL_ASSERT((is_same<test_error, test_error::type>)); + + BOOST_CHECK_EQUAL("test error", test_error::get_value()); +} + diff --git a/src/boost/libs/metaparse/test/digit.cpp b/src/boost/libs/metaparse/test/digit.cpp new file mode 100644 index 000000000..1d7a169a3 --- /dev/null +++ b/src/boost/libs/metaparse/test/digit.cpp @@ -0,0 +1,55 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/digit.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_message.hpp> + +#include <boost/metaparse/error/digit_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +#include <boost/type_traits/is_same.hpp> + +BOOST_METAPARSE_TEST_CASE(digit) +{ + using boost::metaparse::is_error; + using boost::metaparse::digit; + using boost::metaparse::start; + using boost::metaparse::get_result; + using boost::metaparse::get_message; + + using boost::metaparse::error::digit_expected; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + using boost::is_same; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_hello, start> >)); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<digit, str_1983, start> >::type, char_1> + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_, start> >)); + + // test_error_message_with_empty_string + BOOST_MPL_ASSERT(( + is_same<digit_expected, get_message<apply_wrap2<digit, str_, start> >::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/digit_to_int.cpp b/src/boost/libs/metaparse/test/digit_to_int.cpp new file mode 100644 index 000000000..9ee7f73b1 --- /dev/null +++ b/src/boost/libs/metaparse/test/digit_to_int.cpp @@ -0,0 +1,42 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/digit_to_int.hpp> +#include <boost/metaparse/error/digit_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(digit_to_int) +{ + using boost::metaparse::util::digit_to_int; + using boost::metaparse::error::digit_expected; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap1; + using boost::mpl::true_; + + using boost::is_same; + + // test0 + BOOST_MPL_ASSERT((equal_to<apply_wrap1<digit_to_int<>, char_0>::type, int0>)); + + // test9 + BOOST_MPL_ASSERT((equal_to<apply_wrap1<digit_to_int<>, char_9>::type, int9>)); + + // test_error + BOOST_MPL_ASSERT(( + is_same<digit_expected, apply_wrap1<digit_to_int<>, char_x>::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/digit_val.cpp b/src/boost/libs/metaparse/test/digit_val.cpp new file mode 100644 index 000000000..347ca2cff --- /dev/null +++ b/src/boost/libs/metaparse/test/digit_val.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/digit_val.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(digit_val) +{ + using boost::metaparse::is_error; + using boost::metaparse::digit_val; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_val, str_hello, start> >)); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<digit_val, str_1983, start> >::type, int1> + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_val, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/empty.cpp b/src/boost/libs/metaparse/test/empty.cpp new file mode 100644 index 000000000..3e648070a --- /dev/null +++ b/src/boost/libs/metaparse/test/empty.cpp @@ -0,0 +1,39 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/empty.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(empty) +{ + using boost::metaparse::get_result; + using boost::metaparse::empty; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + typedef empty<int13> empty13; + + // test_accept_empty + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<empty13, str_, start> >::type, int13> + )); + + // test_reject_non_empty + BOOST_MPL_ASSERT((is_error<apply_wrap2<empty13, str_a, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/empty_string.cpp b/src/boost/libs/metaparse/test/empty_string.cpp new file mode 100644 index 000000000..ed4468bc5 --- /dev/null +++ b/src/boost/libs/metaparse/test/empty_string.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MODULE empty_string + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/empty_string.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/empty_string.hpp> +#endif + +#include <boost/test/unit_test.hpp> + +#include <string> + +BOOST_AUTO_TEST_CASE(test_empty_string) +{ + using boost::metaparse::v1::impl::empty_string; + using std::string; + + // test_value + BOOST_REQUIRE_EQUAL(string(), empty_string<>::value); +} + diff --git a/src/boost/libs/metaparse/test/entire_input.cpp b/src/boost/libs/metaparse/test/entire_input.cpp new file mode 100644 index 000000000..5b2067b39 --- /dev/null +++ b/src/boost/libs/metaparse/test/entire_input.cpp @@ -0,0 +1,57 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/entire_input.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/get_message.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(entire_input) +{ + using boost::metaparse::get_result; + using boost::metaparse::entire_input; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::one_char; + using boost::metaparse::get_message; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + using boost::is_same; + + typedef entire_input<one_char> ei; + + // test_accept_entire_input + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<ei, str_h, start> >::type, char_h> + )); + + // test_reject_non_entire_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<ei, str_hello, start> >)); + + // test_predefined_error_message + BOOST_MPL_ASSERT(( + is_same< + test_failure, + get_message< + apply_wrap2<entire_input<one_char, test_failure>, str_hello, start> + >::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/except.cpp b/src/boost/libs/metaparse/test/except.cpp new file mode 100644 index 000000000..1a6484221 --- /dev/null +++ b/src/boost/libs/metaparse/test/except.cpp @@ -0,0 +1,56 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/except.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(except) +{ + using boost::metaparse::is_error; + using boost::metaparse::except; + using boost::metaparse::one_char; + using boost::metaparse::start; + using boost::metaparse::get_result; + using boost::metaparse::fail; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + // test_with_good + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<except<one_char, int13, test_failure>, str_hello, start> + > + )); + + // test_with_bad + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + except<fail<test_failure>, int13, test_failure>, + str_hello, + start + > + >::type, + int13 + > + )); +} + + + diff --git a/src/boost/libs/metaparse/test/fail.cpp b/src/boost/libs/metaparse/test/fail.cpp new file mode 100644 index 000000000..1c05d8454 --- /dev/null +++ b/src/boost/libs/metaparse/test/fail.cpp @@ -0,0 +1,30 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(fail) +{ + using boost::metaparse::is_error; + using boost::metaparse::fail; + using boost::metaparse::start; + + using boost::mpl::apply_wrap2; + + // test_fail_for_non_empty_string + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<fail<test_failure>, str_hello, start> > + )); +} + diff --git a/src/boost/libs/metaparse/test/fail_at_first_char_expected.cpp b/src/boost/libs/metaparse/test/fail_at_first_char_expected.cpp new file mode 100644 index 000000000..95917d531 --- /dev/null +++ b/src/boost/libs/metaparse/test/fail_at_first_char_expected.cpp @@ -0,0 +1,42 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/fail_at_first_char_expected.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/keyword.hpp> + +#include <boost/mpl/assert.hpp> + +#include "common.hpp" + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(fail_at_first_char_expected) +{ + using boost::metaparse::fail_at_first_char_expected; + using boost::metaparse::is_error; + using boost::metaparse::start; + + typedef boost::metaparse::keyword<str_hello> accept_hello; + + // test_failure_at_first_char_is_ignored + BOOST_MPL_ASSERT_NOT(( + is_error<fail_at_first_char_expected<accept_hello>::apply<str_ab, start> > + )); + + // test_no_failure_is_error + BOOST_MPL_ASSERT(( + is_error< + fail_at_first_char_expected<accept_hello>::apply<str_hello, start> + > + )); + + // test_failure_at_second_char_is_not_ignored + BOOST_MPL_ASSERT(( + is_error< fail_at_first_char_expected<accept_hello>::apply<str_h, start> > + )); +} + diff --git a/src/boost/libs/metaparse/test/fail_tag.cpp b/src/boost/libs/metaparse/test/fail_tag.cpp new file mode 100644 index 000000000..b2ded6984 --- /dev/null +++ b/src/boost/libs/metaparse/test/fail_tag.cpp @@ -0,0 +1,41 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/start.hpp> + +#include "common.hpp" + +#include <boost/type_traits/is_same.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(fail_tag) +{ + using boost::metaparse::fail; + using boost::metaparse::get_message; + using boost::metaparse::get_position; + using boost::metaparse::start; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::is_same; + + typedef fail<test_failure> p; + typedef apply_wrap2<p, str_hello, start> failed_result; + + // test_getting_message_back + BOOST_MPL_ASSERT((is_same<test_failure, get_message<failed_result>::type>)); + + // test_getting_position + BOOST_MPL_ASSERT((equal_to<start, get_position<failed_result>::type>)); +} + diff --git a/src/boost/libs/metaparse/test/first_of.cpp b/src/boost/libs/metaparse/test/first_of.cpp new file mode 100644 index 000000000..cc04afcc0 --- /dev/null +++ b/src/boost/libs/metaparse/test/first_of.cpp @@ -0,0 +1,68 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/first_of.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(first_of) +{ + using boost::metaparse::get_result; + using boost::metaparse::first_of; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_one_char + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<first_of<lit_h>, str_hello, start> >::type, + char_h + > + )); + + // test_two_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<first_of<lit_h, lit_e>, str_hello, start> >::type, + char_h + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<first_of<lit_x, lit_e>, str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<first_of<lit_h, lit_x>, str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<first_of<lit_h,lit_e>, str_,start> >)); + + // test_three_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<first_of<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + char_h + > + )); +} + diff --git a/src/boost/libs/metaparse/test/foldl.cpp b/src/boost/libs/metaparse/test/foldl.cpp new file mode 100644 index 000000000..8bfb9c346 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/vector.hpp> + +using boost::metaparse::foldl; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated : foldl<P, vector<>, back_inserter> {}; +} + +#define TEST_NAME foldl + +#include "repeated_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl1.cpp b/src/boost/libs/metaparse/test/foldl1.cpp new file mode 100644 index 000000000..231fa6b03 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl1.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl1.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/vector.hpp> + +using boost::metaparse::foldl1; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated1 : foldl1<P, vector<>, back_inserter> {}; +} + +#define TEST_NAME foldl1 + +#include "repeated1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl_reject_incomplete.cpp b/src/boost/libs/metaparse/test/foldl_reject_incomplete.cpp new file mode 100644 index 000000000..064556e80 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl_reject_incomplete.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_reject_incomplete.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/vector.hpp> + +using boost::metaparse::foldl_reject_incomplete; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated_reject_incomplete : + foldl_reject_incomplete<P, vector<>, back_inserter> + {}; +} + +#define TEST_NAME foldl_reject_incomplete + +#include "repeated_reject_incomplete_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl_reject_incomplete1.cpp b/src/boost/libs/metaparse/test/foldl_reject_incomplete1.cpp new file mode 100644 index 000000000..7ec6ab540 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl_reject_incomplete1.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_reject_incomplete1.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include <boost/mpl/vector.hpp> + +using boost::metaparse::foldl_reject_incomplete1; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated_reject_incomplete1 : + foldl_reject_incomplete1<P, vector<>, back_inserter> + {}; +} + +#define TEST_NAME foldl_reject_incomplete1 + +#include "repeated_reject_incomplete1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl_reject_incomplete_start_with_parser.cpp b/src/boost/libs/metaparse/test/foldl_reject_incomplete_start_with_parser.cpp new file mode 100644 index 000000000..9647fbbae --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl_reject_incomplete_start_with_parser.cpp @@ -0,0 +1,97 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/return_.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + struct keep_state + { + typedef keep_state type; + + template <class S, class C> + struct apply : S {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(foldl_reject_incomplete_start_with_parser) +{ + using boost::metaparse::foldl_reject_incomplete_start_with_parser; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::lit_c; + using boost::metaparse::get_result; + using boost::metaparse::sequence; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::char_; + + typedef sequence<lit_c<'a'>, lit_c<'a'> > aa; + + typedef + foldl_reject_incomplete_start_with_parser<aa, lit_c<'b'>, keep_state> + p; + + // test_b + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_b, start> >::type, char_<'b'> > + )); + + // test_ba + BOOST_MPL_ASSERT(( is_error<apply_wrap2<p, str_ba, start> > )); + + // test_baaaa + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_baaaa, start> >::type, char_<'b'> > + )); + + // test_c + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_c, start> >)); + + // test_ca + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_ca, start> >)); +} + +// Test foldl_reject_incomplete_start_with_parser as a normal fold + +using boost::metaparse::foldl_reject_incomplete_start_with_parser; +using boost::metaparse::return_; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated_reject_incomplete : + foldl_reject_incomplete_start_with_parser< + P, + return_<vector<> >, + back_inserter + > + {}; +} + +#define TEST_NAME \ + foldl_reject_incomplete_start_with_parser_as_foldl_reject_incomplete + +#include "repeated_reject_incomplete_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldl_start_with_parser.cpp b/src/boost/libs/metaparse/test/foldl_start_with_parser.cpp new file mode 100644 index 000000000..a671cc43d --- /dev/null +++ b/src/boost/libs/metaparse/test/foldl_start_with_parser.cpp @@ -0,0 +1,88 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldl_start_with_parser.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/return_.hpp> +#include <boost/metaparse/v1/impl/back_inserter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + struct keep_state + { + typedef keep_state type; + + template <class S, class C> + struct apply : S {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(foldl_start_with_parser) +{ + using boost::metaparse::foldl_start_with_parser; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::lit_c; + using boost::metaparse::get_result; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::char_; + + typedef foldl_start_with_parser<lit_c<'a'>, lit_c<'b'>, keep_state> p; + + // test_b + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_b, start> >::type, char_<'b'> > + )); + + // test_ba + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_ba, start> >::type, char_<'b'> > + )); + + // test_baaaa + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_baaaa, start> >::type, char_<'b'> > + )); + + // test_c + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_c, start> >)); + + // test_ca + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_ca, start> >)); +} + +// Test foldl_start_with_parser as a normal fold + +using boost::metaparse::foldl_start_with_parser; +using boost::metaparse::return_; +using boost::metaparse::v1::impl::back_inserter; + +using boost::mpl::vector; + +namespace +{ + template <class P> + struct repeated : + foldl_start_with_parser<P, return_<vector<> >, back_inserter> + {}; +} + +#define TEST_NAME foldl_start_with_parser_as_foldl + +#include "repeated_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr.cpp b/src/boost/libs/metaparse/test/foldr.cpp new file mode 100644 index 000000000..3071c60fd --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr.hpp> +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/list.hpp> + +using boost::metaparse::foldr; +using boost::metaparse::v1::impl::front_inserter; + +using boost::mpl::list; + +namespace +{ + template <class P> + struct repeated : foldr<P, list<>, front_inserter> {}; +} + +#define TEST_NAME foldr + +#include "repeated_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr1.cpp b/src/boost/libs/metaparse/test/foldr1.cpp new file mode 100644 index 000000000..88542c7aa --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr1.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr1.hpp> +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/list.hpp> + +using boost::metaparse::foldr1; +using boost::metaparse::v1::impl::front_inserter; + +using boost::mpl::list; + +namespace +{ + template <class P> + struct repeated1 : foldr1<P, list<>, front_inserter> {}; +} + +#define TEST_NAME foldr1 + +#include "repeated1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr_reject_incomplete.cpp b/src/boost/libs/metaparse/test/foldr_reject_incomplete.cpp new file mode 100644 index 000000000..c4392fb44 --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr_reject_incomplete.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr_reject_incomplete.hpp> +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/list.hpp> + +using boost::metaparse::foldr_reject_incomplete; +using boost::metaparse::v1::impl::front_inserter; + +using boost::mpl::list; + +namespace +{ + template <class P> + struct repeated_reject_incomplete : + foldr_reject_incomplete<P, list<>, front_inserter> + {}; +} + +#define TEST_NAME foldr_reject_incomplete + +#include "repeated_reject_incomplete_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr_reject_incomplete1.cpp b/src/boost/libs/metaparse/test/foldr_reject_incomplete1.cpp new file mode 100644 index 000000000..214a4b05d --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr_reject_incomplete1.cpp @@ -0,0 +1,27 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr_reject_incomplete1.hpp> +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/list.hpp> + +using boost::metaparse::foldr_reject_incomplete1; +using boost::metaparse::v1::impl::front_inserter; + +using boost::mpl::list; + +namespace +{ + template <class P> + struct repeated_reject_incomplete1 : + foldr_reject_incomplete1<P, list<>, front_inserter> + {}; +} + +#define TEST_NAME foldr_reject_incomplete1 + +#include "repeated_reject_incomplete1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/foldr_start_with_parser.cpp b/src/boost/libs/metaparse/test/foldr_start_with_parser.cpp new file mode 100644 index 000000000..621ee550e --- /dev/null +++ b/src/boost/libs/metaparse/test/foldr_start_with_parser.cpp @@ -0,0 +1,67 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/foldr_start_with_parser.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/fail.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + struct keep_state + { + typedef keep_state type; + + template <class S, class C> + struct apply : S {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(foldr_start_with_parser) +{ + using boost::metaparse::foldr_start_with_parser; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::lit_c; + using boost::metaparse::get_result; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::char_; + + typedef foldr_start_with_parser<lit_c<'a'>, lit_c<'b'>, keep_state> p; + + // test_b + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_b, start> >::type, char_<'b'> > + )); + + // test_ab + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_ab, start> >::type, char_<'b'> > + )); + + // test_aaaab + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<p, str_aaaab, start> >::type, char_<'b'> > + )); + + // test_c + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_c, start> >)); + + // test_ac + BOOST_MPL_ASSERT((is_error<apply_wrap2<p, str_ac, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/front_inserter.cpp b/src/boost/libs/metaparse/test/front_inserter.cpp new file mode 100644 index 000000000..6e30ebbe5 --- /dev/null +++ b/src/boost/libs/metaparse/test/front_inserter.cpp @@ -0,0 +1,26 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/front_inserter.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/deque.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(front_inserter) +{ + using boost::metaparse::v1::impl::front_inserter; + + using boost::mpl::equal; + using boost::mpl::deque; + + // test_inserts_at_the_front + BOOST_MPL_ASSERT(( + equal<deque<int, char>, front_inserter::apply<deque<char>, int>::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/grammar.cpp b/src/boost/libs/metaparse/test/grammar.cpp new file mode 100644 index 000000000..390151154 --- /dev/null +++ b/src/boost/libs/metaparse/test/grammar.cpp @@ -0,0 +1,420 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/grammar.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/string.hpp> + +#include "test_case.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +using boost::mpl::char_; + +namespace +{ + struct next_char + { + typedef next_char type; + + template <class C> + struct apply + { + typedef char_<C::type::value + 1> type; + }; + }; +} + +BOOST_METAPARSE_TEST_CASE(grammar) +{ + using boost::metaparse::grammar; + using boost::metaparse::lit_c; + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::string; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::mpl::equal; + using boost::mpl::vector; + + // import + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::import<string<'S'>, lit_c<'x'> >::type, + string<'x'>, + start + > + >::type + > + )); + + // rename_import + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::import<string<'I'>, lit_c<'x'> >::type + ::rule<string<'S',' ',':',':','=',' ','I'> >::type, + string<'x'>, + start + > + >::type + > + )); + + // char + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','x','\''> >::type, + string<'x'>, + start + > + >::type + > + )); + + // char_failure + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','x','\''> >::type, + string<'y'>, + start + > + > + )); + + // char_n + BOOST_MPL_ASSERT(( + equal_to< + char_<'\n'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','n','\''> >::type, + string<'\n'>, + start + > + >::type + > + )); + + // char_r + BOOST_MPL_ASSERT(( + equal_to< + char_<'\r'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','r','\''> >::type, + string<'\r'>, + start + > + >::type + > + )); + + // char_t + BOOST_MPL_ASSERT(( + equal_to< + char_<'\t'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','t','\''> >::type, + string<'\t'>, + start + > + >::type + > + )); + + // backslash + BOOST_MPL_ASSERT(( + equal_to< + char_<'\\'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','\\','\''> >::type, + string<'\\'>, + start + > + >::type + > + )); + + // char_\' + BOOST_MPL_ASSERT(( + equal_to< + char_<'\''>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'S',' ',':',':','=',' ','\'','\\','\'','\''> >::type, + string<'\''>, + start + > + >::type + > + )); + + // rename_rule + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'R',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','R'> >::type, + string<'x'>, + start + > + >::type + > + )); + + // sequence + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'>, char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'R',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','R',' ','R'> >::type, + string<'x','x'>, + start + > + >::type + > + )); + + // sequence_first_fail + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'R',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','R',' ','R'> >::type, + string<'y','x'>, + start + > + > + )); + + // sequence_second_fail + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'R',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','R',' ','R'> >::type, + string<'x','y'>, + start + > + > + )); + + // selection 1 + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'Y',' ',':',':','=',' ','\'','y','\''> >::type + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','|','Y'> >::type, + string<'x'>, + start + > + >::type + > + )); + + // selection 2 + BOOST_MPL_ASSERT(( + equal_to< + char_<'y'>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'Y',' ',':',':','=',' ','\'','y','\''> >::type + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','|','Y'> >::type, + string<'y'>, + start + > + >::type + > + )); + + // selection_fail + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'Y',' ',':',':','=',' ','\'','y','\''> >::type + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','|','Y'> >::type, + string<'z'>, + start + > + > + )); + + // repeated_0 + BOOST_MPL_ASSERT(( + equal< + vector<>, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','*'> >::type, + string<'y'>, + start + > + >::type + > + )); + + // repeated_1 + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','*'> >::type, + string<'x','y'>, + start + > + >::type + > + )); + + // repeated_2 + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'>, char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','*'> >::type, + string<'x','x','y'>, + start + > + >::type + > + )); + + // bracket + BOOST_MPL_ASSERT(( + equal_to< + char_<'x'>, + get_result< + apply_wrap2< + grammar<> + ::rule< + string<'S',' ',':',':','=',' ','(','\'','x','\'',')'> + >::type, + string<'x'>, + start + > + >::type + > + )); + + // semantic_action + BOOST_MPL_ASSERT(( + equal_to< + char_<'y'>, + get_result< + apply_wrap2< + grammar<> + ::rule< + string<'S',' ',':',':','=',' ','\'','x','\''>, + next_char + >::type, + string<'x'>, + start + > + >::type + > + )); + + // repeated+_0 + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','+'> >::type, + string<'y'>, + start + > + > + )); + + // repeated+_1 + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','+'> >::type, + string<'x','y'>, + start + > + >::type + > + )); + + // repeated+_2 + BOOST_MPL_ASSERT(( + equal< + vector<char_<'x'>, char_<'x'> >, + get_result< + apply_wrap2< + grammar<> + ::rule<string<'X',' ',':',':','=',' ','\'','x','\''> >::type + ::rule<string<'S',' ',':',':','=',' ','X','+'> >::type, + string<'x','x','y'>, + start + > + >::type + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/has_type.cpp b/src/boost/libs/metaparse/test/has_type.cpp new file mode 100644 index 000000000..1edd2a1f2 --- /dev/null +++ b/src/boost/libs/metaparse/test/has_type.cpp @@ -0,0 +1,32 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/has_type.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/not.hpp> + +#include "test_case.hpp" + +namespace +{ + struct nullary_metafunction + { + typedef int type; + }; +} + +BOOST_METAPARSE_TEST_CASE(has_type) +{ + using boost::metaparse::v1::impl::has_type; + using boost::mpl::not_; + + // test_int_has_no_type + BOOST_MPL_ASSERT((not_<has_type<int>::type>)); + + // test_nullary_metafunction_has_type + BOOST_MPL_ASSERT((has_type<nullary_metafunction>)); +} + diff --git a/src/boost/libs/metaparse/test/if_.cpp b/src/boost/libs/metaparse/test/if_.cpp new file mode 100644 index 000000000..e4611090a --- /dev/null +++ b/src/boost/libs/metaparse/test/if_.cpp @@ -0,0 +1,46 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/if_.hpp> +#include <boost/metaparse/digit.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(if) +{ + using boost::metaparse::get_result; + using boost::metaparse::if_; + using boost::metaparse::digit; + using boost::metaparse::start; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_true + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<if_<digit, int11, int13>, str_1, start> >::type, + int11 + > + )); + + // test_false + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<if_<digit, int11, int13>, str_a, start> >::type, + int13 + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/in_range.cpp b/src/boost/libs/metaparse/test/in_range.cpp new file mode 100644 index 000000000..8a0ed9ec7 --- /dev/null +++ b/src/boost/libs/metaparse/test/in_range.cpp @@ -0,0 +1,35 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/in_range.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_in_range) +{ + using boost::metaparse::util::in_range; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_int_in_range + BOOST_MPL_ASSERT((apply_wrap1<in_range<int10, int13>, int12>)); + + // test_lower_bound + BOOST_MPL_ASSERT((apply_wrap1<in_range<int10, int13>, int10>)); + + // test_upper_bound + BOOST_MPL_ASSERT((apply_wrap1<in_range<int10, int13>, int13>)); + + // test_int_not_in_range + BOOST_MPL_ASSERT((not_<apply_wrap1<in_range<int10, int13>, int14> >)); +} + diff --git a/src/boost/libs/metaparse/test/in_range_c.cpp b/src/boost/libs/metaparse/test/in_range_c.cpp new file mode 100644 index 000000000..49f4310cf --- /dev/null +++ b/src/boost/libs/metaparse/test/in_range_c.cpp @@ -0,0 +1,36 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/in_range_c.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_in_range_c) +{ + using boost::metaparse::util::in_range_c; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_int_in_range + BOOST_MPL_ASSERT((apply_wrap1<in_range_c<char, 'a', 'g'>, char_e>)); + + // test_lower_bound + BOOST_MPL_ASSERT((apply_wrap1<in_range_c<char, 'a', 'g'>, char_a>)); + + // test_upper_bound + BOOST_MPL_ASSERT((apply_wrap1<in_range_c<int, 10, 13>, int13>)); + + // test_int_not_in_range + BOOST_MPL_ASSERT((not_<apply_wrap1<in_range_c<int, 10, 13>, int14> >)); + +} + diff --git a/src/boost/libs/metaparse/test/int_.cpp b/src/boost/libs/metaparse/test/int_.cpp new file mode 100644 index 000000000..ab1cae671 --- /dev/null +++ b/src/boost/libs/metaparse/test/int_.cpp @@ -0,0 +1,53 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/int_.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(int) +{ + using boost::metaparse::is_error; + using boost::metaparse::int_; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<int_, str_hello, start> >)); + + // test_with_zero + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<int_, str_0, start> >::type, int0> + )); + + // test_with_one_digit + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<int_, str_1, start> >::type, int1> + )); + + // test_with_big_number + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<int_, str_1983, start> >::type, + boost::mpl::int_<1983> + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<int_, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/int_to_digit.cpp b/src/boost/libs/metaparse/test/int_to_digit.cpp new file mode 100644 index 000000000..a0223f37b --- /dev/null +++ b/src/boost/libs/metaparse/test/int_to_digit.cpp @@ -0,0 +1,33 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/int_to_digit.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(int_to_digit) +{ + using boost::metaparse::util::int_to_digit; + + using boost::mpl::char_; + using boost::mpl::int_; + using boost::mpl::equal_to; + + // test0 + BOOST_MPL_ASSERT((equal_to<char_<'0'>, int_to_digit<int_<0> >::type>)); + + // test5 + BOOST_MPL_ASSERT((equal_to<char_<'5'>, int_to_digit<int_<5> >::type>)); + + // test9 + BOOST_MPL_ASSERT((equal_to<char_<'9'>, int_to_digit<int_<9> >::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/is_char_c.cpp b/src/boost/libs/metaparse/test/is_char_c.cpp new file mode 100644 index 000000000..46f579018 --- /dev/null +++ b/src/boost/libs/metaparse/test/is_char_c.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/is_char_c.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/char.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(is_char_c) +{ + using boost::metaparse::v1::impl::is_char_c; + + using boost::mpl::char_; + + // test_for_the_same_char + BOOST_MPL_ASSERT(( is_char_c<'x'>::apply<char_<'x'> > )); + + // test_for_another_char + BOOST_MPL_ASSERT_NOT(( is_char_c<'x'>::apply<char_<'y'> > )); +} + diff --git a/src/boost/libs/metaparse/test/is_digit.cpp b/src/boost/libs/metaparse/test/is_digit.cpp new file mode 100644 index 000000000..3242c4b42 --- /dev/null +++ b/src/boost/libs/metaparse/test/is_digit.cpp @@ -0,0 +1,30 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_digit.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_digit) +{ + using boost::metaparse::util::is_digit; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_digit + BOOST_MPL_ASSERT((apply_wrap1<is_digit<>, char_7>)); + + // test_non_digit + BOOST_MPL_ASSERT((not_<apply_wrap1<is_digit<>, char_a> >)); +} + + diff --git a/src/boost/libs/metaparse/test/is_error.cpp b/src/boost/libs/metaparse/test/is_error.cpp new file mode 100644 index 000000000..98dc3b0f5 --- /dev/null +++ b/src/boost/libs/metaparse/test/is_error.cpp @@ -0,0 +1,31 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/fail.hpp> + +#include "common.hpp" + +#include <boost/mpl/not.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(is_error) +{ + using boost::metaparse::is_error; + using boost::metaparse::fail; + + using boost::mpl::not_; + using boost::mpl::apply_wrap2; + + // test_not_error + BOOST_MPL_ASSERT((not_<is_error<int13> >)); + + // test_error + BOOST_MPL_ASSERT((is_error<apply_wrap2<fail<int11>, int1, int13> >)); +} + diff --git a/src/boost/libs/metaparse/test/is_lcase_letter.cpp b/src/boost/libs/metaparse/test/is_lcase_letter.cpp new file mode 100644 index 000000000..15b7a910e --- /dev/null +++ b/src/boost/libs/metaparse/test/is_lcase_letter.cpp @@ -0,0 +1,29 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_lcase_letter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_lcase_letter) +{ + using boost::metaparse::util::is_lcase_letter; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_letter + BOOST_MPL_ASSERT((apply_wrap1<is_lcase_letter<>, char_k>)); + + // test_non_letter + BOOST_MPL_ASSERT((not_<apply_wrap1<is_lcase_letter<>, char_K> >)); +} + diff --git a/src/boost/libs/metaparse/test/is_letter.cpp b/src/boost/libs/metaparse/test/is_letter.cpp new file mode 100644 index 000000000..f2ab7932b --- /dev/null +++ b/src/boost/libs/metaparse/test/is_letter.cpp @@ -0,0 +1,32 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_letter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_letter) +{ + using boost::metaparse::util::is_letter; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_lcase_letter + BOOST_MPL_ASSERT((apply_wrap1<is_letter<>, char_k>)); + + // test_ucase_letter + BOOST_MPL_ASSERT((apply_wrap1<is_letter<>, char_K>)); + + // test_not_letter + BOOST_MPL_ASSERT((not_<apply_wrap1<is_letter<>, char_7> >)); +} + diff --git a/src/boost/libs/metaparse/test/is_ucase_letter.cpp b/src/boost/libs/metaparse/test/is_ucase_letter.cpp new file mode 100644 index 000000000..5e92f7f8a --- /dev/null +++ b/src/boost/libs/metaparse/test/is_ucase_letter.cpp @@ -0,0 +1,29 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_ucase_letter.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_ucase_letter) +{ + using boost::metaparse::util::is_ucase_letter; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_letter + BOOST_MPL_ASSERT((apply_wrap1<is_ucase_letter<>, char_K>)); + + // test_non_letter + BOOST_MPL_ASSERT((not_<apply_wrap1<is_ucase_letter<>, char_k> >)); +} + diff --git a/src/boost/libs/metaparse/test/is_whitespace.cpp b/src/boost/libs/metaparse/test/is_whitespace.cpp new file mode 100644 index 000000000..08c20f439 --- /dev/null +++ b/src/boost/libs/metaparse/test/is_whitespace.cpp @@ -0,0 +1,32 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/util/is_whitespace.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(util_is_whitespace) +{ + using boost::metaparse::util::is_whitespace; + + using boost::mpl::apply_wrap1; + using boost::mpl::not_; + + // test_space + BOOST_MPL_ASSERT((apply_wrap1<is_whitespace<>, char_space>)); + + // test_tab + BOOST_MPL_ASSERT((apply_wrap1<is_whitespace<>, char_tab>)); + + // test_non_whitespace + BOOST_MPL_ASSERT((not_<apply_wrap1<is_whitespace<>, char_a> >)); +} + diff --git a/src/boost/libs/metaparse/test/iterate.cpp b/src/boost/libs/metaparse/test/iterate.cpp new file mode 100644 index 000000000..b237b93c5 --- /dev/null +++ b/src/boost/libs/metaparse/test/iterate.cpp @@ -0,0 +1,73 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/iterate.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(iterate) +{ + using boost::metaparse::is_error; + using boost::metaparse::iterate; + using boost::metaparse::one_char; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + using boost::mpl::list; + using boost::mpl::vector_c; + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<iterate<one_char, int13>, str_, start> > + )); + + // test0 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate<one_char, int0>, str_hello, start> >::type, + list<> + > + )); + + // test1 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate<one_char, int1>, str_hello, start> >::type, + vector_c<char, 'h'> + > + )); + + // test2 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate<one_char, int2>, str_hello, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test3 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate<one_char, int3>, str_hello, start> >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/iterate_c.cpp b/src/boost/libs/metaparse/test/iterate_c.cpp new file mode 100644 index 000000000..6ff4ee201 --- /dev/null +++ b/src/boost/libs/metaparse/test/iterate_c.cpp @@ -0,0 +1,73 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/iterate_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(iterate_c) +{ + using boost::metaparse::is_error; + using boost::metaparse::iterate_c; + using boost::metaparse::one_char; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + using boost::mpl::list; + using boost::mpl::vector_c; + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<iterate_c<one_char, 13>, str_, start> > + )); + + // test0 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate_c<one_char, 0>, str_hello, start> >::type, + list<> + > + )); + + // test1 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate_c<one_char, 1>, str_hello, start> >::type, + vector_c<char, 'h'> + > + )); + + // test2 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate_c<one_char, 2>, str_hello, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test3 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<iterate_c<one_char, 3>, str_hello, start> >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/keyword.cpp b/src/boost/libs/metaparse/test/keyword.cpp new file mode 100644 index 000000000..1e4fd5189 --- /dev/null +++ b/src/boost/libs/metaparse/test/keyword.cpp @@ -0,0 +1,91 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::keyword; + + using boost::mpl::list_c; + + typedef + list_c<char, 'h','e','l','l','o',' ','w','o','r','l','d'> + str_hello_world; + + typedef list_c<char, 'h','e','l','l','x'> str_hellx; + typedef list_c<char, 'h','x','l','l','o'> str_hxllo; + + typedef keyword<str_hello> keyword_hello; +} + +BOOST_METAPARSE_TEST_CASE(keyword) +{ + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::get_remaining; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + + // test_result_type + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<keyword<str_hello, char_l>, str_hello, start> + >::type, + char_l + > + )); + + // test_empty_keyword + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<keyword<str_, char_l>, str_hello, start> >::type, + char_l + > + )); + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_, start> >)); + + // test_itself + BOOST_MPL_ASSERT(( + equal< + get_remaining<apply_wrap2<keyword_hello, str_hello, start> >::type, + str_ + > + )); + + // test_more_than_itself + BOOST_MPL_ASSERT(( + equal< + get_remaining<apply_wrap2<keyword_hello, str_hello_world, start> >::type, + list_c<char, ' ', 'w', 'o', 'r', 'l', 'd'> + > + )); + + // test_no_match_at_end + BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_hellx, start> >)); + + // test_no_match_in_the_middle + BOOST_MPL_ASSERT((is_error<apply_wrap2<keyword_hello, str_hxllo, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/last_of.cpp b/src/boost/libs/metaparse/test/last_of.cpp new file mode 100644 index 000000000..e06ddaa70 --- /dev/null +++ b/src/boost/libs/metaparse/test/last_of.cpp @@ -0,0 +1,71 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/last_of.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(last_of) +{ + using boost::metaparse::get_result; + using boost::metaparse::last_of; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_one_char + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<last_of<lit_h>, str_hello, start> >::type, + char_h + > + )); + + // test_two_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<last_of<lit_h, lit_e>, str_hello, start> >::type, + char_e + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<last_of<lit_x, lit_e>, str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<last_of<lit_h, lit_x>, str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<last_of<lit_h, lit_e>, str_, start> > + )); + + // test_three_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<last_of<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + char_l + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/letter.cpp b/src/boost/libs/metaparse/test/letter.cpp new file mode 100644 index 000000000..bee753687 --- /dev/null +++ b/src/boost/libs/metaparse/test/letter.cpp @@ -0,0 +1,41 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(letter) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_with_text + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<letter, str_hello, start> >::type, char_h> + )); + + // test_with_number + BOOST_MPL_ASSERT((is_error<apply_wrap2<letter, str_1983, start> >)); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<letter, str_, start> >)); +} + + diff --git a/src/boost/libs/metaparse/test/lit.cpp b/src/boost/libs/metaparse/test/lit.cpp new file mode 100644 index 000000000..6af0c29ab --- /dev/null +++ b/src/boost/libs/metaparse/test/lit.cpp @@ -0,0 +1,74 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/error/literal_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(lit) +{ + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::get_remaining; + using boost::metaparse::get_position; + using boost::metaparse::get_message; + + using boost::metaparse::error::literal_expected; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + using boost::is_same; + + // test_accept + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<lit_h, str_hello, start> >::type, char_h> + )); + + // test_reject + BOOST_MPL_ASSERT((is_error<apply_wrap2<lit_h, str_bello, start> >)); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<lit_h, str_, start> >)); + + // test_error_with_empty_string + BOOST_MPL_ASSERT(( + is_same< + literal_expected<'h'>, + get_message<apply_wrap2<lit_h, str_, start> >::type + > + )); + + // test_remaining_string + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + lit_e, + get_remaining<apply_wrap2<lit_h, str_hello, start> >::type, + get_position<apply_wrap2<lit_h, str_hello, start> >::type + > + >::type, + char_e + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/lit_c.cpp b/src/boost/libs/metaparse/test/lit_c.cpp new file mode 100644 index 000000000..c1848477e --- /dev/null +++ b/src/boost/libs/metaparse/test/lit_c.cpp @@ -0,0 +1,74 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/error/literal_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(lit_c) +{ + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::get_remaining; + using boost::metaparse::get_position; + using boost::metaparse::get_message; + + using boost::metaparse::error::literal_expected; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + using boost::is_same; + + // test_accept + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<lit_c_h, str_hello, start> >::type, char_h> + )); + + // test_reject + BOOST_MPL_ASSERT((is_error<apply_wrap2<lit_c_h, str_bello, start> >)); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error< apply_wrap2<lit_c_h, str_, start> >)); + + // test_error_with_empty_string + BOOST_MPL_ASSERT(( + is_same< + literal_expected<'h'>, + get_message<apply_wrap2<lit_c_h, str_, start> >::type + > + )); + + // test_remaining_string + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + lit_c_e, + get_remaining<apply_wrap2<lit_c_h, str_hello, start> >::type, + get_position<apply_wrap2<lit_c_h, str_hello, start> >::type + > + >::type, + char_e + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/long_string.cpp b/src/boost/libs/metaparse/test/long_string.cpp new file mode 100644 index 000000000..4ef518782 --- /dev/null +++ b/src/boost/libs/metaparse/test/long_string.cpp @@ -0,0 +1,56 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> + +#if BOOST_METAPARSE_STD >= 2011 + +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 1024 +#include <boost/metaparse/string.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "common.hpp" +#include "test_case.hpp" +#include "string_macros.hpp" + +#ifndef BOOST_METAPARSE_V1_CONFIG_NO_BOOST_METAPARSE_STRING + +using boost::metaparse::string; +using boost::is_same; + +BOOST_METAPARSE_TEST_CASE(creating_very_long_string) +{ +// The Oracle Studio limit is 127 characters +#ifndef __SUNPRO_CC + BOOST_MPL_ASSERT(( + is_same< + string< + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_100, + BOOST_METAPARSE_TEST_CHARS_10, + '0', '1' + >, + BOOST_METAPARSE_STRING( + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_100 + BOOST_METAPARSE_TEST_STRING_10 + "01" + ) + > + )); +#endif +} + +#endif + +#endif + diff --git a/src/boost/libs/metaparse/test/look_ahead.cpp b/src/boost/libs/metaparse/test/look_ahead.cpp new file mode 100644 index 000000000..060062329 --- /dev/null +++ b/src/boost/libs/metaparse/test/look_ahead.cpp @@ -0,0 +1,60 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/look_ahead.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/digit_val.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(look_ahead) +{ + + using boost::metaparse::get_result; + using boost::metaparse::look_ahead; + using boost::metaparse::digit_val; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::fail; + using boost::metaparse::get_remaining; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + + // test_returns_result + BOOST_MPL_ASSERT(( + equal_to< + int1, + get_result<apply_wrap2<look_ahead<digit_val>, str_1983, start> >::type + > + )); + + // test_returns_error + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<look_ahead<fail<int13> >, str_1983, start> > + )); + + // test_doesnt_process_input + BOOST_MPL_ASSERT(( + equal< + str_1983, + get_remaining<apply_wrap2<look_ahead<digit_val>, str_1983, start> >::type + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/middle_of.cpp b/src/boost/libs/metaparse/test/middle_of.cpp new file mode 100644 index 000000000..afc308ba2 --- /dev/null +++ b/src/boost/libs/metaparse/test/middle_of.cpp @@ -0,0 +1,81 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/middle_of.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/error/unpaired.hpp> +#include <boost/metaparse/error/literal_expected.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(middle_of) +{ + using boost::metaparse::get_result; + using boost::metaparse::middle_of; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::get_message; + + using boost::metaparse::error::unpaired; + using boost::metaparse::error::literal_expected; + + using boost::is_same; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_three_chars + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<middle_of<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + char_e + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<middle_of<lit_x, lit_e, lit_l>, str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<middle_of<lit_h, lit_x, lit_l>, str_hello, start> > + )); + + // test_third_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<middle_of<lit_h, lit_e, lit_x>, str_hello, start> > + )); + + // test_error_message_when_third_fails + BOOST_MPL_ASSERT(( + is_same< + unpaired<1, 1, literal_expected<'x'> >, + get_message< + apply_wrap2<middle_of<lit_h, lit_e, lit_x>, str_hello, start> + >::type + > + )); + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<middle_of<lit_h, lit_e, lit_l>, str_, start> > + )); +} + + diff --git a/src/boost/libs/metaparse/test/next_digit.cpp b/src/boost/libs/metaparse/test/next_digit.cpp new file mode 100644 index 000000000..376b61698 --- /dev/null +++ b/src/boost/libs/metaparse/test/next_digit.cpp @@ -0,0 +1,25 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/next_digit.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/int.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(next_digit) +{ + using boost::metaparse::v1::impl::next_digit; + + using boost::mpl::equal_to; + using boost::mpl::int_; + + BOOST_MPL_ASSERT((equal_to<int_< 0>, next_digit::apply<int_<0>, int_<0> > >)); + BOOST_MPL_ASSERT((equal_to<int_<10>, next_digit::apply<int_<1>, int_<0> > >)); + BOOST_MPL_ASSERT((equal_to<int_<13>, next_digit::apply<int_<1>, int_<3> > >)); +} + diff --git a/src/boost/libs/metaparse/test/nth_of.cpp b/src/boost/libs/metaparse/test/nth_of.cpp new file mode 100644 index 000000000..aa9884213 --- /dev/null +++ b/src/boost/libs/metaparse/test/nth_of.cpp @@ -0,0 +1,97 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/nth_of.hpp> +#include <boost/metaparse/nth_of_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/start.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(nth_of) +{ + using boost::metaparse::get_result; + using boost::metaparse::nth_of_c; + using boost::metaparse::start; + using boost::metaparse::nth_of; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + namespace mpl = boost::mpl; + namespace mp = boost::metaparse; + + // test_first_of_one + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<nth_of_c<0, lit_h>, str_hello, start> >::type, + char_h + > + )); + + // test_first_of_two + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<nth_of_c<0, lit_h, lit_e>, str_hello, start> + >::type, + char_h + > + )); + + // test_second_of_two + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<nth_of<int1, lit_h, lit_e>, str_hello, start> + >::type, + char_e + > + )); + + // test_nothing + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<1, lit_x, lit_e>, str_hello, start> > + )); + + // test_first_of_none + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<0>, str_hello, start> > + )); + + // test_n_is_less_than_zero + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<-1, lit_h, lit_e>, str_hello, start> > + )); + + // test_n_is_greater_than_the_number_of_parsers + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<2, lit_h, lit_e>, str_hello, start> > + )); + + // test_error_before_the_nth + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<1, lit_x, lit_e, lit_l>, str_hello, start> > + )); + + // test_error_at_the_nth + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<1, lit_h, lit_x, lit_l>, str_hello, start> > + )); + + // test_error_after_the_nth + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<nth_of_c<1, lit_h, lit_e, lit_x>, str_hello, start> > + )); +} + diff --git a/src/boost/libs/metaparse/test/one_char.cpp b/src/boost/libs/metaparse/test/one_char.cpp new file mode 100644 index 000000000..5eff7521d --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char.cpp @@ -0,0 +1,16 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_char.hpp> + +namespace +{ + typedef boost::metaparse::one_char oc; +} + +#define TEST_NAME one_char + +#include "one_char_test.hpp" + diff --git a/src/boost/libs/metaparse/test/one_char_except.cpp b/src/boost/libs/metaparse/test/one_char_except.cpp new file mode 100644 index 000000000..b8b540316 --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char_except.cpp @@ -0,0 +1,19 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_char_except.hpp> + +#include "common.hpp" + +namespace +{ + typedef boost::metaparse::one_char_except<char_0, char_1> oc; +} + +#define TEST_NAME test_one_char_except + +#include "one_char_except_test.hpp" + + diff --git a/src/boost/libs/metaparse/test/one_char_except_c.cpp b/src/boost/libs/metaparse/test/one_char_except_c.cpp new file mode 100644 index 000000000..a84097804 --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char_except_c.cpp @@ -0,0 +1,18 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_char_except_c.hpp> + +#include "common.hpp" + +namespace +{ + typedef boost::metaparse::one_char_except_c<'0', '1'> oc; +} + +#define TEST_NAME one_char_except_c + +#include "one_char_except_test.hpp" + diff --git a/src/boost/libs/metaparse/test/one_char_except_test.hpp b/src/boost/libs/metaparse/test/one_char_except_test.hpp new file mode 100644 index 000000000..47ab60cad --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char_except_test.hpp @@ -0,0 +1,33 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/is_error.hpp> + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/preprocessor/cat.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(BOOST_PP_CAT(TEST_NAME, _except)) +{ + using boost::metaparse::is_error; + using boost::metaparse::start; + + using boost::mpl::apply_wrap2; + + // rejects_except_char + BOOST_MPL_ASSERT((is_error<apply_wrap2<oc, str_0, start> >)); + + // rejects_other_except_char + BOOST_MPL_ASSERT((is_error<apply_wrap2<oc, str_1, start> >)); +} + +#include "one_char_test.hpp" + diff --git a/src/boost/libs/metaparse/test/one_char_test.hpp b/src/boost/libs/metaparse/test/one_char_test.hpp new file mode 100644 index 000000000..033415b50 --- /dev/null +++ b/src/boost/libs/metaparse/test/one_char_test.hpp @@ -0,0 +1,103 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010 - 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/get_line.hpp> +#include <boost/metaparse/iterate_c.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::start; + + using boost::mpl::list_c; + using boost::mpl::apply_wrap2; + + typedef list_c<char, 'a','\n','b'> unix_multi_line_text; + typedef list_c<char, 'a','\r','\n','b'> dos_multi_line_text; + typedef list_c<char, 'a','\r','b'> mac_multi_line_text; + + typedef apply_wrap2<oc, str_hello, start> parse_first_char; +} + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::get_remaining; + using boost::metaparse::get_position; + using boost::metaparse::is_error; + using boost::metaparse::iterate_c; + using boost::metaparse::get_line; + + using boost::mpl::equal_to; + + // test_for_non_empty_string + BOOST_MPL_ASSERT((equal_to<get_result<parse_first_char>::type, char_h>)); + + // test_for_non_empty_string_second + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2< + oc, + get_remaining<parse_first_char>::type, + get_position<parse_first_char>::type + > + >::type, + char_e + > + )); + + // test_for_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<oc, str_, start> >)); + + // test_unix_multi_line_text + BOOST_MPL_ASSERT(( + equal_to< + int2, + get_line< + get_position< + apply_wrap2<iterate_c<oc, 2>, unix_multi_line_text, start> + > + > + > + )); + + // test_dos_multi_line_text + BOOST_MPL_ASSERT(( + equal_to< + int2, + get_line< + get_position<apply_wrap2<iterate_c<oc, 3>, dos_multi_line_text, start> > + > + > + )); + + // test_mac_multi_line_text + BOOST_MPL_ASSERT(( + equal_to< + int2, + get_line< + get_position<apply_wrap2<iterate_c<oc, 2>, mac_multi_line_text, start> > + > + > + )); +} + + + diff --git a/src/boost/libs/metaparse/test/one_of.cpp b/src/boost/libs/metaparse/test/one_of.cpp new file mode 100644 index 000000000..b7890f00d --- /dev/null +++ b/src/boost/libs/metaparse/test/one_of.cpp @@ -0,0 +1,158 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_of.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/next_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(one_of) +{ + using boost::metaparse::is_error; + using boost::metaparse::one_of; + using boost::metaparse::start; + using boost::metaparse::get_result; + using boost::metaparse::one_char; + using boost::metaparse::fail; + using boost::metaparse::sequence; + using boost::metaparse::get_position; + using boost::metaparse::next_char; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + typedef fail<test_failure> test_fail; + typedef sequence<one_char, test_fail> test_fail_later; + + // test_1_with_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of<one_char>, str_hello, start> >::type, + char_h + > + )); + + // test_1_with_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of<test_fail>, str_hello, start> > + )); + + // test_2_with_two_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<one_char, one_char>, str_hello, start> + >::type, + char_h + > + )); + + // test_2_with_first_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<one_char, test_fail>, str_hello, start> + >::type, + char_h + > + )); + + // test_2_with_second_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<test_fail, one_char>, str_hello, start> + >::type, + char_h + > + )); + + // test_2_with_two_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of<test_fail, test_fail>, str_hello, start> > + )); + + + + + + // test + BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of< >, str_hello, start> >)); + + // test_with_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of<one_char>, str_hello, start> >::type, + char_h + > + )); + + // test_with_bad + BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of<test_fail>,str_hello,start> >)); + + // test_with_two_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<one_char, one_char>, str_hello, start> + >::type, + char_h + > + )); + + // test_with_first_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<one_char, test_fail>, str_hello, start> + >::type, + char_h + > + )); + + // test_with_second_good + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<one_of<test_fail, one_char>, str_hello, start> + >::type, + char_h + > + )); + + // test_with_two_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of<test_fail, test_fail>, str_hello, start> > + )); + + // test_error_is_the_last_error + BOOST_MPL_ASSERT(( + equal_to< + next_char<start, char_h>::type, + get_position< + apply_wrap2< + one_of<test_fail, test_fail_later>, + str_hello, + start + > + >::type + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/one_of_c.cpp b/src/boost/libs/metaparse/test/one_of_c.cpp new file mode 100644 index 000000000..010cb5b8f --- /dev/null +++ b/src/boost/libs/metaparse/test/one_of_c.cpp @@ -0,0 +1,75 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/one_of_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(one_of_c) +{ + using boost::metaparse::is_error; + using boost::metaparse::one_of_c; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + + // test0 + BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of_c< >, str_hello, start> >)); + + // test_1_with_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of_c<'h'>, str_hello, start> >::type, + char_h + > + )); + + // test_1_with_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of_c<'x'>, str_hello, start> > + )); + + // test_2_with_two_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of_c<'h', 'x'>, str_hello, start> >::type, + char_h + > + )); + + // test_2_with_first_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of_c<'h', 'x'>, str_hello, start> >::type, + char_h + > + )); + + // test_2_with_second_good + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<one_of_c<'x', 'h'>, str_hello, start> >::type, + char_h + > + )); + + // test_2_with_two_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<one_of_c<'x', 'y'>, str_hello, start> > + )); +} + + diff --git a/src/boost/libs/metaparse/test/optional.cpp b/src/boost/libs/metaparse/test/optional.cpp new file mode 100644 index 000000000..4bba83b26 --- /dev/null +++ b/src/boost/libs/metaparse/test/optional.cpp @@ -0,0 +1,55 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/optional.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/start.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(optional) +{ + using boost::metaparse::optional; + using boost::metaparse::lit_c; + using boost::metaparse::string; + using boost::metaparse::get_result; + using boost::metaparse::start; + + using boost::mpl::equal_to; + + using boost::is_same; + + typedef optional<lit_c<'x'>, double> optional_x; + + // test_optional_parser_succeeds + BOOST_MPL_ASSERT(( + equal_to< + boost::mpl::char_<'x'>, + get_result<optional_x::apply<string<'x'>, start> >::type + > + )); + + // test_optional_parser_fails + BOOST_MPL_ASSERT(( + is_same<double, get_result<optional_x::apply<string<'y'>, start> >::type> + )); + + // test_optional_parser_default_value + BOOST_MPL_ASSERT(( + is_same< + void, + get_result<optional<lit_c<'x'> >::apply<string<'y'>, start> >::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/pop_back.cpp b/src/boost/libs/metaparse/test/pop_back.cpp new file mode 100644 index 000000000..b74c83b61 --- /dev/null +++ b/src/boost/libs/metaparse/test/pop_back.cpp @@ -0,0 +1,38 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/pop_back.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/pop_back.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(pop_back) +{ + using boost::metaparse::v1::impl::pop_back; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_pop_back + BOOST_MPL_ASSERT((equal_to<string<'h','e','l','l'>, pop_back<hello>::type>)); + + // test_pop_back_one_element + BOOST_MPL_ASSERT((equal_to<string<>, pop_back<string<'x'> >::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/pop_front.cpp b/src/boost/libs/metaparse/test/pop_front.cpp new file mode 100644 index 000000000..988ec8227 --- /dev/null +++ b/src/boost/libs/metaparse/test/pop_front.cpp @@ -0,0 +1,38 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/pop_front.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/pop_front.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(pop_front) +{ + using boost::metaparse::v1::impl::pop_front; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_pop_front + BOOST_MPL_ASSERT((equal_to<string<'e','l','l','o'>, pop_front<hello>::type>)); + + // test_pop_front_one_element + BOOST_MPL_ASSERT((equal_to<string<>, pop_front<string<'x'> >::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/push_back_c.cpp b/src/boost/libs/metaparse/test/push_back_c.cpp new file mode 100644 index 000000000..0927197ed --- /dev/null +++ b/src/boost/libs/metaparse/test/push_back_c.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/push_back_c.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/push_back_c.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(push_back_c) +{ + using boost::metaparse::v1::impl::push_back_c; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_push_back + BOOST_MPL_ASSERT(( + equal_to<hello, push_back_c<string<'h','e','l','l'>, 'o'>::type> + )); + + // test_push_back_to_empty + BOOST_MPL_ASSERT((equal_to<string<'x'>, push_back_c<string<>, 'x'>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/push_front_c.cpp b/src/boost/libs/metaparse/test/push_front_c.cpp new file mode 100644 index 000000000..9ac65865c --- /dev/null +++ b/src/boost/libs/metaparse/test/push_front_c.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/push_front_c.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/push_front_c.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(push_front_c) +{ + using boost::metaparse::v1::impl::push_front_c; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef string<'h','e','l','l','o'> hello; + + // test_push_front + BOOST_MPL_ASSERT(( + equal_to<hello, push_front_c<string<'e','l','l','o'>, 'h'>::type> + )); + + // test_push_front_to_empty + BOOST_MPL_ASSERT((equal_to<string<'x'>, push_front_c<string<>, 'x'>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/range.cpp b/src/boost/libs/metaparse/test/range.cpp new file mode 100644 index 000000000..9c93c06e6 --- /dev/null +++ b/src/boost/libs/metaparse/test/range.cpp @@ -0,0 +1,47 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/range.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/char.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(range) +{ + using boost::metaparse::is_error; + using boost::metaparse::range; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef range<char_<'0'>, char_<'9'> > digit_range; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_range, str_hello, start> >)); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<digit_range, str_1983, start> >::type, + char_1 + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_range, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/range_c.cpp b/src/boost/libs/metaparse/test/range_c.cpp new file mode 100644 index 000000000..1a734cfd5 --- /dev/null +++ b/src/boost/libs/metaparse/test/range_c.cpp @@ -0,0 +1,47 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/range_c.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/char.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(range_c) +{ + using boost::metaparse::is_error; + using boost::metaparse::range_c; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::mpl::char_; + + typedef range_c<'0', '9'> digit_range; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_range, str_hello, start> >)); + + // test_with_number + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<digit_range, str_1983, start> >::type, + char_1 + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<digit_range, str_, start> >)); +} + diff --git a/src/boost/libs/metaparse/test/reject.cpp b/src/boost/libs/metaparse/test/reject.cpp new file mode 100644 index 000000000..5dfe2ad1f --- /dev/null +++ b/src/boost/libs/metaparse/test/reject.cpp @@ -0,0 +1,58 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/reject.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_message.hpp> +#include <boost/metaparse/get_position.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +namespace +{ + template <class T> + struct returns + { + typedef T type; + }; + + template <class T> + struct get_foo + { + typedef typename T::foo type; + }; +} + +BOOST_METAPARSE_TEST_CASE(reject) +{ + using boost::metaparse::reject; + using boost::metaparse::start; + using boost::metaparse::get_message; + using boost::metaparse::get_position; + + using boost::is_same; + + // test_reject_is_metaprogramming_value + BOOST_MPL_ASSERT((is_same<reject<int, start>, reject<int, start>::type>)); + + // test_reject_is_not_lazy + BOOST_MPL_ASSERT(( + is_same< + reject<get_foo<int>, start>, + reject<get_foo<int>, returns<start> >::type + > + )); + + // test_get_message_of_reject + BOOST_MPL_ASSERT((is_same<int, get_message<reject<int, start> >::type>)); + + // test_get_position_of_reject + BOOST_MPL_ASSERT((is_same<start, get_position<reject<int, start> >::type>)); +} + diff --git a/src/boost/libs/metaparse/test/repeated.cpp b/src/boost/libs/metaparse/test/repeated.cpp new file mode 100644 index 000000000..f7b57da1b --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated.hpp> + +using boost::metaparse::repeated; + +#define TEST_NAME repeated + +#include "repeated_test.hpp" + diff --git a/src/boost/libs/metaparse/test/repeated1.cpp b/src/boost/libs/metaparse/test/repeated1.cpp new file mode 100644 index 000000000..c1d47b23a --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated1.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated1.hpp> + +using boost::metaparse::repeated1; + +#define TEST_NAME repeated1 + +#include "repeated1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/repeated1_test.hpp b/src/boost/libs/metaparse/test/repeated1_test.hpp new file mode 100644 index 000000000..848b23221 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated1_test.hpp @@ -0,0 +1,99 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::equal; + using boost::mpl::apply_wrap2; + using boost::mpl::list; + using boost::mpl::vector_c; + using boost::mpl::vector; + + typedef repeated1<letter> repeated1_letter; + typedef always<one_char, int> always_int; + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<repeated1_letter, str_, start> >)); + + // test0 + BOOST_MPL_ASSERT((is_error<apply_wrap2<repeated1_letter, chars0, start> >)); + + // test1 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars1, start> >::type, + vector_c<char, 'h'> + > + )); + + // test2 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars2, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test3 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars3, start> >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); + + // test4 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars4, start> >::type, + vector_c<char, 'h', 'e', 'l', 'l'> + > + )); + + // test5 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1_letter, chars5, start> >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated1<always_int>, str_ca, start> >::type, + vector<int, int> + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/repeated_one_of.cpp b/src/boost/libs/metaparse/test/repeated_one_of.cpp new file mode 100644 index 000000000..488ae46ae --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_one_of.cpp @@ -0,0 +1,106 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated_one_of.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(repeated_one_of) +{ + using boost::metaparse::fail; + using boost::metaparse::get_result; + using boost::metaparse::repeated_one_of; + using boost::metaparse::start; + using boost::metaparse::one_char; + using boost::metaparse::keyword; + + using boost::mpl::equal; + using boost::mpl::apply_wrap2; + using boost::mpl::list; + using boost::mpl::vector_c; + + typedef fail<test_failure> test_fail; + + // test0 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_one_of< >, str_hello, start> >::type, + list<> + > + )); + + // test_good_sequence + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of<one_char>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_1_with_bad + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of<test_fail>, str_hello, start> + >::type, + list< > + > + )); + + // test_2_with_first_good + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of<one_char, test_fail>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_2_with_second_good + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of<test_fail, one_char>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + typedef keyword<str_h, char_h> keyword_h; + typedef keyword<str_e, char_e> keyword_e; + typedef keyword<str_l, char_l> keyword_l; + + // test_accept_any_argument + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2< + repeated_one_of<keyword_h, keyword_e, keyword_l>, + str_hello, + start + > + >::type, + list<char_h, char_e, char_l, char_l> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/repeated_one_of1.cpp b/src/boost/libs/metaparse/test/repeated_one_of1.cpp new file mode 100644 index 000000000..a4ba3013e --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_one_of1.cpp @@ -0,0 +1,100 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated_one_of1.hpp> +#include <boost/metaparse/one_char.hpp> +#include <boost/metaparse/fail.hpp> +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(repeated_one_of1) +{ + using boost::metaparse::fail; + using boost::metaparse::is_error; + using boost::metaparse::repeated_one_of1; + using boost::metaparse::start; + using boost::metaparse::get_result; + using boost::metaparse::one_char; + using boost::metaparse::keyword; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + using boost::mpl::list; + using boost::mpl::vector_c; + + typedef fail<test_failure> test_fail; + + // test0 + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<repeated_one_of1< >, str_hello, start> > + )); + + // test_good_sequence + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of1<one_char>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_1_with_bad + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<repeated_one_of1<test_fail>, str_hello, start> > + )); + + // test_2_with_first_good + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of1<one_char, test_fail>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_2_with_second_good + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_one_of1<test_fail, one_char>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + typedef keyword<str_h, char_h> keyword_h; + typedef keyword<str_e, char_e> keyword_e; + typedef keyword<str_l, char_l> keyword_l; + + // test_accept_any_argument + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2< + repeated_one_of1<keyword_h, keyword_e, keyword_l>, + str_hello, + start + > + >::type, + list<char_h, char_e, char_l, char_l> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/repeated_reject_incomplete.cpp b/src/boost/libs/metaparse/test/repeated_reject_incomplete.cpp new file mode 100644 index 000000000..3bf61c970 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_reject_incomplete.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated_reject_incomplete.hpp> + +using boost::metaparse::repeated_reject_incomplete; + +#define TEST_NAME repeated_reject_incomplete + +#include "repeated_reject_incomplete_test.hpp" + diff --git a/src/boost/libs/metaparse/test/repeated_reject_incomplete1.cpp b/src/boost/libs/metaparse/test/repeated_reject_incomplete1.cpp new file mode 100644 index 000000000..145d3866d --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_reject_incomplete1.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/repeated_reject_incomplete1.hpp> + +using boost::metaparse::repeated_reject_incomplete1; + +#define TEST_NAME repeated_reject_incomplete1 + +#include "repeated_reject_incomplete1_test.hpp" + diff --git a/src/boost/libs/metaparse/test/repeated_reject_incomplete1_test.hpp b/src/boost/libs/metaparse/test/repeated_reject_incomplete1_test.hpp new file mode 100644 index 000000000..5e3fda368 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_reject_incomplete1_test.hpp @@ -0,0 +1,173 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::sequence; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::equal; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::vector_c; + using boost::mpl::vector; + using boost::mpl::size; + + typedef sequence<letter, letter> letter_pair; + typedef + repeated_reject_incomplete1<letter_pair> + repeated_reject_incomplete1_letter_pair; + typedef always<one_char, int> always_int; + + typedef boost::mpl::vector_c<char, 'h','e','l','l','o','w','0'> chars6; + + typedef + boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','0'> + chars8; + + typedef + boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','l','d','0'> + chars10; + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<repeated_reject_incomplete1_letter_pair, str_, start> + > + )); + + // test0 + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars0, start> + > + )); + + // test1_pair + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars2, start> + >::type, + vector<vector_c<char, 'h', 'e'> >, + equal_sequences + > + )); + + // test_with_a_failing_item + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars3, start> + > + )); + + // test2_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars4, start> + >::type, + vector<vector_c<char, 'h','e'>, vector_c<char, 'l','l'> >, + equal_sequences + > + )); + + // test3_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars6, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'> + >, + equal_sequences + > + )); + + // test4_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars8, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'>, + vector_c<char, 'o','r'> + >, + equal_sequences + > + )); + + // test5 + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars10, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'>, + vector_c<char, 'o','r'>, + vector_c<char, 'l','d'> + >, + equal_sequences + > + )); + + // test_length + BOOST_MPL_ASSERT(( + equal_to< + size< + get_result< + apply_wrap2<repeated_reject_incomplete1_letter_pair, chars6, start> + >::type + >::type, + int3 + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete1<always_int>, str_ca, start> + >::type, + vector<int, int> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/repeated_reject_incomplete_test.hpp b/src/boost/libs/metaparse/test/repeated_reject_incomplete_test.hpp new file mode 100644 index 000000000..5f21b2f16 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_reject_incomplete_test.hpp @@ -0,0 +1,176 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::sequence; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::equal; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::vector_c; + using boost::mpl::vector; + using boost::mpl::size; + + typedef sequence<letter, letter> letter_pair; + typedef + repeated_reject_incomplete<letter_pair> + repeated_reject_incomplete_letter_pair; + typedef always<one_char, int> always_int; + + typedef boost::mpl::vector_c<char, 'h','e','l','l','o','w','0'> chars6; + + typedef + boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','0'> + chars8; + + typedef + boost::mpl::vector_c<char, 'h','e','l','l','o','w','o','r','l','d','0'> + chars10; + + // test_empty_input + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, str_, start> + >::type, + vector<> + > + )); + + // test0 + BOOST_MPL_ASSERT_NOT(( + is_error< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars0, start> + > + )); + + // test_with_a_failing_item + BOOST_MPL_ASSERT(( + is_error< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars1, start> + > + )); + + // test1_pair + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars2, start> + >::type, + vector<vector_c<char, 'h', 'e'> >, + equal_sequences + > + )); + + // test2_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars4, start> + >::type, + vector<vector_c<char, 'h','e'>, vector_c<char, 'l','l'> >, + equal_sequences + > + )); + + // test3_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars6, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'> + >, + equal_sequences + > + )); + + // test4_pairs + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars8, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'>, + vector_c<char, 'o','r'> + >, + equal_sequences + > + )); + + // test5 + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars10, start> + >::type, + vector< + vector_c<char, 'h','e'>, + vector_c<char, 'l','l'>, + vector_c<char, 'o','w'>, + vector_c<char, 'o','r'>, + vector_c<char, 'l','d'> + >, + equal_sequences + > + )); + + // test_length + BOOST_MPL_ASSERT(( + equal_to< + size< + get_result< + apply_wrap2<repeated_reject_incomplete_letter_pair, chars6, start> + >::type + >::type, + int3 + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<repeated_reject_incomplete<always_int>, str_ca, start> + >::type, + vector<int, int> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/repeated_test.hpp b/src/boost/libs/metaparse/test/repeated_test.hpp new file mode 100644 index 000000000..0f2405136 --- /dev/null +++ b/src/boost/libs/metaparse/test/repeated_test.hpp @@ -0,0 +1,117 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// This header file contains code that is reused by other cpp files + +#include <boost/metaparse/letter.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(TEST_NAME) +{ + using boost::metaparse::get_result; + using boost::metaparse::letter; + using boost::metaparse::start; + using boost::metaparse::one_char; + using boost::metaparse::always; + + using boost::mpl::equal; + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::vector_c; + using boost::mpl::vector; + using boost::mpl::list; + using boost::mpl::size; + + typedef repeated<letter> repeated_letter; + typedef always<one_char, int> always_int; + + // test_empty_input + BOOST_MPL_ASSERT(( + equal<get_result<apply_wrap2<repeated_letter, str_, start> >::type, list<> > + )); + + // test0 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars0, start> >::type, + list<> + > + )); + + // test1 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars1, start> >::type, + vector_c<char, 'h'> + > + )); + + // test2 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars2, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test3 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars3, start> >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); + + // test4 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars4, start> >::type, + vector_c<char, 'h', 'e', 'l', 'l'> + > + )); + + // test5 + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated_letter, chars5, start> >::type, + vector_c<char, 'h', 'e', 'l', 'l', 'o'> + > + )); + + // test_length + BOOST_MPL_ASSERT(( + equal_to< + size< + get_result<apply_wrap2<repeated_letter, chars3, start> >::type + >::type, + int3 + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<repeated<always_int>, str_ca, start> >::type, + vector<int, int> + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/return_.cpp b/src/boost/libs/metaparse/test/return_.cpp new file mode 100644 index 000000000..8c60fba88 --- /dev/null +++ b/src/boost/libs/metaparse/test/return_.cpp @@ -0,0 +1,61 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/return_.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> +#include <boost/metaparse/get_position.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::return_; + + using boost::mpl::apply_wrap2; + + typedef apply_wrap2<return_<int1>, int2, int3> acc; + + typedef return_<char_x> return_x; +} + +BOOST_METAPARSE_TEST_CASE(return) +{ + using boost::metaparse::get_result; + using boost::metaparse::get_remaining; + using boost::metaparse::get_position; + using boost::metaparse::start; + + using boost::mpl::equal_to; + + // test_for_non_empty_string + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<return_x, str_hello, start> >::type, char_x> + )); + + // test_for_empty_string + BOOST_MPL_ASSERT(( + equal_to<get_result<apply_wrap2<return_x, str_, start> >::type, char_x> + )); + + + // test_get_result + BOOST_MPL_ASSERT((equal_to<int1, get_result<acc>::type>)); + + // test_get_remaining + BOOST_MPL_ASSERT((equal_to<int2, get_remaining<acc>::type>)); + + // test_get_position + BOOST_MPL_ASSERT((equal_to<int3, get_position<acc>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/returns.cpp b/src/boost/libs/metaparse/test/returns.cpp new file mode 100644 index 000000000..47f5ed82d --- /dev/null +++ b/src/boost/libs/metaparse/test/returns.cpp @@ -0,0 +1,23 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/returns.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(returns) +{ + using boost::metaparse::v1::impl::returns; + + using boost::is_same; + + // test_returns_evaluates_to_its_argument + BOOST_MPL_ASSERT((is_same<int, returns<int>::type>)); +} + diff --git a/src/boost/libs/metaparse/test/sequence.cpp b/src/boost/libs/metaparse/test/sequence.cpp new file mode 100644 index 000000000..bc2757784 --- /dev/null +++ b/src/boost/libs/metaparse/test/sequence.cpp @@ -0,0 +1,115 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/sequence.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(sequence) +{ + using boost::metaparse::get_result; + using boost::metaparse::sequence; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::equal; + using boost::mpl::apply_wrap2; + using boost::mpl::list; + using boost::mpl::equal_to; + using boost::mpl::at_c; + using boost::mpl::vector_c; + using boost::mpl::vector; + + typedef always<one_char, int> always_int; + + // test_no_parser + BOOST_MPL_ASSERT(( + equal<get_result<apply_wrap2<sequence<>, str_hello, start> >::type, list<> > + )); + + // test_one_parser + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<sequence<lit_h>, str_hello, start> >::type, + vector_c<char, 'h'> + > + )); + + // test_one_failing_parser + BOOST_MPL_ASSERT((is_error<apply_wrap2<sequence<lit_e>, str_hello, start> >)); + + // test_two_chars + BOOST_MPL_ASSERT(( + equal< + get_result<apply_wrap2<sequence<lit_h, lit_e>, str_hello, start> >::type, + vector_c<char, 'h', 'e'> + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<sequence<lit_x, lit_e>, str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<sequence<lit_h, lit_x>, str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<sequence<lit_h,lit_e>, str_,start> >)); + + // test_three_chars + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<sequence<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + vector_c<char, 'h', 'e', 'l'> + > + )); + + // test_indexing_in_result + BOOST_MPL_ASSERT(( + equal_to< + at_c< + get_result< + apply_wrap2<sequence<lit_h, lit_e, lit_l>, str_hello, start> + >::type, + 1 + >::type, + char_e + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + equal< + get_result< + apply_wrap2<sequence<always_int, always_int>, str_ca, start> + >::type, + vector<int, int> + > + )); +} + diff --git a/src/boost/libs/metaparse/test/sequence_apply.cpp b/src/boost/libs/metaparse/test/sequence_apply.cpp new file mode 100644 index 000000000..4d4cd5c6c --- /dev/null +++ b/src/boost/libs/metaparse/test/sequence_apply.cpp @@ -0,0 +1,162 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/sequence_apply.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/always.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/list.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/vector_c.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/char.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <boost/preprocessor/repetition/repeat_from_to.hpp> +#include <boost/preprocessor/repetition/enum_params.hpp> +#include <boost/preprocessor/repetition/enum.hpp> +#include <boost/preprocessor/tuple/eat.hpp> +#include <boost/preprocessor/cat.hpp> + +#include "test_case.hpp" + +namespace +{ +#ifdef BOOST_METAPARSE_C_VALUE +# error BOOST_METAPARSE_C_VALUE already defined +#endif +#define BOOST_METAPARSE_C_VALUE(z, n, unused) BOOST_PP_CAT(C, n)::value + +#ifdef BOOST_METAPARSE_TEMPLATE +# error BOOST_METAPARSE_TEMPLATE already defined +#endif +#define BOOST_METAPARSE_TEMPLATE(z, n, unused) \ + template <BOOST_PP_ENUM(n, char BOOST_PP_TUPLE_EAT(3), ~)> \ + struct BOOST_PP_CAT(template_c, n) \ + { \ + typedef BOOST_PP_CAT(template_c, n) type; \ + }; \ + \ + template <BOOST_PP_ENUM_PARAMS(n, class C)> \ + struct BOOST_PP_CAT(template, n) \ + { \ + typedef \ + BOOST_PP_CAT(template_c, n)< \ + BOOST_PP_ENUM(n, BOOST_METAPARSE_C_VALUE, ~) \ + > \ + type; \ + }; + + BOOST_PP_REPEAT_FROM_TO(1, 4, BOOST_METAPARSE_TEMPLATE, ~) + +#undef BOOST_METAPARSE_TEMPLATE +#undef BOOST_METAPARSE_C_VALUE + + template <class T> struct has_no_type {}; + + // "is_same<T::type::type, double_eval<T>::type>" - helper tool to avoid + // writing type::type (which is interpreted as the constructor of ::type by + // msvc-7.1) + template <class T> struct double_eval : T::type {}; +} + +BOOST_METAPARSE_TEST_CASE(sequence_apply) +{ + using boost::metaparse::get_result; + using boost::metaparse::sequence_apply1; + using boost::metaparse::sequence_apply2; + using boost::metaparse::sequence_apply3; + using boost::metaparse::start; + using boost::metaparse::is_error; + using boost::metaparse::always; + using boost::metaparse::one_char; + + using boost::mpl::list; + using boost::mpl::equal_to; + using boost::mpl::at_c; + using boost::mpl::vector_c; + using boost::mpl::vector; + using boost::mpl::char_; + + using boost::is_same; + + typedef always<one_char, int> always_int; + + // test_one_parser + BOOST_MPL_ASSERT(( + is_same< + template_c1<'h'>, + double_eval< + get_result< + sequence_apply1<template1, lit_h>::apply<str_hello, start> + > + >::type + > + )); + + // test_one_failing_parser + BOOST_MPL_ASSERT(( + is_error<sequence_apply1<template1, lit_e>::apply<str_hello, start> > + )); + + // test_two_chars + BOOST_MPL_ASSERT(( + is_same< + template_c2<'h', 'e'>, + double_eval< + get_result< + sequence_apply2<template2, lit_h, lit_e>::apply<str_hello, start> + > + >::type + > + )); + + // test_first_fails + BOOST_MPL_ASSERT(( + is_error<sequence_apply2<template2, lit_x, lit_e>::apply<str_hello, start> > + )); + + // test_second_fails + BOOST_MPL_ASSERT(( + is_error<sequence_apply2<template2, lit_h, lit_x>::apply<str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT(( + is_error<sequence_apply2<template2, lit_h, lit_e>::apply<str_,start> > + )); + + // test_three_chars + BOOST_MPL_ASSERT(( + is_same< + template_c3<'h', 'e', 'l'>, + double_eval< + get_result< + sequence_apply3<template3, lit_h, lit_e, lit_l> + ::apply<str_hello, start> + > + >::type + > + )); + + // test_no_extra_evaluation + BOOST_MPL_ASSERT(( + is_same< + has_no_type<int>, + get_result< + sequence_apply1<has_no_type, always_int>::apply<str_ca, start> + >::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/size.cpp b/src/boost/libs/metaparse/test/size.cpp new file mode 100644 index 000000000..62ae0a6ae --- /dev/null +++ b/src/boost/libs/metaparse/test/size.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD >= 2011 +# include <boost/metaparse/v1/cpp11/impl/size.hpp> +#else +# include <boost/metaparse/v1/cpp98/impl/size.hpp> +#endif + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(size) +{ + using boost::metaparse::v1::impl::size; + using boost::metaparse::string; + + using boost::mpl::equal_to; + using boost::mpl::int_; + + // test_0 + BOOST_MPL_ASSERT((equal_to<int_<0>, size<string<> >::type>)); + + // test_1_ + BOOST_MPL_ASSERT((equal_to<int_<1>, size<string<'x'> >::type>)); + + // test_5 + BOOST_MPL_ASSERT((equal_to<int_<4>, size<string<'1','2','3','4'> >::type>)); + +} + + diff --git a/src/boost/libs/metaparse/test/source_position.cpp b/src/boost/libs/metaparse/test/source_position.cpp new file mode 100644 index 000000000..4715bc582 --- /dev/null +++ b/src/boost/libs/metaparse/test/source_position.cpp @@ -0,0 +1,339 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/source_position.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/next_char.hpp> +#include <boost/metaparse/next_line.hpp> +#include <boost/metaparse/get_prev_char.hpp> +#include <boost/metaparse/get_line.hpp> +#include <boost/metaparse/get_col.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/not_equal_to.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/less.hpp> +#include <boost/mpl/greater.hpp> +#include <boost/mpl/greater_equal.hpp> +#include <boost/mpl/less_equal.hpp> +#include <boost/mpl/not.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::source_position; + using boost::metaparse::next_char; + using boost::metaparse::start; + + typedef source_position<int11, int13, int1> sp; + typedef next_char<start, char_0> next0; + } + +BOOST_METAPARSE_TEST_CASE(source_position) +{ + using boost::metaparse::get_line; + using boost::metaparse::get_col; + using boost::metaparse::get_prev_char; + using boost::metaparse::next_line; + + using boost::mpl::equal_to; + using boost::mpl::not_equal_to; + + using boost::mpl::not_; + using boost::mpl::less; + using boost::mpl::greater; + using boost::mpl::greater_equal; + using boost::mpl::less_equal; + + // test_get_line + BOOST_MPL_ASSERT((equal_to<int11, get_line<sp>::type>)); + + // test_get_col + BOOST_MPL_ASSERT((equal_to<int13, get_col<sp>::type>)); + + // test_get_prev_char + BOOST_MPL_ASSERT((equal_to<int1, get_prev_char<sp>::type>)); + + // test_line_of_start + BOOST_MPL_ASSERT((equal_to<int1, get_line<start>::type>)); + + // test_col_of_start + BOOST_MPL_ASSERT((equal_to<int1, get_col<start>::type>)); + + // test_next_chars_char + BOOST_MPL_ASSERT((equal_to<int2, get_col<next0>::type>)); + + // test_next_chars_line + BOOST_MPL_ASSERT((equal_to<int1, get_line<next0>::type>)); + + // test_next_lines_char + BOOST_MPL_ASSERT(( + equal_to<int1, get_col<next_line<next0, char_0> >::type> + )); + + // test_next_lines_line + BOOST_MPL_ASSERT(( + equal_to<int2, get_line<next_line<start, char_0> >::type> + )); + + // test_next_chars_prev_char + BOOST_MPL_ASSERT(( + equal_to<char_1, get_prev_char< next_char<start, char_1> >::type> + )); + + // test_next_lines_prev_char + BOOST_MPL_ASSERT(( + equal_to<char_1, get_prev_char<next_line<start, char_1> >::type> + )); + + // test_equal_source_positions + BOOST_MPL_ASSERT((equal_to<sp, sp>)); + + // test_equal_source_positions_when_prev_char_is_different + BOOST_MPL_ASSERT(( + not_< + equal_to< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + >::type + > + )); + + // test_not_equal_source_positions_when_line_is_different + BOOST_MPL_ASSERT(( + not_equal_to< + source_position<int11, int13, char_a>, + source_position<int13, int13, char_a> + > + )); + + // test_not_equal_source_positions_when_col_is_different + BOOST_MPL_ASSERT(( + not_equal_to< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_is_not_less_than_itself + BOOST_MPL_ASSERT(( + not_< + less< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_earlier_in_the_same_line_is_less + BOOST_MPL_ASSERT(( + less< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_later_in_the_same_line_is_not_less + BOOST_MPL_ASSERT(( + not_< + less< + source_position<int11, int13, char_a>, + source_position<int11, int11, char_a> + >::type + > + )); + + // test_source_position_in_the_same_pos_with_less_char_is_less + BOOST_MPL_ASSERT(( + less< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + > + )); + + // test_source_position_earlier_line_is_less + BOOST_MPL_ASSERT(( + less< + source_position<int1, int28, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_later_line_is_not_less + BOOST_MPL_ASSERT(( + not_< + less< + source_position<int28, int2, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_is_greater_equal_to_itself + BOOST_MPL_ASSERT(( + greater_equal< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_earlier_in_the_same_line_is_not_greater_equal + BOOST_MPL_ASSERT(( + not_< + greater_equal< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_later_in_the_same_line_is_greater_equal + BOOST_MPL_ASSERT(( + greater_equal< + source_position<int11, int13, char_a>, + source_position<int11, int11, char_a> + > + )); + + // test_source_position_in_the_same_pos_with_less_char_is_not_greater_equal + BOOST_MPL_ASSERT(( + not_< + greater_equal< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + >::type + > + )); + + // test_source_position_earlier_line_is_not_greater_equal + BOOST_MPL_ASSERT(( + not_< + greater_equal< + source_position<int1, int28, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_later_line_is_greater_equal + BOOST_MPL_ASSERT(( + greater_equal< + source_position<int28, int2, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_is_not_greater_than_itself + BOOST_MPL_ASSERT(( + not_< + greater< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_earlier_in_the_same_line_is_not_greater + BOOST_MPL_ASSERT(( + not_< + greater< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_later_in_the_same_line_is_greater + BOOST_MPL_ASSERT(( + greater< + source_position<int11, int13, char_a>, + source_position<int11, int11, char_a> + > + )); + + // test_source_position_in_the_same_pos_with_less_char_is_not_greater + BOOST_MPL_ASSERT(( + not_< + greater< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + >::type + > + )); + + // test_source_position_earlier_line_is_not_greater + BOOST_MPL_ASSERT(( + not_< + greater< + source_position<int1, int28, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); + + // test_source_position_later_line_is_greater + BOOST_MPL_ASSERT(( + greater< + source_position<int28, int2, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_is_less_equal_to_itself + BOOST_MPL_ASSERT(( + less_equal< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_earlier_in_the_same_line_is_less_equal + BOOST_MPL_ASSERT(( + less_equal< + source_position<int11, int11, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_later_in_the_same_line_is_not_less_equal + BOOST_MPL_ASSERT(( + not_< + less_equal< + source_position<int11, int13, char_a>, + source_position<int11, int11, char_a> + >::type + > + )); + + // test_source_position_in_the_same_pos_with_less_char_is_less_equal + BOOST_MPL_ASSERT(( + less_equal< + source_position<int11, int13, char_a>, + source_position<int11, int13, char_b> + > + )); + + // test_source_position_earlier_line_is_less_equal + BOOST_MPL_ASSERT(( + less_equal< + source_position<int1, int28, char_a>, + source_position<int11, int13, char_a> + > + )); + + // test_source_position_later_line_is_not_less_equal + BOOST_MPL_ASSERT(( + not_< + less_equal< + source_position<int28, int2, char_a>, + source_position<int11, int13, char_a> + >::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/space.cpp b/src/boost/libs/metaparse/test/space.cpp new file mode 100644 index 000000000..5ae594cb2 --- /dev/null +++ b/src/boost/libs/metaparse/test/space.cpp @@ -0,0 +1,79 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/space.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::mpl::list_c; + + typedef list_c<char, '\t', 'e', 'l', 'l', 'o'> str_with_t; + typedef list_c<char, '\n', 'e', 'l', 'l', 'o'> str_with_n; + typedef list_c<char, '\r', 'e', 'l', 'l', 'o'> str_with_r; +} + +BOOST_METAPARSE_TEST_CASE(space) +{ + using boost::metaparse::is_error; + using boost::metaparse::space; + using boost::metaparse::start; + using boost::metaparse::get_result; + + using boost::mpl::apply_wrap2; + using boost::mpl::equal_to; + using boost::mpl::char_; + + // test_with_text + BOOST_MPL_ASSERT((is_error<apply_wrap2<space, str_hello, start> >)); + + // test_with_space + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<space, str__ello, start> >::type, + char_<' '> + > + )); + + // test_with_tab + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<space, str_with_t, start> >::type, + char_<'\t'> + > + )); + + // test_with_line_feed + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<space, str_with_n, start> >::type, + char_<'\n'> + > + )); + + // test_with_c_return + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<space, str_with_r, start> >::type, + char_<'\r'> + > + )); + + // test_with_empty_string + BOOST_MPL_ASSERT((is_error<apply_wrap2<space, str_, start> >)); +} + + diff --git a/src/boost/libs/metaparse/test/spaces.cpp b/src/boost/libs/metaparse/test/spaces.cpp new file mode 100644 index 000000000..1dbfe0fb3 --- /dev/null +++ b/src/boost/libs/metaparse/test/spaces.cpp @@ -0,0 +1,70 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/spaces.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/not.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::mpl::list_c; + + typedef list_c<char, 'e', 'l', 'l', 'o'> str_ello; + typedef + list_c<char, ' ', '\t', '\n', '\r', 'e', 'l', 'l', 'o'> + str_____ello; + +} + +BOOST_METAPARSE_TEST_CASE(spaces) +{ + using boost::metaparse::is_error; + using boost::metaparse::spaces; + using boost::metaparse::start; + using boost::metaparse::get_remaining; + + using boost::mpl::apply_wrap2; + using boost::mpl::not_; + using boost::mpl::equal; + + // test_reject_no_space + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<spaces, str_hello, start> > + )); + + // test_accept_one_space + BOOST_MPL_ASSERT(( + not_<is_error<apply_wrap2<spaces, str__ello, start> > > + )); + + // test_accept_only_space + BOOST_MPL_ASSERT(( + equal<get_remaining<apply_wrap2<spaces, str__ello, start> >::type, str_ello> + )); + + // test_accept_all_spaces + BOOST_MPL_ASSERT((not_<is_error<apply_wrap2<spaces, str_____ello,start> > >)); + + // test_consume_all_spaces + BOOST_MPL_ASSERT(( + equal< + get_remaining<apply_wrap2<spaces, str_____ello, start> >::type, + str_ello + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/string.cpp b/src/boost/libs/metaparse/test/string.cpp new file mode 100644 index 000000000..779946eca --- /dev/null +++ b/src/boost/libs/metaparse/test/string.cpp @@ -0,0 +1,166 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_TEST_MODULE string + +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 64 + +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal.hpp> +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/char.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/back.hpp> +#include <boost/mpl/begin_end.hpp> +#include <boost/mpl/deref.hpp> +#include <boost/mpl/advance.hpp> +#include <boost/mpl/next.hpp> +#include <boost/mpl/prior.hpp> +#include <boost/mpl/distance.hpp> +#include <boost/mpl/clear.hpp> +#include <boost/mpl/empty.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/mpl/pop_front.hpp> +#include <boost/mpl/pop_back.hpp> +#include <boost/mpl/push_front.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/string.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/test/unit_test.hpp> + +#include <string> + +BOOST_AUTO_TEST_CASE(test_string) +{ + using boost::mpl::equal; + using boost::mpl::equal_to; + using boost::mpl::char_; + using boost::mpl::int_; + using boost::mpl::at; + using boost::mpl::at_c; + using boost::mpl::size; + using boost::mpl::back; + using boost::mpl::deref; + using boost::mpl::advance; + using boost::mpl::next; + using boost::mpl::prior; + using boost::mpl::distance; + using boost::mpl::clear; + using boost::mpl::empty; + using boost::mpl::front; + using boost::mpl::is_sequence; + using boost::mpl::pop_front; + using boost::mpl::pop_back; + using boost::mpl::begin; + using boost::mpl::end; + using boost::mpl::c_str; + using boost::mpl::push_front; + using boost::mpl::push_back; + + using namespace boost; + + // string type + /////////////////////// + + typedef metaparse::string<'H','e','l','l','o'> hello; + typedef metaparse::string<> empty_string; + + typedef begin<hello>::type begin_hello; + typedef end<hello>::type end_hello; + + // test_value_of_empty_string + BOOST_REQUIRE_EQUAL(std::string(), c_str<empty_string>::type::value); + + // test_value + BOOST_REQUIRE_EQUAL(std::string("Hello"), c_str<hello>::type::value); + + // equal_to + BOOST_MPL_ASSERT((equal_to<hello, hello>)); + BOOST_MPL_ASSERT_NOT((equal_to<hello, empty_string>)); + + // at + BOOST_MPL_ASSERT((equal_to<char_<'e'>, at<hello, int_<1> >::type>)); + BOOST_MPL_ASSERT((equal_to<char_<'e'>, at_c<hello, 1>::type>)); + + // size + BOOST_MPL_ASSERT((equal_to<int_<5>, size<hello>::type>)); + + // is_sequence + BOOST_MPL_ASSERT((is_sequence<hello>)); + + // front + BOOST_MPL_ASSERT((equal_to<char_<'H'>, front<hello>::type>)); + + // push_front + BOOST_MPL_ASSERT(( + equal_to< + metaparse::string<'x','H','e','l','l','o'>, + push_front<hello, char_<'x'> >::type + > + )); + + // back + BOOST_MPL_ASSERT((equal_to<char_<'o'>, back<hello>::type>)); + + // push_back + BOOST_MPL_ASSERT(( + equal_to< + metaparse::string<'H','e','l','l','o', 'x'>, + push_back<hello, char_<'x'> >::type + > + )); + + // clear + BOOST_MPL_ASSERT((equal_to<empty_string, clear<hello>::type>)); + + // empty + BOOST_MPL_ASSERT_NOT((empty<hello>::type)); + BOOST_MPL_ASSERT((empty<empty_string>::type)); + + // string_iterator + BOOST_MPL_ASSERT((equal_to<begin_hello, begin_hello>)); + BOOST_MPL_ASSERT_NOT((equal_to<begin_hello, end_hello>)); + BOOST_MPL_ASSERT(( + equal_to<begin<empty_string>::type, end<empty_string>::type> + )); + + BOOST_MPL_ASSERT((equal_to<char_<'H'>, deref<begin_hello>::type>)); + BOOST_MPL_ASSERT((equal_to<end_hello, advance<begin_hello, int_<5> >::type>)); + BOOST_MPL_ASSERT(( + equal_to<char_<'e'>, deref<next<begin_hello>::type>::type> + )); + BOOST_MPL_ASSERT((equal_to<char_<'o'>, deref<prior<end_hello>::type>::type>)); + + BOOST_MPL_ASSERT((equal_to<int_<5>, distance<begin_hello, end_hello>::type>)); + + // pop_front + BOOST_MPL_ASSERT(( + equal_to<metaparse::string<'e','l','l','o'>, pop_front<hello>::type> + )); + + // pop_back + BOOST_MPL_ASSERT(( + equal_to<metaparse::string<'H','e','l','l'>, pop_back<hello>::type> + )); + +#if BOOST_METAPARSE_STD >= 2011 + // BOOST_METAPARSE_STRING macro + /////////////////////// + + // test_empty_string + BOOST_MPL_ASSERT((equal<BOOST_METAPARSE_STRING(""), empty_string>)); + + // test_string_creation + BOOST_MPL_ASSERT((equal<BOOST_METAPARSE_STRING("Hello"), hello>)); +#endif + +} + diff --git a/src/boost/libs/metaparse/test/string_iterator_tag.cpp b/src/boost/libs/metaparse/test/string_iterator_tag.cpp new file mode 100644 index 000000000..49b4d7587 --- /dev/null +++ b/src/boost/libs/metaparse/test/string_iterator_tag.cpp @@ -0,0 +1,23 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/impl/string_iterator_tag.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(string_iterator_tag) +{ + using boost::metaparse::v1::impl::string_iterator_tag; + + using boost::is_same; + + // test_metaprogramming_value + BOOST_MPL_ASSERT((is_same<string_iterator_tag, string_iterator_tag::type>)); +} + diff --git a/src/boost/libs/metaparse/test/string_macros.hpp b/src/boost/libs/metaparse/test/string_macros.hpp new file mode 100644 index 000000000..5f0926f3c --- /dev/null +++ b/src/boost/libs/metaparse/test/string_macros.hpp @@ -0,0 +1,82 @@ +#ifndef BOOST_METAPARSE_TEST_STRING_MACROS_HPP +#define BOOST_METAPARSE_TEST_STRING_MACROS_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifdef BOOST_METAPARSE_TEST_CHARS_10 +# error BOOST_METAPARSE_TEST_CHARS_10 already defined +#endif +#define BOOST_METAPARSE_TEST_CHARS_10 \ + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' + +#ifdef BOOST_METAPARSE_TEST_CHARS_100 +# error BOOST_METAPARSE_TEST_CHARS_100 already defined +#endif +#define BOOST_METAPARSE_TEST_CHARS_100 \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10, \ + BOOST_METAPARSE_TEST_CHARS_10 + +#ifdef BOOST_METAPARSE_TEST_CHARS_1000 +# error BOOST_METAPARSE_TEST_CHARS_1000 already defined +#endif +#define BOOST_METAPARSE_TEST_CHARS_1000 \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100, \ + BOOST_METAPARSE_TEST_CHARS_100 + + +#ifdef BOOST_METAPARSE_TEST_STRING_10 +# error BOOST_METAPARSE_TEST_STRING_10 already defined +#endif +#define BOOST_METAPARSE_TEST_STRING_10 "0123456789" + +#ifdef BOOST_METAPARSE_TEST_STRING_100 +# error BOOST_METAPARSE_TEST_STRING_100 already defined +#endif +#define BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 \ + BOOST_METAPARSE_TEST_STRING_10 + +#ifdef BOOST_METAPARSE_TEST_STRING_1000 +# error BOOST_METAPARSE_TEST_STRING_1000 already defined +#endif +#define BOOST_METAPARSE_TEST_STRING_1000 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 \ + BOOST_METAPARSE_TEST_STRING_100 + +#endif + diff --git a/src/boost/libs/metaparse/test/string_tag.cpp b/src/boost/libs/metaparse/test/string_tag.cpp new file mode 100644 index 000000000..73f44803e --- /dev/null +++ b/src/boost/libs/metaparse/test/string_tag.cpp @@ -0,0 +1,23 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/string_tag.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(string_tag) +{ + using boost::metaparse::string_tag; + + using boost::is_same; + + // test_metaprogramming_value + BOOST_MPL_ASSERT((is_same<string_tag, string_tag::type>)); +} + diff --git a/src/boost/libs/metaparse/test/swap.cpp b/src/boost/libs/metaparse/test/swap.cpp new file mode 100644 index 000000000..8c366569f --- /dev/null +++ b/src/boost/libs/metaparse/test/swap.cpp @@ -0,0 +1,52 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/v1/swap.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + struct returns_first + { + typedef returns_first type; + + template <class A, class> + struct apply + { + typedef A type; + }; + }; + + struct returns_second + { + typedef returns_second type; + + template <class, class B> + struct apply + { + typedef B type; + }; + }; +} + +BOOST_METAPARSE_TEST_CASE(swap) +{ + using boost::metaparse::v1::swap; + using boost::is_same; + + BOOST_MPL_ASSERT(( + is_same<double, swap<returns_first>::apply<int, double>::type> + )); + + BOOST_MPL_ASSERT(( + is_same<int, swap<returns_second>::apply<int, double>::type> + )); +} + diff --git a/src/boost/libs/metaparse/test/test_case.hpp b/src/boost/libs/metaparse/test/test_case.hpp new file mode 100644 index 000000000..f60db17ac --- /dev/null +++ b/src/boost/libs/metaparse/test/test_case.hpp @@ -0,0 +1,18 @@ +#ifndef BOOST_METAPARSE_TEST_TEST_CASE_HPP +#define BOOST_METAPARSE_TEST_TEST_CASE_HPP + +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/preprocessor/cat.hpp> + +#ifdef BOOST_METAPARSE_TEST_CASE +# error BOOST_METAPARSE_TEST_CASE already defined +#endif +#define BOOST_METAPARSE_TEST_CASE(name) \ + void BOOST_PP_CAT(metaparse_test_case_, name)() + +#endif + diff --git a/src/boost/libs/metaparse/test/token.cpp b/src/boost/libs/metaparse/test/token.cpp new file mode 100644 index 000000000..94ef6d7f8 --- /dev/null +++ b/src/boost/libs/metaparse/test/token.cpp @@ -0,0 +1,74 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/token.hpp> +#include <boost/metaparse/keyword.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/get_remaining.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply.hpp> +#include <boost/mpl/equal.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::keyword; + using boost::metaparse::token; + + using boost::mpl::list_c; + + typedef list_c<char, 'h', 'e', 'l', 'l', 'o', ' ', '\t'> str_hello_t; + + typedef keyword<str_hello, int13> test_parser; + typedef token<test_parser> a_test_token; +} + +BOOST_METAPARSE_TEST_CASE(token) +{ + using boost::metaparse::get_result; + using boost::metaparse::start; + using boost::metaparse::get_remaining; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + using boost::mpl::equal; + + // test_no_space + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<a_test_token, str_hello, start> >::type, + get_result<apply_wrap2<test_parser, str_hello, start> >::type + > + )); + + // test_spaces + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<a_test_token, str_hello_t, start> >::type, + get_result<apply_wrap2<test_parser, str_hello, start> >::type + > + )); + + // test_spaces_consumed + BOOST_MPL_ASSERT(( + equal< + get_remaining<apply_wrap2<a_test_token, str_hello_t, start> >::type, + str_ + > + )); + + // test_fail + BOOST_MPL_ASSERT((is_error<apply_wrap2<a_test_token, str_, start> >)); +} + + diff --git a/src/boost/libs/metaparse/test/too_long_string.cpp b/src/boost/libs/metaparse/test/too_long_string.cpp new file mode 100644 index 000000000..738d523aa --- /dev/null +++ b/src/boost/libs/metaparse/test/too_long_string.cpp @@ -0,0 +1,13 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#define BOOST_METAPARSE_LIMIT_STRING_SIZE 4 +#include <boost/metaparse/string.hpp> + +namespace +{ + typedef BOOST_METAPARSE_STRING("abcde") too_long; +} + diff --git a/src/boost/libs/metaparse/test/transform.cpp b/src/boost/libs/metaparse/test/transform.cpp new file mode 100644 index 000000000..3b21f75bc --- /dev/null +++ b/src/boost/libs/metaparse/test/transform.cpp @@ -0,0 +1,79 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2010. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/transform.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/get_result.hpp> +#include <boost/metaparse/repeated.hpp> +#include <boost/metaparse/one_char.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/always.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/front.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::metaparse::repeated; + using boost::metaparse::one_char; + + using boost::mpl::always; + + typedef always<char_x> f; + typedef repeated<one_char> repeated_one_char; + + struct get_front + { + typedef get_front type; + + template <class C> + struct apply : boost::mpl::front<C> {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(transform) +{ + using boost::metaparse::get_result; + using boost::metaparse::transform; + using boost::metaparse::start; + using boost::metaparse::is_error; + + using boost::mpl::equal_to; + using boost::mpl::apply_wrap2; + + // test_normal_case + BOOST_MPL_ASSERT(( + equal_to< + get_result<apply_wrap2<transform<lit_h, f>, str_hello, start> >::type, + char_x + > + )); + + // test_parser_fails + BOOST_MPL_ASSERT(( + is_error<apply_wrap2<transform<lit_x, f>, str_hello, start> > + )); + + // test_empty_input + BOOST_MPL_ASSERT((is_error<apply_wrap2<transform<lit_h, f>, str_, start> >)); + + // test_tranformation_functions_arg + BOOST_MPL_ASSERT(( + equal_to< + get_result< + apply_wrap2<transform<repeated_one_char, get_front>, str_hello, start> + >::type, + char_h + > + )); +} + + diff --git a/src/boost/libs/metaparse/test/transform_error.cpp b/src/boost/libs/metaparse/test/transform_error.cpp new file mode 100644 index 000000000..2a9a52c84 --- /dev/null +++ b/src/boost/libs/metaparse/test/transform_error.cpp @@ -0,0 +1,65 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/transform_error.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/reject.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/get_position.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +using boost::metaparse::reject; +using boost::metaparse::get_position; + +namespace +{ + struct new_message + { + typedef new_message type; + }; + + struct change_message + { + typedef change_message type; + + template <class E> + struct apply : reject<new_message, get_position<E> > {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(transform_error) +{ + using boost::metaparse::transform_error; + using boost::metaparse::start; + using boost::metaparse::string; + using boost::metaparse::lit_c; + + using boost::is_same; + + typedef string<'H','e','l','l','o'> s; + + // test_transform_error_does_not_change_accept + BOOST_MPL_ASSERT(( + is_same< + lit_c<'H'>::apply<s, start>::type, + transform_error<lit_c<'H'>, change_message>::apply<s, start>::type + > + )); + + // test_transform_is_called + BOOST_MPL_ASSERT(( + is_same< + reject<new_message, start>, + transform_error<lit_c<'x'>, change_message>::apply<s, start>::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/transform_error_message.cpp b/src/boost/libs/metaparse/test/transform_error_message.cpp new file mode 100644 index 000000000..23cf3def7 --- /dev/null +++ b/src/boost/libs/metaparse/test/transform_error_message.cpp @@ -0,0 +1,68 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/transform_error_message.hpp> +#include <boost/metaparse/start.hpp> +#include <boost/metaparse/string.hpp> +#include <boost/metaparse/reject.hpp> +#include <boost/metaparse/lit_c.hpp> +#include <boost/metaparse/get_position.hpp> +#include <boost/metaparse/error/literal_expected.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits.hpp> + +#include "test_case.hpp" + +using boost::metaparse::reject; +using boost::metaparse::get_position; + +namespace +{ + template <class OldMsg> + struct new_message + { + typedef new_message type; + }; + + struct change_message + { + typedef change_message type; + + template <class Msg> + struct apply : new_message<Msg> {}; + }; +} + +BOOST_METAPARSE_TEST_CASE(transform_error_message) +{ + using boost::metaparse::transform_error_message; + using boost::metaparse::start; + using boost::metaparse::string; + using boost::metaparse::lit_c; + using boost::metaparse::error::literal_expected; + + using boost::is_same; + + typedef string<'H','e','l','l','o'> s; + + // test_transform_error_message_does_not_change_accept + BOOST_MPL_ASSERT(( + is_same< + lit_c<'H'>::apply<s, start>::type, + transform_error_message<lit_c<'H'>, change_message>::apply<s, start>::type + > + )); + + // test_transform_is_called + BOOST_MPL_ASSERT(( + is_same< + reject<new_message<literal_expected<'x'> >, start>, + transform_error_message<lit_c<'x'>, change_message>::apply<s, start>::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/unless_error.cpp b/src/boost/libs/metaparse/test/unless_error.cpp new file mode 100644 index 000000000..b8315adda --- /dev/null +++ b/src/boost/libs/metaparse/test/unless_error.cpp @@ -0,0 +1,40 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/unless_error.hpp> +#include <boost/metaparse/is_error.hpp> +#include <boost/metaparse/fail.hpp> + +#include "common.hpp" + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/apply_wrap.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +namespace +{ + using boost::mpl::apply_wrap2; + using boost::metaparse::fail; + + typedef apply_wrap2<fail<int1>, int11, int2> err; +} + +BOOST_METAPARSE_TEST_CASE(util_unless_error) +{ + using boost::metaparse::is_error; + using boost::metaparse::unless_error; + + using boost::mpl::equal_to; + + // test_error + BOOST_MPL_ASSERT((is_error<unless_error<err, int13> >)); + + // test_not_error + BOOST_MPL_ASSERT((equal_to<int13, unless_error<int11, int13>::type>)); +} + + diff --git a/src/boost/libs/metaparse/test/unpaired.cpp b/src/boost/libs/metaparse/test/unpaired.cpp new file mode 100644 index 000000000..f0e4c4309 --- /dev/null +++ b/src/boost/libs/metaparse/test/unpaired.cpp @@ -0,0 +1,36 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/error/unpaired.hpp> + +#include <boost/mpl/assert.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include "test_case.hpp" + +namespace +{ + struct some_tmp_value + { + typedef some_tmp_value type; + }; +} + +BOOST_METAPARSE_TEST_CASE(unpaired) +{ + using boost::metaparse::error::unpaired; + + using boost::is_same; + + // test_unpaired_currying + BOOST_MPL_ASSERT(( + is_same< + unpaired<1, 2, some_tmp_value>, + unpaired<1, 2>::apply<some_tmp_value>::type + > + )); +} + diff --git a/src/boost/libs/metaparse/test/update_c.cpp b/src/boost/libs/metaparse/test/update_c.cpp new file mode 100644 index 000000000..94f9ab0c4 --- /dev/null +++ b/src/boost/libs/metaparse/test/update_c.cpp @@ -0,0 +1,43 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/config.hpp> +#if BOOST_METAPARSE_STD < 2011 + +#include <boost/metaparse/v1/cpp98/impl/update_c.hpp> +#include <boost/metaparse/string.hpp> + +#include <boost/mpl/equal_to.hpp> +#include <boost/mpl/assert.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(update_c) +{ + using boost::metaparse::v1::impl::update_c; + using boost::metaparse::string; + + using boost::mpl::equal_to; + + typedef string<'h','e','l','l','o'> hello; + + // test_update_first_char + BOOST_MPL_ASSERT(( + equal_to<string<'x','e','l','l','o'>, update_c<hello, 0, 'x'>::type> + )); + + // test_update_middle_char + BOOST_MPL_ASSERT(( + equal_to<string<'h','e','x','l','o'>, update_c<hello, 2, 'x'>::type> + )); + + // test_update_last_char + BOOST_MPL_ASSERT(( + equal_to<string<'h','e','l','l','x'>, update_c<hello, 4, 'x'>::type> + )); +} + +#endif + diff --git a/src/boost/libs/metaparse/test/version.cpp b/src/boost/libs/metaparse/test/version.cpp new file mode 100644 index 000000000..9eec59082 --- /dev/null +++ b/src/boost/libs/metaparse/test/version.cpp @@ -0,0 +1,20 @@ +// Copyright Abel Sinkovics (abel@sinkovics.hu) 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/metaparse/version.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/bool.hpp> + +#include "test_case.hpp" + +BOOST_METAPARSE_TEST_CASE(version) +{ + using boost::mpl::bool_; + + // test_version_number + BOOST_MPL_ASSERT((bool_<BOOST_METAPARSE_VERSION == 10000000>)); +} + |