summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/qi/lit1.cpp
blob: 6f8eaf089f870661d528ae514f7ba2977fe8ce09 (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
/*=============================================================================
    Copyright (c) 2001-2011 Joel de Guzman
    http://spirit.sourceforge.net/

    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/detail/workaround.hpp>
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>

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

int
main()
{
    using spirit_test::test;
    using spirit_test::test_attr;
    using boost::spirit::qi::string;
    using boost::spirit::qi::_1;

    {
        BOOST_TEST((test("kimpo", "kimpo")));
        BOOST_TEST((test("kimpo", string("kimpo"))));

        BOOST_TEST((test("x", string("x"))));
        BOOST_TEST((test(L"x", string(L"x"))));

        std::basic_string<char> s("kimpo");
        std::basic_string<wchar_t> ws(L"kimpo");
        BOOST_TEST((test("kimpo", s)));
        BOOST_TEST((test(L"kimpo", ws)));
        BOOST_TEST((test("kimpo", string(s))));
        BOOST_TEST((test(L"kimpo", string(ws))));
    }

    {
        BOOST_TEST((test(L"kimpo", L"kimpo")));
        BOOST_TEST((test(L"kimpo", string(L"kimpo"))));
        BOOST_TEST((test(L"x", string(L"x"))));
    }

    {
        std::basic_string<char> s("kimpo");
        BOOST_TEST((test("kimpo", string(s))));

        std::basic_string<wchar_t> ws(L"kimpo");
        BOOST_TEST((test(L"kimpo", string(ws))));
    }

    {
        using namespace boost::spirit::ascii;
        BOOST_TEST((test("    kimpo", string("kimpo"), space)));
        BOOST_TEST((test(L"    kimpo", string(L"kimpo"), space)));
        BOOST_TEST((test("    x", string("x"), space)));
    }

    {
        using namespace boost::spirit::ascii;
        BOOST_TEST((test("    kimpo", string("kimpo"), space)));
        BOOST_TEST((test(L"    kimpo", string(L"kimpo"), space)));
        BOOST_TEST((test("    x", string("x"), space)));
    }

    {
        using namespace boost::spirit::ascii;
        std::string s;
        BOOST_TEST((test_attr("kimpo", string("kimpo"), s)));
        BOOST_TEST(s == "kimpo");
        s.clear();
        BOOST_TEST((test_attr(L"kimpo", string(L"kimpo"), s)));
        BOOST_TEST(s == "kimpo");
        s.clear();
        BOOST_TEST((test_attr("x", string("x"), s)));
        BOOST_TEST(s == "x");
    }

    {   // lazy string

        using namespace boost::spirit::ascii;
        namespace phx = boost::phoenix;

        BOOST_TEST((test("x", string(phx::val("x")))));

        std::string str; // make sure lazy lits have an attribute
        BOOST_TEST(test("x", string(phx::val("x"))[phx::ref(str) = _1]));
        BOOST_TEST(str == "x");
    }

    return boost::report_errors();
}