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