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 <string>
8#include <vector>
9
10#include<boost/spirit/include/karma.hpp>
11
12#include <boost/core/lightweight_test.hpp>
13
14int main()
15{
16 namespace karma = boost::spirit::karma;
17
18 int num[] = {0, 1, 2, 3, 4, 5};
19 std::vector<int> contents(num, num + sizeof(num) / sizeof(int));
20
21 {
22 std::string result;
23 BOOST_TEST(karma::generate(std::back_inserter(result),
24 *karma::center[karma::int_], contents));
25 BOOST_TEST(result == " 0 1 2 3 4 5 ");
26 }
27
28 {
29 std::string result;
30 BOOST_TEST(karma::generate(std::back_inserter(result),
31 *karma::center(5)[karma::int_], contents));
32 BOOST_TEST(result == " 0 1 2 3 4 5 ");
33 }
34
35 {
36 std::string result;
37 BOOST_TEST(karma::generate(std::back_inserter(result),
38 *karma::center("_")[karma::int_], contents));
39 BOOST_TEST(result == "_____0_________1_________2_________3_________4_________5____");
40 }
41
42 {
43 std::string result;
44 BOOST_TEST(karma::generate(std::back_inserter(result),
45 *karma::center(5, "_")[karma::int_], contents));
46 BOOST_TEST(result == "__0____1____2____3____4____5__");
47 }
48
49 {
50 std::string result;
51 BOOST_TEST(karma::generate(std::back_inserter(result),
52 *karma::center(karma::char_("_"))[karma::int_], contents));
53 BOOST_TEST(result == "_____0_________1_________2_________3_________4_________5____");
54 }
55
56 {
57 std::string result;
58 BOOST_TEST(karma::generate(std::back_inserter(result),
59 *karma::center(5, karma::char_("_"))[karma::int_], contents));
60 BOOST_TEST(result == "__0____1____2____3____4____5__");
61 }
62
63 return boost::report_errors();
64}
65
66

source code of boost/libs/spirit/test/karma/regression_center_alignment.cpp