1 /*=============================================================================
2 Copyright (c) 2004 Joao Abecasis
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 #include <boost/spirit/include/classic_parser.hpp>
11 #include <boost/spirit/include/classic_skipper.hpp>
12 #include <boost/spirit/include/classic_primitives.hpp>
13 #include <boost/spirit/include/classic_optional.hpp>
14 #include <boost/spirit/include/classic_sequence.hpp>
15 #include <boost/spirit/include/classic_ast.hpp>
16 #include <boost/spirit/include/classic_parse_tree.hpp>
17
18 #include <boost/detail/lightweight_test.hpp>
19
20 using namespace BOOST_SPIRIT_CLASSIC_NS;
21
22 char const * test1 = " 12345 ";
23 char const * test2 = " 12345 x";
24
parse_tests()25 void parse_tests()
26 {
27 parse_info<> info;
28
29 // Warming up...
30 info = parse(test1, str_p("12345"));
31 BOOST_TEST(!info.hit);
32
33 // No post-skips!
34 info = parse(test1, str_p("12345"), blank_p);
35 BOOST_TEST(info.hit);
36 BOOST_TEST(!info.full);
37
38 // Require a full match
39 info = parse(test1, str_p("12345") >> end_p, blank_p);
40 BOOST_TEST(info.full);
41 info = parse(test2, str_p("12345") >> end_p, blank_p);
42 BOOST_TEST(!info.hit);
43
44 // Check for a full match but don't make it a requirement
45 info = parse(test1, str_p("12345") >> !end_p, blank_p);
46 BOOST_TEST(info.full);
47 info = parse(test2, str_p("12345") >> !end_p, blank_p);
48 BOOST_TEST(info.hit);
49 BOOST_TEST(!info.full);
50 }
51
ast_parse_tests()52 void ast_parse_tests()
53 {
54 tree_parse_info<> info;
55
56 // Warming up...
57 info = ast_parse(test1, str_p("12345"));
58 BOOST_TEST(!info.match);
59
60 // No post-skips!
61 info = ast_parse(test1, str_p("12345"), blank_p);
62 BOOST_TEST(info.match);
63 BOOST_TEST(!info.full);
64
65 // Require a full match
66 info = ast_parse(test1, str_p("12345") >> end_p, blank_p);
67 BOOST_TEST(info.full);
68 info = ast_parse(test2, str_p("12345") >> end_p, blank_p);
69 BOOST_TEST(!info.match);
70
71 // Check for a full match but don't make it a requirement
72 info = ast_parse(test1, str_p("12345") >> !end_p, blank_p);
73 BOOST_TEST(info.full);
74 info = ast_parse(test2, str_p("12345") >> !end_p, blank_p);
75 BOOST_TEST(info.match);
76 BOOST_TEST(!info.full);
77 }
78
pt_parse_tests()79 void pt_parse_tests()
80 {
81 tree_parse_info<> info;
82
83 // Warming up...
84 info = pt_parse(test1, str_p("12345"));
85 BOOST_TEST(!info.match);
86
87 // No post-skips!
88 info = pt_parse(test1, str_p("12345"), blank_p);
89 BOOST_TEST(info.match);
90 BOOST_TEST(!info.full);
91
92 // Require a full match
93 info = pt_parse(test1, str_p("12345") >> end_p, blank_p);
94 BOOST_TEST(info.full);
95 info = pt_parse(test2, str_p("12345") >> end_p, blank_p);
96 BOOST_TEST(!info.match);
97
98 // Check for a full match but don't make it a requirement
99 info = pt_parse(test1, str_p("12345") >> !end_p, blank_p);
100 BOOST_TEST(info.full);
101 info = pt_parse(test2, str_p("12345") >> !end_p, blank_p);
102 BOOST_TEST(info.match);
103 BOOST_TEST(!info.full);
104 }
105
main()106 int main()
107 {
108 parse_tests();
109 ast_parse_tests();
110 pt_parse_tests();
111
112 return boost::report_errors();
113 }
114