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