summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/qi/attr.cpp
blob: 319c9a70e21198bf9d58159c59cc9351d7ca2eb7 (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
/*=============================================================================
    Copyright (c) 2001-2011 Hartmut Kaiser
    Copyright (c) 2001-2011 Joel de Guzman

    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/include/qi_char.hpp>
#include <boost/spirit/include/qi_auxiliary.hpp>
#include <boost/spirit/include/qi_numeric.hpp>
#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/fusion/include/std_pair.hpp>

#include <iostream>
#include "test.hpp"

int
main()
{
    using spirit_test::test_attr;
    namespace qi = boost::spirit::qi;

    using qi::attr;
    using qi::double_;

    {
        double d = 0.0;
        BOOST_TEST(test_attr("", attr(1.0), d) && d == 1.0);

        double d1 = 1.0;
        BOOST_TEST(test_attr("", attr(d1), d) && d == 1.0);

        std::pair<double, double> p;
        BOOST_TEST(test_attr("1.0", double_ >> attr(1.0), p) && 
            p.first == 1.0 && p.second == 1.0);

        char c = '\0';
        BOOST_TEST(test_attr("", attr('a'), c) && c == 'a');
        std::string str;
        BOOST_TEST(test_attr("", attr("test"), str) && str == "test");
    }

    {   // testing lazy constructs
        using boost::phoenix::val;
        using boost::phoenix::ref;

        double d = 0.0;
        BOOST_TEST(test_attr("", attr(val(1.0)), d) && d == 1.0);

        double d1 = 2.0;
        BOOST_TEST(test_attr("", attr(ref(d1)), d) && d == 2.0);
    }

    {
        std::string s;
        BOOST_TEST(test_attr("s", "s" >> qi::attr(std::string("123")), s) && 
            s == "123");
    }

    return boost::report_errors();
}