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 //#define KARMA_FAIL_COMPILATION
7 
8 #include <boost/config/warning_disable.hpp>
9 #include <boost/detail/lightweight_test.hpp>
10 
11 #include <boost/spirit/include/karma_char.hpp>
12 #include <boost/spirit/include/karma_generate.hpp>
13 #include <boost/spirit/include/karma_action.hpp>
14 #include <boost/spirit/include/karma_phoenix_attributes.hpp>
15 
16 #include <boost/spirit/include/phoenix_core.hpp>
17 #include <boost/spirit/include/phoenix_operator.hpp>
18 #include <boost/spirit/include/phoenix_statement.hpp>
19 
20 #include "test.hpp"
21 
22 using namespace spirit_test;
23 
24 ///////////////////////////////////////////////////////////////////////////////
25 int
main()26 main()
27 {
28     using namespace boost::spirit;
29     using namespace boost::phoenix;
30     using boost::spirit::karma::lit;
31 
32     {
33         BOOST_TEST(test("x", lit('x')));
34         BOOST_TEST(!test("x", lit('y')));
35 
36         BOOST_TEST(test("x", lit('x'), 'x'));
37         BOOST_TEST(!test("", lit('y'), 'x'));
38 
39 //         BOOST_TEST(test("a", lit('a', 'z'), 'a'));
40 //         BOOST_TEST(test("b", lit('a', 'z'), 'b'));
41 //         BOOST_TEST(!test("", lit('a', 'z'), 'A'));
42 
43         BOOST_TEST(!test("", ~lit('x')));
44 
45         BOOST_TEST(!test("", ~lit('x'), 'x'));
46         BOOST_TEST(test("x", ~lit('y'), 'x'));
47 
48 //         BOOST_TEST(!test("", ~lit('a', 'z'), 'a'));
49 //         BOOST_TEST(!test("", ~lit('a', 'z'), 'b'));
50 //         BOOST_TEST(test("A", ~lit('a', 'z'), 'A'));
51 
52         BOOST_TEST(test("x", ~~lit('x')));
53         BOOST_TEST(!test("x", ~~lit('y')));
54 
55         BOOST_TEST(test("x", ~~lit('x'), 'x'));
56         BOOST_TEST(!test("", ~~lit('y'), 'x'));
57 
58 //         BOOST_TEST(test("a", ~~lit('a', 'z'), 'a'));
59 //         BOOST_TEST(test("b", ~~lit('a', 'z'), 'b'));
60 //         BOOST_TEST(!test("", ~~lit('a', 'z'), 'A'));
61     }
62 
63     {
64         BOOST_TEST(test(L"x", lit('x')));
65         BOOST_TEST(test(L"x", lit(L'x')));
66         BOOST_TEST(!test(L"x", lit('y')));
67         BOOST_TEST(!test(L"x", lit(L'y')));
68 
69         BOOST_TEST(test(L"x", lit(L'x'), L'x'));
70         BOOST_TEST(!test(L"", lit('y'), L'x'));
71 
72 //         BOOST_TEST(test("a", lit("a", "z"), 'a'));
73 //         BOOST_TEST(test(L"a", lit(L"a", L"z"), L'a'));
74 
75         BOOST_TEST(!test(L"", ~lit('x')));
76         BOOST_TEST(!test(L"", ~lit(L'x')));
77 
78         BOOST_TEST(!test(L"", ~lit(L'x'), L'x'));
79         BOOST_TEST(test(L"x", ~lit('y'), L'x'));
80     }
81 
82     {   // lazy chars
83         using namespace boost::phoenix;
84 
85         BOOST_TEST((test("x", lit(val('x')))));
86         BOOST_TEST((test(L"x", lit(val(L'x')))));
87 
88         BOOST_TEST((test("x", lit(val('x')), 'x')));
89         BOOST_TEST((test(L"x", lit(val(L'x')), L'x')));
90 
91         BOOST_TEST((!test("", lit(val('y')), 'x')));
92         BOOST_TEST((!test(L"", lit(val(L'y')), L'x')));
93     }
94 
95     // we can pass optionals as attributes to any generator
96     {
97         boost::optional<char> v;
98         boost::optional<wchar_t> w;
99 
100         BOOST_TEST(!test("", lit('x'), v));
101         BOOST_TEST(!test(L"", lit(L'x'), w));
102     }
103 
104     return boost::report_errors();
105 }
106