auto.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2001-2010 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. #if !defined(BOOST_SPIRIT_TEST_AUTO_HPP)
  6. #define BOOST_SPIRIT_TEST_AUTO_HPP
  7. #include <boost/config/warning_disable.hpp>
  8. #include <boost/detail/lightweight_test.hpp>
  9. #include <boost/fusion/include/std_pair.hpp>
  10. #include <boost/spirit/include/karma_bool.hpp>
  11. #include <boost/spirit/include/karma_char.hpp>
  12. #include <boost/spirit/include/karma_numeric.hpp>
  13. #include <boost/spirit/include/karma_string.hpp>
  14. #include <boost/spirit/include/karma_nonterminal.hpp>
  15. #include <boost/spirit/include/karma_operator.hpp>
  16. #include <boost/spirit/include/karma_directive.hpp>
  17. #include <boost/spirit/include/karma_auto.hpp>
  18. #include "test.hpp"
  19. namespace karma = boost::spirit::karma;
  20. namespace traits = boost::spirit::traits;
  21. ///////////////////////////////////////////////////////////////////////////////
  22. template <typename Char, typename T>
  23. bool test_create_generator(Char const *expected, T const& t)
  24. {
  25. std::basic_string<Char> generated;
  26. std::back_insert_iterator<std::basic_string<Char> > sink(generated);
  27. BOOST_TEST((traits::meta_create_exists<karma::domain, T>::value));
  28. bool result = karma::generate(sink, karma::create_generator<T>(), t);
  29. spirit_test::print_if_failed("test_create_generator", result, generated, expected);
  30. return result && generated == expected;
  31. }
  32. template <typename Char, typename T>
  33. bool test_create_generator_auto(Char const *expected, T const& t)
  34. {
  35. std::basic_string<Char> generated;
  36. std::back_insert_iterator<std::basic_string<Char> > sink(generated);
  37. BOOST_TEST((traits::meta_create_exists<karma::domain, T>::value));
  38. bool result = karma::generate(sink, t);
  39. spirit_test::print_if_failed("test_create_generator (auto)", result, generated, expected);
  40. return result && generated == expected;
  41. }
  42. template <typename Char, typename Attribute>
  43. bool test_rule(Char const *expected, Attribute const& attr)
  44. {
  45. BOOST_TEST((traits::meta_create_exists<karma::domain, Attribute>::value));
  46. typedef typename spirit_test::output_iterator<Char>::type sink_type;
  47. karma::rule<sink_type, Attribute()> r =
  48. karma::create_generator<Attribute>();
  49. return spirit_test::test(expected, r, attr);
  50. }
  51. template <typename Char, typename Attribute, typename Delimiter>
  52. bool test_rule_delimited(Char const *expected, Attribute const& attr
  53. , Delimiter const& d)
  54. {
  55. BOOST_TEST((traits::meta_create_exists<karma::domain, Attribute>::value));
  56. typedef typename spirit_test::output_iterator<Char>::type sink_type;
  57. karma::rule<sink_type, Attribute(), Delimiter> r =
  58. karma::create_generator<Attribute>();
  59. return spirit_test::test_delimited(expected, r, attr, d);
  60. }
  61. struct my_type {};
  62. #endif