duplicate.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  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. #include <boost/config/warning_disable.hpp>
  6. #include <boost/detail/lightweight_test.hpp>
  7. #include <boost/spirit/include/karma.hpp>
  8. #include <iostream>
  9. #include "test.hpp"
  10. using namespace spirit_test;
  11. int main()
  12. {
  13. using boost::spirit::karma::double_;
  14. using boost::spirit::karma::space;
  15. using boost::spirit::karma::duplicate;
  16. // test for sequences
  17. {
  18. BOOST_TEST(test("2.02.0", duplicate[double_ << double_], 2.0));
  19. BOOST_TEST(test_delimited("2.0 2.0 ",
  20. duplicate[double_ << double_], 2.0, space));
  21. BOOST_TEST(test("2.02.02.0",
  22. duplicate[double_ << double_ << double_], 2.0));
  23. BOOST_TEST(test_delimited("2.0 2.0 2.0 ",
  24. duplicate[double_ << double_ << double_], 2.0, space));
  25. }
  26. // test for non-sequences
  27. {
  28. BOOST_TEST(test("2.02.0", duplicate["2.0" << double_], 2.0));
  29. BOOST_TEST(test_delimited("2.0 2.0 ",
  30. duplicate["2.0" << double_], 2.0, space));
  31. }
  32. // test for subjects exposing no attribute
  33. {
  34. BOOST_TEST(test("2.02.0", duplicate["2.0"] << double_, 2.0));
  35. BOOST_TEST(test_delimited("2.0 2.0 ",
  36. duplicate["2.0"] << double_, 2.0, space));
  37. }
  38. // test for attribute reporting
  39. {
  40. BOOST_TEST(test("bar", (duplicate["bar"] | "foo")));
  41. BOOST_TEST(test("2.0", (duplicate[double_] | "foo"), 2.0));
  42. BOOST_TEST(test("2.02.0",
  43. (duplicate[double_ << double_] | "foo"), 2.0));
  44. }
  45. return boost::report_errors();
  46. }