]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/test/karma/sequence1.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / sequence1.cpp
CommitLineData
7c673cae
FG
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
1e59de90 6#include <boost/spirit/include/karma_sequence.hpp>
7c673cae
FG
7
8#include <boost/spirit/include/karma_char.hpp>
9#include <boost/spirit/include/karma_string.hpp>
10#include <boost/spirit/include/karma_numeric.hpp>
11#include <boost/spirit/include/karma_generate.hpp>
12#include <boost/spirit/include/karma_operator.hpp>
13#include <boost/spirit/include/karma_directive.hpp>
14#include <boost/spirit/include/karma_action.hpp>
15#include <boost/spirit/include/karma_nonterminal.hpp>
16#include <boost/spirit/include/karma_auxiliary.hpp>
17#include <boost/spirit/include/karma_directive.hpp>
18#include <boost/spirit/include/support_unused.hpp>
7c673cae
FG
19#include <boost/fusion/include/vector.hpp>
20
21#include "test.hpp"
22
23using namespace spirit_test;
24
25///////////////////////////////////////////////////////////////////////////////
26int main()
27{
28 using namespace boost::spirit;
29 using namespace boost::spirit::ascii;
30 namespace fusion = boost::fusion;
31
32 {
33 BOOST_TEST(test("xi", char_('x') << char_('i')));
34 BOOST_TEST(!test("xi", char_('x') << char_('o')));
35 }
36
37 {
38 BOOST_TEST(test_delimited("x i ", char_('x') << 'i', char(' ')));
39 BOOST_TEST(!test_delimited("x i ",
40 char_('x') << char_('o'), char(' ')));
41 }
42
43 {
44 BOOST_TEST(test_delimited("Hello , World ",
45 lit("Hello") << ',' << "World", char(' ')));
46 }
47
48 {
49 // a single element
50 char attr = 'a';
51 BOOST_TEST((test("ab", char_ << 'b', attr)));
52 }
53
54 {
55 // a single element fusion sequence
56 fusion::vector<char> attr('a');
57 BOOST_TEST((test("ab", char_ << 'b', attr)));
58 }
59
60 {
61 fusion::vector<char, char, std::string> p ('a', 'b', "cdefg");
62 BOOST_TEST(test("abcdefg", char_ << char_ << string, p));
63 BOOST_TEST(test_delimited("a b cdefg ",
64 char_ << char_ << string, p, char(' ')));
65 }
66
67 {
68 fusion::vector<char, int, char> p ('a', 12, 'c');
69 BOOST_TEST(test("a12c", char_ << int_ << char_, p));
70 BOOST_TEST(test_delimited("a 12 c ",
71 char_ << int_ << char_, p, char(' ')));
72 }
73
74 {
75 // element sequence can be shorter and longer than the attribute
76 // sequence
77 using boost::spirit::karma::strict;
78 using boost::spirit::karma::relaxed;
79
80 fusion::vector<char, int, char> p ('a', 12, 'c');
81 BOOST_TEST(test("a12", char_ << int_, p));
82 BOOST_TEST(test_delimited("a 12 ", char_ << int_, p, char(' ')));
83
84 BOOST_TEST(test("a12", relaxed[char_ << int_], p));
85 BOOST_TEST(test_delimited("a 12 ", relaxed[char_ << int_], p, char(' ')));
86
87 BOOST_TEST(!test("", strict[char_ << int_], p));
88 BOOST_TEST(!test_delimited("", strict[char_ << int_], p, char(' ')));
89
90 fusion::vector<char, int> p1 ('a', 12);
91 BOOST_TEST(test("a12c", char_ << int_ << char_('c'), p1));
92 BOOST_TEST(test_delimited("a 12 c ", char_ << int_ << char_('c'),
93 p1, char(' ')));
94
95 BOOST_TEST(test("a12c", relaxed[char_ << int_ << char_('c')], p1));
96 BOOST_TEST(test_delimited("a 12 c ",
97 relaxed[char_ << int_ << char_('c')], p1, char(' ')));
98
99 BOOST_TEST(!test("", strict[char_ << int_ << char_('c')], p1));
100 BOOST_TEST(!test_delimited("", strict[char_ << int_ << char_('c')],
101 p1, char(' ')));
102
103 BOOST_TEST(test("a12", strict[char_ << int_], p1));
104 BOOST_TEST(test_delimited("a 12 ", strict[char_ << int_], p1, char(' ')));
105
106 std::string value("foo ' bar");
107 BOOST_TEST(test("\"foo ' bar\"", '"' << strict[*(~char_('*'))] << '"', value));
108 BOOST_TEST(test("\"foo ' bar\"", strict['"' << *(~char_('*')) << '"'], value));
109 }
110
111 {
112 // if all elements of a sequence have unused parameters, the whole
113 // sequence has an unused parameter as well
114 fusion::vector<char, char> p ('a', 'e');
115 BOOST_TEST(test("abcde",
116 char_ << (lit('b') << 'c' << 'd') << char_, p));
117 BOOST_TEST(test_delimited("a b c d e ",
118 char_ << (lit('b') << 'c' << 'd') << char_, p, char(' ')));
119 }
120
121 {
122 // literal generators do not need an attribute
123 fusion::vector<char, char> p('a', 'c');
124 BOOST_TEST(test("abc", char_ << 'b' << char_, p));
125 BOOST_TEST(test_delimited("a b c ",
126 char_ << 'b' << char_, p, char(' ')));
127 }
128
129 {
130 // literal generators do not need an attribute, not even at the end
131 fusion::vector<char, char> p('a', 'c');
132 BOOST_TEST(test("acb", char_ << char_ << 'b', p));
133 BOOST_TEST(test_delimited("a c b ",
134 char_ << char_ << 'b', p, char(' ')));
135 }
136
137 return boost::report_errors();
138}
139