attr.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*=============================================================================
  2. Copyright (c) 2001-2015 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1. (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/home/x3.hpp>
  8. #include <boost/fusion/include/std_pair.hpp>
  9. #include <vector>
  10. #include "test.hpp"
  11. int main()
  12. {
  13. using spirit_test::test_attr;
  14. using boost::spirit::x3::attr;
  15. using boost::spirit::x3::int_;
  16. {
  17. int d = 0;
  18. BOOST_TEST(test_attr("", attr(1), d) && d == 1);
  19. int d1 = 1;
  20. BOOST_TEST(test_attr("", attr(d1), d) && d == 1);
  21. std::pair<int, int> p;
  22. BOOST_TEST(test_attr("1", int_ >> attr(1), p) &&
  23. p.first == 1 && p.second == 1);
  24. char c = '\0';
  25. BOOST_TEST(test_attr("", attr('a'), c) && c == 'a');
  26. // $$$ Needs some special is_convertible support, or
  27. // str ends up with an explicit null-terminator... $$$
  28. //~ std::string str;
  29. //~ BOOST_TEST(test_attr("", attr("test"), str) && str == "test");
  30. int array[] = {0, 1, 2};
  31. std::vector<int> vec;
  32. BOOST_TEST(test_attr("", attr(array), vec) && vec.size() == 3 &&
  33. vec[0] == 0 && vec[1] == 1 && vec[2] == 2);
  34. }
  35. {
  36. std::string s;
  37. BOOST_TEST(test_attr("s", "s" >> attr(std::string("123")), s) &&
  38. s == "123");
  39. }
  40. return boost::report_errors();
  41. }