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_string.hpp>
11 #include <boost/spirit/include/karma_numeric.hpp>
12 #include <boost/spirit/include/karma_generate.hpp>
13 #include <boost/spirit/include/karma_directive.hpp>
14 
15 #include "test.hpp"
16 
17 using namespace spirit_test;
18 
19 ///////////////////////////////////////////////////////////////////////////////
20 int
main()21 main()
22 {
23     using namespace boost::spirit;
24     using namespace boost::spirit::ascii;
25 
26     {
27         BOOST_TEST(test("0123456789", maxwidth[lit("0123456789")]));
28         BOOST_TEST(test("012345678", maxwidth[lit("012345678")]));
29         BOOST_TEST(test("0123456789", maxwidth[lit("01234567890")]));
30 
31         BOOST_TEST(test("0123456789", maxwidth[string], "0123456789"));
32         BOOST_TEST(test("012345678", maxwidth[string], "012345678"));
33         BOOST_TEST(test("0123456789", maxwidth[string], "01234567890"));
34     }
35 
36     {
37         BOOST_TEST(test("01234567", maxwidth(8)[lit("01234567")]));
38         BOOST_TEST(test("0123456", maxwidth(8)[lit("0123456")]));
39         BOOST_TEST(test("01234567", maxwidth(8)[lit("012345678")]));
40 
41         BOOST_TEST(test("01234567", maxwidth(8)[string], "01234567"));
42         BOOST_TEST(test("0123456", maxwidth(8)[string], "0123456"));
43         BOOST_TEST(test("01234567", maxwidth(8)[string], "012345678"));
44     }
45 
46     {
47         std::string str;
48         BOOST_TEST(test("01234567",
49             maxwidth(8, std::back_inserter(str))[lit("01234567")]) &&
50             str.empty());
51 
52         str = "";
53         BOOST_TEST(test("0123456",
54             maxwidth(8, std::back_inserter(str))[lit("0123456")]) &&
55             str.empty());
56 
57         str = "";
58         BOOST_TEST(test("01234567",
59             maxwidth(8, std::back_inserter(str))[lit("012345678")]) &&
60             str == "8");
61     }
62 
63     {
64         using namespace boost::phoenix;
65 
66         BOOST_TEST(test("01234567", maxwidth(val(8))[lit("01234567")]));
67         BOOST_TEST(test("0123456", maxwidth(val(8))[lit("0123456")]));
68         BOOST_TEST(test("01234567", maxwidth(val(8))[lit("012345678")]));
69 
70         int w = 8;
71         BOOST_TEST(test("01234567", maxwidth(ref(w))[string], "01234567"));
72         BOOST_TEST(test("0123456", maxwidth(ref(w))[string], "0123456"));
73         BOOST_TEST(test("01234567", maxwidth(ref(w))[string], "012345678"));
74     }
75 
76     return boost::report_errors();
77 }
78