summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/karma/pattern1.cpp
blob: 9892bb058acbda525952035c87ed81f9dee49094 (plain)
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
//  Copyright (c) 2001-2010 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_operator.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_auxiliary.hpp>
#include <boost/spirit/include/karma_string.hpp>
#include <boost/spirit/include/karma_numeric.hpp>
#include <boost/spirit/include/karma_nonterminal.hpp>
#include <boost/spirit/include/karma_action.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>

#include "test.hpp"

using namespace spirit_test;

///////////////////////////////////////////////////////////////////////////////
int main()
{
    using namespace boost;
    using namespace boost::spirit;
    using namespace boost::spirit::ascii;

    typedef spirit_test::output_iterator<char>::type outiter_type;

    // test rule parameter propagation
    {
        using boost::phoenix::at_c;

        karma::rule<outiter_type, fusion::vector<char, int, double>()> start;
        fusion::vector<char, int, double> vec('a', 10, 12.4);

        start %= char_ << int_ << double_;
        BOOST_TEST(test("a1012.4", start, vec));

        karma::rule<outiter_type, char()> a;
        karma::rule<outiter_type, int()> b;
        karma::rule<outiter_type, double()> c;

        a %= char_ << eps;
        b %= int_;
        c %= double_;
        start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
        BOOST_TEST(test("a1012.4", start, vec));

        start = (a << b << c)[_1 = at_c<0>(_r0), _2 = at_c<1>(_r0), _3 = at_c<2>(_r0)];
        BOOST_TEST(test("a1012.4", start, vec));

        start = a << b << c;
        BOOST_TEST(test("a1012.4", start, vec));

        start %= a << b << c;
        BOOST_TEST(test("a1012.4", start, vec));
    }

    {
        using boost::phoenix::at_c;

        karma::rule<outiter_type, space_type, fusion::vector<char, int, double>()> start;
        fusion::vector<char, int, double> vec('a', 10, 12.4);

        start %= char_ << int_ << double_;
        BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));

        karma::rule<outiter_type, space_type, char()> a;
        karma::rule<outiter_type, space_type, int()> b;
        karma::rule<outiter_type, space_type, double()> c;

        a %= char_ << eps;
        b %= int_;
        c %= double_;
        start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
        BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));

        start = (a << b << c)[_1 = at_c<0>(_r0), _2 = at_c<1>(_r0), _3 = at_c<2>(_r0)];
        BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));

        start = a << b << c;
        BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));

        start %= a << b << c;
        BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));
    }

    // test direct initalization
    {
        using boost::phoenix::at_c;

        fusion::vector<char, int, double> vec('a', 10, 12.4);
        karma::rule<outiter_type, space_type, fusion::vector<char, int, double>()> 
            start = char_ << int_ << double_;;

        BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));

        karma::rule<outiter_type, space_type, char()> a = char_ << eps;
        karma::rule<outiter_type, space_type, int()> b = int_;
        karma::rule<outiter_type, space_type, double()> c = double_;

        start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
        BOOST_TEST(test_delimited("a  10 12.4 ", start, vec, space));
    }

    return boost::report_errors();
}