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