| 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_optional.hpp> |
| 7 | |
| 8 | #include <boost/spirit/include/karma_char.hpp> |
| 9 | #include <boost/spirit/include/karma_int.hpp> |
| 10 | #include <boost/spirit/include/karma_action.hpp> |
| 11 | #include <boost/phoenix/core.hpp> |
| 12 | #include <boost/phoenix/operator.hpp> |
| 13 | |
| 14 | #include <iostream> |
| 15 | #include "test.hpp" |
| 16 | |
| 17 | int main() |
| 18 | { |
| 19 | using namespace spirit_test; |
| 20 | using namespace boost::spirit; |
| 21 | using namespace boost::spirit::ascii; |
| 22 | |
| 23 | { |
| 24 | boost::optional<int> opt; |
| 25 | BOOST_TEST(test("" , -int_, opt)); |
| 26 | |
| 27 | opt = 10; |
| 28 | BOOST_TEST(test("10" , -int_, opt)); |
| 29 | } |
| 30 | |
| 31 | { |
| 32 | int opt = 10; |
| 33 | BOOST_TEST(test("10" , -int_, opt)); |
| 34 | } |
| 35 | |
| 36 | { |
| 37 | boost::optional<int> opt; |
| 38 | BOOST_TEST(test_delimited("" , -int_, opt, space)); |
| 39 | |
| 40 | opt = 10; |
| 41 | BOOST_TEST(test_delimited("10 " , -int_, opt, space)); |
| 42 | } |
| 43 | |
| 44 | { |
| 45 | int opt = 10; |
| 46 | BOOST_TEST(test_delimited("10 " , -int_, opt, space)); |
| 47 | } |
| 48 | |
| 49 | { // test action |
| 50 | using namespace boost::phoenix; |
| 51 | namespace phoenix = boost::phoenix; |
| 52 | |
| 53 | boost::optional<int> n ; |
| 54 | BOOST_TEST(test("" , (-int_)[_1 = phoenix::ref(n)])); |
| 55 | |
| 56 | n = 1234; |
| 57 | BOOST_TEST(test("1234" , (-int_)[_1 = phoenix::ref(n)])); |
| 58 | } |
| 59 | |
| 60 | { // test action |
| 61 | using namespace boost::phoenix; |
| 62 | namespace phoenix = boost::phoenix; |
| 63 | |
| 64 | int n = 1234; |
| 65 | BOOST_TEST(test("1234" , (-int_)[_1 = phoenix::ref(n)])); |
| 66 | } |
| 67 | |
| 68 | { // test action |
| 69 | using namespace boost::phoenix; |
| 70 | namespace phoenix = boost::phoenix; |
| 71 | |
| 72 | boost::optional<int> n; |
| 73 | BOOST_TEST(test_delimited("" , (-int_)[_1 = phoenix::ref(n)], space)); |
| 74 | |
| 75 | n = 1234; |
| 76 | BOOST_TEST(test_delimited("1234 " , (-int_)[_1 = phoenix::ref(n)], space)); |
| 77 | } |
| 78 | |
| 79 | { // test action |
| 80 | using namespace boost::phoenix; |
| 81 | namespace phoenix = boost::phoenix; |
| 82 | |
| 83 | int n = 1234; |
| 84 | BOOST_TEST(test_delimited("1234 " , (-int_)[_1 = phoenix::ref(n)], space)); |
| 85 | } |
| 86 | |
| 87 | return boost::report_errors(); |
| 88 | } |
| 89 | |