| 1 | /*============================================================================= |
|---|
| 2 | Copyright (c) 2003 2003 Vaclav Vesely |
|---|
| 3 | http://spirit.sourceforge.net/ |
|---|
| 4 | |
|---|
| 5 | Use, modification and distribution is subject to the Boost Software |
|---|
| 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | =============================================================================*/ |
|---|
| 9 | #include <boost/spirit/core.hpp> |
|---|
| 10 | #include <boost/spirit/utility/confix.hpp> |
|---|
| 11 | #include <boost/detail/lightweight_test.hpp> |
|---|
| 12 | |
|---|
| 13 | using namespace boost; |
|---|
| 14 | using namespace spirit; |
|---|
| 15 | |
|---|
| 16 | typedef |
|---|
| 17 | scanner<char const*, scanner_policies<skipper_iteration_policy<> > > |
|---|
| 18 | scanner_t; |
|---|
| 19 | |
|---|
| 20 | typedef |
|---|
| 21 | rule<scanner_t> |
|---|
| 22 | rule_t; |
|---|
| 23 | |
|---|
| 24 | void comment_nest_p_test() |
|---|
| 25 | { |
|---|
| 26 | rule_t r = comment_nest_p('{', '}'); |
|---|
| 27 | |
|---|
| 28 | { |
|---|
| 29 | parse_info<> info = parse("{a{b}c{d}e}", r, space_p); |
|---|
| 30 | BOOST_TEST(info.full); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | { |
|---|
| 34 | parse_info<> info = parse("{a{b}c{d}e}x", r, space_p); |
|---|
| 35 | BOOST_TEST(info.hit); |
|---|
| 36 | BOOST_TEST(info.length == 11); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | { |
|---|
| 40 | char const* str = "x{a{b}c{d}e}"; |
|---|
| 41 | parse_info<> info = parse(str, r, space_p); |
|---|
| 42 | BOOST_TEST(!info.hit); |
|---|
| 43 | BOOST_TEST(info.stop == str); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | { |
|---|
| 47 | char const* str = "{a{b}c{d}e"; |
|---|
| 48 | parse_info<> info = parse(str, r, space_p); |
|---|
| 49 | BOOST_TEST(!info.hit); |
|---|
| 50 | BOOST_TEST(info.stop == (str + 10)); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | int |
|---|
| 55 | main() |
|---|
| 56 | { |
|---|
| 57 | comment_nest_p_test(); |
|---|
| 58 | return boost::report_errors(); |
|---|
| 59 | } |
|---|
| 60 | |
|---|