digit.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/metaparse/digit.hpp>
  6. #include <boost/metaparse/is_error.hpp>
  7. #include <boost/metaparse/start.hpp>
  8. #include <boost/metaparse/get_result.hpp>
  9. #include <boost/metaparse/get_message.hpp>
  10. #include <boost/metaparse/error/digit_expected.hpp>
  11. #include "common.hpp"
  12. #include <boost/mpl/equal_to.hpp>
  13. #include <boost/mpl/apply_wrap.hpp>
  14. #include <boost/mpl/assert.hpp>
  15. #include "test_case.hpp"
  16. #include <boost/type_traits/is_same.hpp>
  17. BOOST_METAPARSE_TEST_CASE(digit)
  18. {
  19. using boost::metaparse::is_error;
  20. using boost::metaparse::digit;
  21. using boost::metaparse::start;
  22. using boost::metaparse::get_result;
  23. using boost::metaparse::get_message;
  24. using boost::metaparse::error::digit_expected;
  25. using boost::mpl::apply_wrap2;
  26. using boost::mpl::equal_to;
  27. using boost::is_same;
  28. // test_with_text
  29. BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_hello, start> >));
  30. // test_with_number
  31. BOOST_MPL_ASSERT((
  32. equal_to<get_result<apply_wrap2<digit, str_1983, start> >::type, char_1>
  33. ));
  34. // test_with_empty_string
  35. BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_, start> >));
  36. // test_error_message_with_empty_string
  37. BOOST_MPL_ASSERT((
  38. is_same<digit_expected, get_message<apply_wrap2<digit, str_, start> >::type>
  39. ));
  40. }