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