alphanum.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/alphanum.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/digit.hpp>
  10. #include "common.hpp"
  11. #include <boost/mpl/equal_to.hpp>
  12. #include <boost/mpl/apply_wrap.hpp>
  13. #include <boost/mpl/assert.hpp>
  14. #include "test_case.hpp"
  15. BOOST_METAPARSE_TEST_CASE(alphanum)
  16. {
  17. using boost::metaparse::get_result;
  18. using boost::metaparse::alphanum;
  19. using boost::metaparse::start;
  20. using boost::metaparse::digit;
  21. using boost::metaparse::is_error;
  22. using boost::mpl::list_c;
  23. using boost::mpl::equal_to;
  24. using boost::mpl::apply_wrap2;
  25. typedef list_c<char, '.', '.', ','> other_string;
  26. // test_with_text
  27. BOOST_MPL_ASSERT((
  28. equal_to<get_result<apply_wrap2<alphanum, str_hello, start> >::type, char_h>
  29. ));
  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_non_alphanum
  35. BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, other_string, start> >));
  36. // test_with_empty_string
  37. BOOST_MPL_ASSERT((is_error<apply_wrap2<digit, str_, start> >));
  38. }