int_.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
  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/int_.hpp>
  6. #include <boost/metaparse/is_error.hpp>
  7. #include <boost/metaparse/start.hpp>
  8. #include <boost/metaparse/get_result.hpp>
  9. #include "common.hpp"
  10. #include <boost/mpl/equal_to.hpp>
  11. #include <boost/mpl/apply_wrap.hpp>
  12. #include <boost/mpl/assert.hpp>
  13. #include "test_case.hpp"
  14. BOOST_METAPARSE_TEST_CASE(int)
  15. {
  16. using boost::metaparse::is_error;
  17. using boost::metaparse::int_;
  18. using boost::metaparse::start;
  19. using boost::metaparse::get_result;
  20. using boost::mpl::apply_wrap2;
  21. using boost::mpl::equal_to;
  22. // test_with_text
  23. BOOST_MPL_ASSERT((is_error<apply_wrap2<int_, str_hello, start> >));
  24. // test_with_zero
  25. BOOST_MPL_ASSERT((
  26. equal_to<get_result<apply_wrap2<int_, str_0, start> >::type, int0>
  27. ));
  28. // test_with_one_digit
  29. BOOST_MPL_ASSERT((
  30. equal_to<get_result<apply_wrap2<int_, str_1, start> >::type, int1>
  31. ));
  32. // test_with_big_number
  33. BOOST_MPL_ASSERT((
  34. equal_to<
  35. get_result<apply_wrap2<int_, str_1983, start> >::type,
  36. boost::mpl::int_<1983>
  37. >
  38. ));
  39. // test_with_empty_string
  40. BOOST_MPL_ASSERT((is_error<apply_wrap2<int_, str_, start> >));
  41. }