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