]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-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 | /////////////////////////////////////////////////////////////////////////////// | |
10 | // | |
11 | // Fundamental meta sublayer tests | |
12 | // | |
13 | /////////////////////////////////////////////////////////////////////////////// | |
14 | ||
15 | #include <boost/detail/lightweight_test.hpp> | |
16 | #include <iostream> | |
17 | #include <boost/static_assert.hpp> | |
18 | #include <boost/spirit/include/classic_core.hpp> | |
19 | #include <boost/spirit/include/classic_meta.hpp> | |
20 | #include <boost/spirit/include/classic_assign_actor.hpp> | |
21 | ||
7c673cae FG |
22 | using namespace BOOST_SPIRIT_CLASSIC_NS; |
23 | ||
24 | typedef ref_value_actor<char, assign_action> assign_actor; | |
25 | ||
26 | /////////////////////////////////////////////////////////////////////////////// | |
27 | // | |
28 | // node_count_tests | |
29 | // | |
30 | /////////////////////////////////////////////////////////////////////////////// | |
31 | void | |
32 | node_count_tests() | |
33 | { | |
34 | // simple types | |
35 | typedef chlit<char> plain_t; | |
36 | typedef optional<chlit<char> > optional_t; | |
37 | typedef action<chlit<char>, assign_actor> action_t; | |
38 | typedef sequence<chlit<char>, anychar_parser> sequence_t; | |
39 | ||
40 | BOOST_STATIC_ASSERT(1 == node_count<plain_t>::value); | |
41 | BOOST_STATIC_ASSERT(2 == node_count<optional_t>::value); | |
42 | BOOST_STATIC_ASSERT(2 == node_count<action_t>::value); | |
43 | BOOST_STATIC_ASSERT(3 == node_count<sequence_t>::value); | |
44 | ||
45 | // more elaborate types | |
46 | typedef sequence<sequence<plain_t, action_t>, plain_t> sequence2_t; | |
47 | typedef sequence<plain_t, sequence<action_t, plain_t> > sequence3_t; | |
48 | ||
49 | BOOST_STATIC_ASSERT(6 == node_count<sequence2_t>::value); | |
50 | BOOST_STATIC_ASSERT(6 == node_count<sequence3_t>::value); | |
51 | } | |
52 | ||
53 | /////////////////////////////////////////////////////////////////////////////// | |
54 | // | |
55 | // leaf_count_tests | |
56 | // | |
57 | /////////////////////////////////////////////////////////////////////////////// | |
58 | void | |
59 | leaf_count_tests() | |
60 | { | |
61 | // simple types | |
62 | typedef chlit<char> plain_t; | |
63 | typedef optional<chlit<char> > optional_t; | |
64 | typedef action<chlit<char>, assign_actor> action_t; | |
65 | typedef sequence<chlit<char>, anychar_parser> sequence_t; | |
66 | ||
67 | BOOST_STATIC_ASSERT(1 == leaf_count<plain_t>::value); | |
68 | BOOST_STATIC_ASSERT(1 == leaf_count<optional_t>::value); | |
69 | BOOST_STATIC_ASSERT(1 == leaf_count<action_t>::value); | |
70 | BOOST_STATIC_ASSERT(2 == leaf_count<sequence_t>::value); | |
71 | ||
72 | // more elaborate types | |
73 | typedef sequence<sequence<plain_t, action_t>, plain_t> sequence2_t; | |
74 | typedef sequence<plain_t, sequence<action_t, plain_t> > sequence3_t; | |
75 | ||
76 | BOOST_STATIC_ASSERT(3 == leaf_count<sequence2_t>::value); | |
77 | BOOST_STATIC_ASSERT(3 == leaf_count<sequence3_t>::value); | |
78 | } | |
79 | ||
80 | ||
81 | /////////////////////////////////////////////////////////////////////////////// | |
82 | // | |
83 | // Main | |
84 | // | |
85 | /////////////////////////////////////////////////////////////////////////////// | |
86 | int | |
87 | main() | |
88 | { | |
89 | node_count_tests(); | |
90 | leaf_count_tests(); | |
91 | ||
92 | return boost::report_errors(); | |
93 | } | |
94 |