difference.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*=============================================================================
  2. Copyright (c) 2001-2010 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #include <boost/detail/lightweight_test.hpp>
  7. #include <boost/spirit/include/qi_operator.hpp>
  8. #include <boost/spirit/include/qi_char.hpp>
  9. #include <boost/spirit/include/qi_string.hpp>
  10. #include <boost/spirit/include/qi_numeric.hpp>
  11. #include <boost/spirit/include/qi_directive.hpp>
  12. #include <boost/spirit/include/qi_action.hpp>
  13. #include <boost/spirit/include/support_argument.hpp>
  14. #include <boost/spirit/include/phoenix_core.hpp>
  15. #include <boost/spirit/include/phoenix_operator.hpp>
  16. #include <string>
  17. #include <iostream>
  18. #include "test.hpp"
  19. int
  20. main()
  21. {
  22. using namespace boost::spirit::ascii;
  23. using boost::spirit::lit;
  24. using spirit_test::test;
  25. {
  26. BOOST_TEST(test("b", char_ - 'a'));
  27. BOOST_TEST(!test("a", char_ - 'a'));
  28. BOOST_TEST(test("/* abcdefghijk */", "/*" >> *(char_ - "*/") >> "*/"));
  29. }
  30. {
  31. BOOST_TEST(test("b", char_ - no_case['a']));
  32. BOOST_TEST(!test("a", char_ - no_case['a']));
  33. BOOST_TEST(!test("A", char_ - no_case['a']));
  34. BOOST_TEST(test("b", no_case[lower - 'a']));
  35. BOOST_TEST(test("B", no_case[lower - 'a']));
  36. BOOST_TEST(!test("a", no_case[lower - 'a']));
  37. BOOST_TEST(!test("A", no_case[lower - 'a']));
  38. }
  39. {
  40. // $$$ See difference.hpp why these tests are not done anymore. $$$
  41. // BOOST_TEST(test("switcher", lit("switcher") - "switch"));
  42. // BOOST_TEST(test(" switcher ", lit("switcher") - "switch", space));
  43. BOOST_TEST(!test("switch", lit("switch") - "switch"));
  44. }
  45. {
  46. using boost::spirit::_1;
  47. namespace phx = boost::phoenix;
  48. std::string s;
  49. BOOST_TEST(test(
  50. "/*abcdefghijk*/"
  51. , "/*" >> *(char_ - "*/")[phx::ref(s) += _1] >> "*/"
  52. ));
  53. BOOST_TEST(s == "abcdefghijk");
  54. s.clear();
  55. BOOST_TEST(test(
  56. " /*abcdefghijk*/"
  57. , "/*" >> *(char_ - "*/")[phx::ref(s) += _1] >> "*/"
  58. , space
  59. ));
  60. BOOST_TEST(s == "abcdefghijk");
  61. }
  62. return boost::report_errors();
  63. }