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