1 //  Copyright (c) 2001-2010 Hartmut Kaiser
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include "auto.hpp"
7 
8 ///////////////////////////////////////////////////////////////////////////////
main()9 int main()
10 {
11     {
12         using karma::auto_;
13         using karma::upper;
14         using spirit_test::test;
15         using spirit_test::test_delimited;
16 
17         // test primitive types
18         BOOST_TEST(test("true", auto_, true));
19         BOOST_TEST(test("1", auto_, 1));
20         BOOST_TEST(test("1.1", auto_, 1.1));
21         BOOST_TEST(test("test", auto_, "test"));
22         BOOST_TEST(test(L"test", auto_, L"test"));
23         BOOST_TEST(test("a", auto_, 'a'));
24         BOOST_TEST(test(L"a", auto_, L'a'));
25 
26         BOOST_TEST(test("TRUE", upper[auto_], true));
27         BOOST_TEST(test("TEST", upper[auto_], "test"));
28 
29         // test containers
30         std::vector<int> v;
31         v.push_back(0);
32         v.push_back(1);
33         v.push_back(2);
34         BOOST_TEST(test("012", auto_, v));
35         BOOST_TEST(test("0,1,2", auto_ % ',', v));
36         BOOST_TEST(test_delimited("0,1,2,", auto_, v, ','));
37 
38         std::list<int> l;
39         l.push_back(0);
40         l.push_back(1);
41         l.push_back(2);
42         BOOST_TEST(test("012", auto_, l));
43         BOOST_TEST(test("0,1,2", auto_ % ',', l));
44         BOOST_TEST(test_delimited("0,1,2,", auto_, l, ','));
45 
46         // test optional
47         boost::optional<int> o;
48         BOOST_TEST(test("", auto_, o));
49         o = 1;
50         BOOST_TEST(test("1", auto_, o));
51 
52         // test alternative
53         boost::variant<int, double, float, std::string> vv;
54         vv = 1;
55         BOOST_TEST(test("1", auto_, vv));
56         vv = 1.0;
57         BOOST_TEST(test("1.0", auto_, vv));
58         vv = 1.0f;
59         BOOST_TEST(test("1.0", auto_, vv));
60         vv = "some string";
61         BOOST_TEST(test("some string", auto_, vv));
62 
63         // test fusion sequence
64         std::pair<int, double> p (1, 2.0);
65         BOOST_TEST(test("12.0", auto_, p));
66         BOOST_TEST(test_delimited("1,2.0,", auto_, p, ','));
67     }
68 
69     {
70         using karma::auto_;
71         using karma::upper;
72         using spirit_test::test;
73         using spirit_test::test_delimited;
74 
75         // test primitive types
76         BOOST_TEST(test("true", auto_(true)));
77         BOOST_TEST(test("1", auto_(1)));
78         BOOST_TEST(test("1.1", auto_(1.1)));
79         BOOST_TEST(test("test", auto_("test")));
80         BOOST_TEST(test(L"test", auto_(L"test")));
81         BOOST_TEST(test("a", auto_('a')));
82         BOOST_TEST(test(L"a", auto_(L'a')));
83 
84         BOOST_TEST(test("TRUE", upper[auto_(true)]));
85         BOOST_TEST(test("TEST", upper[auto_("test")]));
86 
87         // test containers
88         std::vector<int> v;
89         v.push_back(0);
90         v.push_back(1);
91         v.push_back(2);
92         BOOST_TEST(test("012", auto_(v)));
93         BOOST_TEST(test_delimited("0,1,2,", auto_(v), ','));
94 
95         std::list<int> l;
96         l.push_back(0);
97         l.push_back(1);
98         l.push_back(2);
99         BOOST_TEST(test("012", auto_(l)));
100         BOOST_TEST(test_delimited("0,1,2,", auto_(l), ','));
101 
102         // test optional
103         boost::optional<int> o;
104         BOOST_TEST(test("", auto_(o)));
105         o = 1;
106         BOOST_TEST(test("1", auto_(o)));
107 
108         // test alternative
109         boost::variant<int, double, float, std::string> vv;
110         vv = 1;
111         BOOST_TEST(test("1", auto_(vv)));
112         vv = 1.0;
113         BOOST_TEST(test("1.0", auto_(vv)));
114         vv = 1.0f;
115         BOOST_TEST(test("1.0", auto_(vv)));
116         vv = "some string";
117         BOOST_TEST(test("some string", auto_(vv)));
118 
119         // test fusion sequence
120         std::pair<int, double> p (1, 2.0);
121         BOOST_TEST(test("12.0", auto_, p));
122         BOOST_TEST(test_delimited("1,2.0,", auto_(p), ','));
123     }
124 
125     return boost::report_errors();
126 }
127