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