| 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 | |
| 6 | #include <boost/spirit/include/karma_operator.hpp> |
| 7 | #include <boost/spirit/include/karma_char.hpp> |
| 8 | #include <boost/spirit/include/karma_auxiliary.hpp> |
| 9 | #include <boost/spirit/include/karma_string.hpp> |
| 10 | #include <boost/spirit/include/karma_numeric.hpp> |
| 11 | #include <boost/spirit/include/karma_nonterminal.hpp> |
| 12 | #include <boost/spirit/include/karma_action.hpp> |
| 13 | #include <boost/spirit/include/karma_directive.hpp> |
| 14 | #include <boost/phoenix/core.hpp> |
| 15 | #include <boost/phoenix/operator.hpp> |
| 16 | |
| 17 | #include "test.hpp" |
| 18 | |
| 19 | using namespace spirit_test; |
| 20 | |
| 21 | /////////////////////////////////////////////////////////////////////////////// |
| 22 | int main() |
| 23 | { |
| 24 | using namespace boost; |
| 25 | using namespace boost::spirit; |
| 26 | using namespace boost::spirit::ascii; |
| 27 | |
| 28 | typedef spirit_test::output_iterator<char>::type outiter_type; |
| 29 | |
| 30 | { |
| 31 | karma::rule<outiter_type, void(char, int, double)> start; |
| 32 | fusion::vector<char, int, double> vec('a', 10, 12.4); |
| 33 | |
| 34 | start = char_[_1 = _r1] << int_[_1 = _r2] << double_[_1 = _r3]; |
| 35 | BOOST_TEST(test("a1012.4" , start('a', 10, 12.4))); |
| 36 | |
| 37 | start = (char_ << int_ << double_)[(_1 = _r1, _2 = _r2, _3 = _r3)]; |
| 38 | BOOST_TEST(test("a1012.4" , start('a', 10, 12.4))); |
| 39 | |
| 40 | karma::rule<outiter_type, void(char)> a; |
| 41 | karma::rule<outiter_type, void(int)> b; |
| 42 | karma::rule<outiter_type, void(double)> c; |
| 43 | |
| 44 | a = char_[_1 = _r1]; |
| 45 | b = int_[_1 = _r1]; |
| 46 | c = double_[_1 = _r1]; |
| 47 | start = a(_r1) << b(_r2) << c(_r3); |
| 48 | BOOST_TEST(test("a1012.4" , start('a', 10, 12.4))); |
| 49 | } |
| 50 | |
| 51 | { |
| 52 | karma::rule<outiter_type, space_type, void(char, int, double)> start; |
| 53 | fusion::vector<char, int, double> vec('a', 10, 12.4); |
| 54 | |
| 55 | start = char_[_1 = _r1] << int_[_1 = _r2] << double_[_1 = _r3]; |
| 56 | BOOST_TEST(test_delimited("a 10 12.4 " , start('a', 10, 12.4), space)); |
| 57 | |
| 58 | start = (char_ << int_ << double_)[(_1 = _r1, _2 = _r2, _3 = _r3)]; |
| 59 | BOOST_TEST(test_delimited("a 10 12.4 " , start('a', 10, 12.4), space)); |
| 60 | |
| 61 | karma::rule<outiter_type, space_type, void(char)> a; |
| 62 | karma::rule<outiter_type, space_type, void(int)> b; |
| 63 | karma::rule<outiter_type, space_type, void(double)> c; |
| 64 | |
| 65 | a = char_[_1 = _r1]; |
| 66 | b = int_[_1 = _r1]; |
| 67 | c = double_[_1 = _r1]; |
| 68 | start = a(_r1) << b(_r2) << c(_r3); |
| 69 | BOOST_TEST(test_delimited("a 10 12.4 " , start('a', 10, 12.4), space)); |
| 70 | } |
| 71 | |
| 72 | // copy tests |
| 73 | { |
| 74 | karma::rule<outiter_type> a, b, c, start; |
| 75 | |
| 76 | a = 'a'; |
| 77 | b = int_(10); |
| 78 | c = double_(12.4); |
| 79 | |
| 80 | // The FF is the dynamic equivalent of start = a << b << c; |
| 81 | start = a; |
| 82 | start = start.copy() << b; |
| 83 | start = start.copy() << c; |
| 84 | start = start.copy(); |
| 85 | |
| 86 | BOOST_TEST(test("a1012.4" , start)); |
| 87 | } |
| 88 | |
| 89 | { |
| 90 | karma::rule<outiter_type, space_type> a, b, c, start; |
| 91 | |
| 92 | a = 'a'; |
| 93 | b = int_(10); |
| 94 | c = double_(12.4); |
| 95 | |
| 96 | // The FF is the dynamic equivalent of start = a << b << c; |
| 97 | start = a; |
| 98 | start = start.copy() << b; |
| 99 | start = start.copy() << c; |
| 100 | start = start.copy(); |
| 101 | |
| 102 | BOOST_TEST(test_delimited("a 10 12.4 " , start, space)); |
| 103 | } |
| 104 | |
| 105 | { // specifying the encoding |
| 106 | using karma::lower; |
| 107 | using karma::upper; |
| 108 | using karma::string; |
| 109 | |
| 110 | typedef boost::spirit::char_encoding::iso8859_1 iso8859_1; |
| 111 | karma::rule<outiter_type, iso8859_1> r; |
| 112 | |
| 113 | r = lower['\xE1']; |
| 114 | BOOST_TEST(test("\xE1" , r)); |
| 115 | r = lower[char_('\xC1')]; |
| 116 | BOOST_TEST(test("\xE1" , r)); |
| 117 | r = upper['\xE1']; |
| 118 | BOOST_TEST(test("\xC1" , r)); |
| 119 | r = upper[char_('\xC1')]; |
| 120 | BOOST_TEST(test("\xC1" , r)); |
| 121 | |
| 122 | r = lower["\xE1\xC1" ]; |
| 123 | BOOST_TEST(test("\xE1\xE1" , r)); |
| 124 | r = lower[lit("\xE1\xC1" )]; |
| 125 | BOOST_TEST(test("\xE1\xE1" , r)); |
| 126 | r = lower[string("\xE1\xC1" )]; |
| 127 | BOOST_TEST(test("\xE1\xE1" , r)); |
| 128 | r = upper["\xE1\xC1" ]; |
| 129 | BOOST_TEST(test("\xC1\xC1" , r)); |
| 130 | r = upper[lit("\xE1\xC1" )]; |
| 131 | BOOST_TEST(test("\xC1\xC1" , r)); |
| 132 | r = upper[string("\xE1\xC1" )]; |
| 133 | BOOST_TEST(test("\xC1\xC1" , r)); |
| 134 | } |
| 135 | |
| 136 | return boost::report_errors(); |
| 137 | } |
| 138 | |
| 139 | |