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
|
/*=============================================================================
Copyright (c) 2009 Chris Hoeppler
Copyright (c) 2014 Lee Clagett
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/detail/lightweight_test.hpp>
#include <boost/spirit/home/x3/char.hpp>
#include <boost/spirit/home/x3/core.hpp>
#include <boost/spirit/home/x3/numeric.hpp>
#include <boost/spirit/home/x3/operator.hpp>
#include <boost/spirit/home/x3/string.hpp>
#include <boost/spirit/home/x3/directive/confix.hpp>
#include "test.hpp"
int main()
{
namespace x3 = boost::spirit::x3;
using namespace spirit_test;
{
const auto comment = x3::confix("/*", "*/");
BOOST_TEST(test_failure("/abcdef*/", comment["abcdef"]));
BOOST_TEST(test_failure("/* abcdef*/", comment["abcdef"]));
BOOST_TEST(test_failure("/*abcdef */", comment["abcdef"]));
BOOST_TEST(test("/*abcdef*/", comment["abcdef"]));
{
unsigned value = 0;
BOOST_TEST(
test_attr(" /* 123 */ ", comment[x3::uint_], value, x3::space));
BOOST_TEST(value == 123);
using x3::_attr;
value = 0;
const auto lambda = [&value](auto& ctx ){ value = _attr(ctx) + 1; };
BOOST_TEST(test_attr("/*123*/", comment[x3::uint_][lambda], value));
BOOST_TEST(value == 124);
}
}
{
const auto array = x3::confix('[', ']');
{
std::vector<unsigned> values;
BOOST_TEST(test("[0,2,4,6,8]", array[x3::uint_ % ',']));
BOOST_TEST(test_attr("[0,2,4,6,8]", array[x3::uint_ % ','], values));
BOOST_TEST(
values.size() == 5 &&
values[0] == 0 &&
values[1] == 2 &&
values[2] == 4 &&
values[3] == 6 &&
values[4] == 8);
}
{
std::vector<std::vector<unsigned>> values;
BOOST_TEST(
test("[[1,3,5],[0,2,4]]", array[array[x3::uint_ % ','] % ',']));
BOOST_TEST(
test_attr(
"[[1,3,5],[0,2,4]]",
array[array[x3::uint_ % ','] % ','],
values));
BOOST_TEST(
values.size() == 2 &&
values[0].size() == 3 &&
values[0][0] == 1 &&
values[0][1] == 3 &&
values[0][2] == 5 &&
values[1].size() == 3 &&
values[1][0] == 0 &&
values[1][1] == 2 &&
values[1][2] == 4);
}
}
return boost::report_errors();
}
|