exception_tests.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*=============================================================================
  2. Copyright (c) 1998-2003 Joel de Guzman
  3. http://spirit.sourceforge.net/
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #include <boost/spirit/include/classic_core.hpp>
  9. #include <boost/spirit/include/classic_exceptions.hpp>
  10. #include <iostream>
  11. #include <boost/detail/lightweight_test.hpp>
  12. using namespace std;
  13. using namespace BOOST_SPIRIT_CLASSIC_NS;
  14. struct handler
  15. {
  16. template <typename ScannerT, typename ErrorT>
  17. error_status<>
  18. operator()(ScannerT const& /*scan*/, ErrorT const& /*error*/) const
  19. {
  20. cout << "exception caught...Test concluded successfully" << endl;
  21. return error_status<>(error_status<>::fail);
  22. }
  23. };
  24. int
  25. main()
  26. {
  27. cout << "/////////////////////////////////////////////////////////\n\n";
  28. cout << "\t\tExceptions Test...\n\n";
  29. cout << "/////////////////////////////////////////////////////////\n\n";
  30. assertion<int> expect(0);
  31. guard<int> my_guard;
  32. bool r =
  33. parse("abcx",
  34. my_guard(ch_p('a') >> 'b' >> 'c' >> expect( ch_p('d') ))
  35. [
  36. handler()
  37. ]
  38. ).full;
  39. BOOST_TEST(!r);
  40. return boost::report_errors();
  41. }