1 // Copyright (c) 2001-2012 Hartmut Kaiser
2 // Copyright (c) 2012 yyyy yyyy <typhoonking77@hotmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #include <boost/config/warning_disable.hpp>
8 #include <boost/detail/lightweight_test.hpp>
9
10 #include <string>
11 #include <vector>
12
13 #include<boost/spirit/include/karma.hpp>
14
main()15 int main()
16 {
17 namespace karma = boost::spirit::karma;
18
19 int num[] = {0, 1, 2, 3, 4, 5};
20 std::vector<int> contents(num, num + sizeof(num) / sizeof(int));
21
22 {
23 std::string result;
24 BOOST_TEST(karma::generate(std::back_inserter(result),
25 *karma::center[karma::int_], contents));
26 BOOST_TEST(result == " 0 1 2 3 4 5 ");
27 }
28
29 {
30 std::string result;
31 BOOST_TEST(karma::generate(std::back_inserter(result),
32 *karma::center(5)[karma::int_], contents));
33 BOOST_TEST(result == " 0 1 2 3 4 5 ");
34 }
35
36 {
37 std::string result;
38 BOOST_TEST(karma::generate(std::back_inserter(result),
39 *karma::center("_")[karma::int_], contents));
40 BOOST_TEST(result == "_____0_________1_________2_________3_________4_________5____");
41 }
42
43 {
44 std::string result;
45 BOOST_TEST(karma::generate(std::back_inserter(result),
46 *karma::center(5, "_")[karma::int_], contents));
47 BOOST_TEST(result == "__0____1____2____3____4____5__");
48 }
49
50 {
51 std::string result;
52 BOOST_TEST(karma::generate(std::back_inserter(result),
53 *karma::center(karma::char_("_"))[karma::int_], contents));
54 BOOST_TEST(result == "_____0_________1_________2_________3_________4_________5____");
55 }
56
57 {
58 std::string result;
59 BOOST_TEST(karma::generate(std::back_inserter(result),
60 *karma::center(5, karma::char_("_"))[karma::int_], contents));
61 BOOST_TEST(result == "__0____1____2____3____4____5__");
62 }
63
64 return boost::report_errors();
65 }
66
67