Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/spirit/test/subrule_tests.cpp @ 33

Last change on this file since 33 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.2 KB
Line 
1/*=============================================================================
2    Copyright (c) 1998-2003 Joel de Guzman
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 <iostream>
10#include <boost/detail/lightweight_test.hpp>
11
12using namespace std;
13
14#include <boost/spirit/core.hpp>
15using namespace boost::spirit;
16
17///////////////////////////////////////////////////////////////////////////////
18//
19//  Sub Rules tests
20//
21///////////////////////////////////////////////////////////////////////////////
22void
23subrules_tests()
24{
25    subrule<0>  start;
26    subrule<1>  a;
27    subrule<2>  b;
28    subrule<3>  c;
29
30    parse_info<char const*> pi;
31    pi = parse("abcabcacb",
32        (
33            start   = *(a | b | c),
34            a       = ch_p('a'),
35            b       = ch_p('b'),
36            c       = ch_p('c')
37        )
38    );
39
40    BOOST_TEST(pi.hit);
41    BOOST_TEST(pi.full);
42    BOOST_TEST(pi.length == 9);
43    BOOST_TEST(*pi.stop == 0);
44
45    pi = parse("aaaabababaaabbb",
46        (
47            start   = (a | b) >> (start | b),
48            a       = ch_p('a'),
49            b       = ch_p('b')
50        )
51    );
52
53    BOOST_TEST(pi.hit);
54    BOOST_TEST(pi.full);
55    BOOST_TEST(pi.length == 15);
56    BOOST_TEST(*pi.stop == 0);
57
58    pi = parse("aaaabababaaabba",
59        (
60            start   = (a | b) >> (start | b),
61            a       = ch_p('a'),
62            b       = ch_p('b')
63        )
64    );
65
66    BOOST_TEST(pi.hit);
67    BOOST_TEST(!pi.full);
68    BOOST_TEST(pi.length == 14);
69
70    pi = parse("aaaabababaaabbb",
71
72        //  single subrule test
73        start = (ch_p('a') | 'b') >> (start | 'b')
74    );
75
76    BOOST_TEST(pi.hit);
77    BOOST_TEST(pi.full);
78    BOOST_TEST(pi.length == 15);
79    BOOST_TEST(*pi.stop == 0);
80}
81
82///////////////////////////////////////////////////////////////////////////////
83//
84//  Main
85//
86///////////////////////////////////////////////////////////////////////////////
87int
88main()
89{
90    subrules_tests();
91    return boost::report_errors();
92}
93
Note: See TracBrowser for help on using the repository browser.