• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  Copyright (c) 2001-2011 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 <boost/config/warning_disable.hpp>
7 #include <boost/detail/lightweight_test.hpp>
8 
9 #include <boost/spirit/include/karma_char.hpp>
10 #include <boost/spirit/include/karma_generate.hpp>
11 #include <boost/spirit/include/karma_numeric.hpp>
12 #include <boost/spirit/include/karma_directive.hpp>
13 
14 #include <boost/spirit/include/karma_nonterminal.hpp>
15 #include <boost/spirit/include/karma_action.hpp>
16 
17 #include <boost/spirit/include/phoenix_core.hpp>
18 
19 #include "test.hpp"
20 
21 using namespace spirit_test;
22 namespace karma = boost::spirit::karma;
23 
24 ///////////////////////////////////////////////////////////////////////////////
25 int
main()26 main()
27 {
28     {
29         using karma::columns;
30         using karma::int_;
31 
32         std::vector<int> v;
33         for (int i = 0; i < 11; ++i)
34             v.push_back(i);
35 
36         BOOST_TEST(test("01234\n56789\n10\n", columns[*int_], v));
37         BOOST_TEST(test_delimited("0 1 2 3 4 \n5 6 7 8 9 \n10 \n", columns[*int_]
38           , v, karma::space));
39     }
40 
41     {
42         using karma::columns;
43         using karma::int_;
44 
45         std::vector<int> v;
46         for (int i = 0; i < 11; ++i)
47             v.push_back(i);
48 
49         BOOST_TEST(test("012\n345\n678\n910\n", columns(3)[*int_], v));
50         BOOST_TEST(test_delimited("0 1 2 \n3 4 5 \n6 7 8 \n9 10 \n"
51           , columns(3)[*int_], v, karma::space));
52     }
53 
54     {
55         using karma::columns;
56         using karma::int_;
57         using boost::phoenix::ref;
58 
59         std::vector<int> v;
60         for (int i = 0; i < 11; ++i)
61             v.push_back(i);
62 
63         int count = 3;
64         BOOST_TEST(test("012\n345\n678\n910\n", columns(ref(count))[*int_], v));
65         BOOST_TEST(test_delimited("0 1 2 \n3 4 5 \n6 7 8 \n9 10 \n"
66           , columns(val(ref(count)))[*int_], v, karma::space));
67     }
68 
69     {
70         using karma::columns;
71         using karma::int_;
72         using karma::lit;
73 
74         std::vector<int> v;
75         for (int i = 0; i < 11; ++i)
76             v.push_back(i);
77 
78         BOOST_TEST(test("01234\t56789\t10\t", columns(lit('\t'))[*int_], v));
79         BOOST_TEST(test_delimited("0 1 2 3 4 \t5 6 7 8 9 \t10 \t"
80           , columns(lit('\t'))[*int_], v, karma::space));
81     }
82 
83     {
84         using karma::columns;
85         using karma::int_;
86         using karma::lit;
87 
88         std::vector<int> v;
89         for (int i = 0; i < 11; ++i)
90             v.push_back(i);
91 
92         BOOST_TEST(test("012\t345\t678\t910\t", columns(3, lit('\t'))[*int_], v));
93         BOOST_TEST(test_delimited("0 1 2 \t3 4 5 \t6 7 8 \t9 10 \t"
94           , columns(3, lit('\t'))[*int_], v, karma::space));
95     }
96     return boost::report_errors();
97 }
98