summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/spirit/test/karma/auto2.cpp
blob: 4527b869c333c37d373305abd1061f03e6fd40a5 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//  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 "auto.hpp"

///////////////////////////////////////////////////////////////////////////////
int main()
{
    {
        using karma::auto_;
        using karma::upper;
        using spirit_test::test;
        using spirit_test::test_delimited;

        // test primitive types
        BOOST_TEST(test("true", auto_, true));
        BOOST_TEST(test("1", auto_, 1));
        BOOST_TEST(test("1.1", auto_, 1.1));
        BOOST_TEST(test("test", auto_, "test"));
        BOOST_TEST(test(L"test", auto_, L"test"));
        BOOST_TEST(test("a", auto_, 'a'));
        BOOST_TEST(test(L"a", auto_, L'a'));

        BOOST_TEST(test("TRUE", upper[auto_], true));
        BOOST_TEST(test("TEST", upper[auto_], "test"));

        // test containers
        std::vector<int> v;
        v.push_back(0);
        v.push_back(1);
        v.push_back(2);
        BOOST_TEST(test("012", auto_, v));
        BOOST_TEST(test("0,1,2", auto_ % ',', v));
        BOOST_TEST(test_delimited("0,1,2,", auto_, v, ','));

        std::list<int> l;
        l.push_back(0);
        l.push_back(1);
        l.push_back(2);
        BOOST_TEST(test("012", auto_, l));
        BOOST_TEST(test("0,1,2", auto_ % ',', l));
        BOOST_TEST(test_delimited("0,1,2,", auto_, l, ','));

        // test optional
        boost::optional<int> o;
        BOOST_TEST(test("", auto_, o));
        o = 1;
        BOOST_TEST(test("1", auto_, o));

        // test alternative
        boost::variant<int, double, float, std::string> vv;
        vv = 1;
        BOOST_TEST(test("1", auto_, vv));
        vv = 1.0;
        BOOST_TEST(test("1.0", auto_, vv));
        vv = 1.0f;
        BOOST_TEST(test("1.0", auto_, vv));
        vv = "some string";
        BOOST_TEST(test("some string", auto_, vv));

        // test fusion sequence
        std::pair<int, double> p (1, 2.0);
        BOOST_TEST(test("12.0", auto_, p));
        BOOST_TEST(test_delimited("1,2.0,", auto_, p, ','));
    }

    {
        using karma::auto_;
        using karma::upper;
        using spirit_test::test;
        using spirit_test::test_delimited;

        // test primitive types
        BOOST_TEST(test("true", auto_(true)));
        BOOST_TEST(test("1", auto_(1)));
        BOOST_TEST(test("1.1", auto_(1.1)));
        BOOST_TEST(test("test", auto_("test")));
        BOOST_TEST(test(L"test", auto_(L"test")));
        BOOST_TEST(test("a", auto_('a')));
        BOOST_TEST(test(L"a", auto_(L'a')));

        BOOST_TEST(test("TRUE", upper[auto_(true)]));
        BOOST_TEST(test("TEST", upper[auto_("test")]));

        // test containers
        std::vector<int> v;
        v.push_back(0);
        v.push_back(1);
        v.push_back(2);
        BOOST_TEST(test("012", auto_(v)));
        BOOST_TEST(test_delimited("0,1,2,", auto_(v), ','));

        std::list<int> l;
        l.push_back(0);
        l.push_back(1);
        l.push_back(2);
        BOOST_TEST(test("012", auto_(l)));
        BOOST_TEST(test_delimited("0,1,2,", auto_(l), ','));

        // test optional
        boost::optional<int> o;
        BOOST_TEST(test("", auto_(o)));
        o = 1;
        BOOST_TEST(test("1", auto_(o)));

        // test alternative
        boost::variant<int, double, float, std::string> vv;
        vv = 1;
        BOOST_TEST(test("1", auto_(vv)));
        vv = 1.0;
        BOOST_TEST(test("1.0", auto_(vv)));
        vv = 1.0f;
        BOOST_TEST(test("1.0", auto_(vv)));
        vv = "some string";
        BOOST_TEST(test("some string", auto_(vv)));

        // test fusion sequence
        std::pair<int, double> p (1, 2.0);
        BOOST_TEST(test("12.0", auto_, p));
        BOOST_TEST(test_delimited("1,2.0,", auto_(p), ','));
    }

    return boost::report_errors();
}