1/*=============================================================================
2 Copyright (c) 2001-2013 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6=============================================================================*/
7#if !defined(BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM)
8#define BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM
9
10#include <boost/spirit/home/x3/core/parse.hpp>
11
12#include <boost/core/lightweight_test.hpp>
13#include <boost/utility/string_view.hpp>
14#include <iostream>
15
16namespace spirit_test
17{
18 template <typename Char, typename Parser>
19 bool test(Char const* in, Parser const& p, bool full_match = true)
20 {
21 Char const* last = in;
22 while (*last)
23 last++;
24 return boost::spirit::x3::parse(in, last, p)
25 && (!full_match || (in == last));
26 }
27
28 template <typename Char, typename Parser>
29 bool test(boost::basic_string_view<Char, std::char_traits<Char>> in,
30 Parser const& p, bool full_match = true)
31 {
32 auto const last = in.end();
33 auto pos = in.begin();
34
35 return boost::spirit::x3::parse(pos, last, p) && (!full_match || (pos == last));
36 }
37
38 template <typename Char, typename Parser, typename Skipper>
39 bool test(Char const* in, Parser const& p
40 , Skipper const& s, bool full_match = true)
41 {
42 Char const* last = in;
43 while (*last)
44 last++;
45 return boost::spirit::x3::phrase_parse(in, last, p, s)
46 && (!full_match || (in == last));
47 }
48
49 template <typename Char, typename Parser>
50 bool test_failure(Char const* in, Parser const& p)
51 {
52 Char const * const start = in;
53 Char const* last = in;
54 while (*last)
55 last++;
56
57 return !boost::spirit::x3::parse(in, last, p) && (in == start);
58 }
59
60 template <typename Char, typename Parser>
61 bool test_failure(boost::basic_string_view<Char, std::char_traits<Char>> const in,
62 Parser const& p)
63 {
64 auto pos = in.begin();
65 return !boost::spirit::x3::parse(pos, in.end(), p) && (pos == in.begin());
66 }
67
68 template <typename Char, typename Parser, typename Attr>
69 bool test_attr(Char const* in, Parser const& p
70 , Attr& attr, bool full_match = true)
71 {
72 Char const* last = in;
73 while (*last)
74 last++;
75 return boost::spirit::x3::parse(in, last, p, attr)
76 && (!full_match || (in == last));
77 }
78
79 template <typename Char, typename Parser, typename Attr, typename Skipper>
80 bool test_attr(Char const* in, Parser const& p
81 , Attr& attr, Skipper const& s, bool full_match = true)
82 {
83 Char const* last = in;
84 while (*last)
85 last++;
86 return boost::spirit::x3::phrase_parse(in, last, p, s, attr)
87 && (!full_match || (in == last));
88 }
89
90 template <typename Char, typename Parser>
91 bool binary_test(Char const* in, std::size_t size, Parser const& p,
92 bool full_match = true)
93 {
94 Char const* last = in + size;
95 return boost::spirit::x3::parse(in, last, p)
96 && (!full_match || (in == last));
97 }
98
99 template <typename Char, typename Parser, typename Skipper>
100 bool binary_test(Char const* in, std::size_t size, Parser const& p,
101 Skipper const& s, bool full_match = true)
102 {
103 Char const* last = in + size;
104 return boost::spirit::x3::phrase_parse(in, last, p, s)
105 && (!full_match || (in == last));
106 }
107
108 template <typename Char, typename Parser, typename Attr>
109 bool binary_test_attr(Char const* in, std::size_t size, Parser const& p,
110 Attr& attr, bool full_match = true)
111 {
112 Char const* last = in + size;
113 return boost::spirit::x3::parse(in, last, p, attr)
114 && (!full_match || (in == last));
115 }
116
117 template <typename Char, typename Parser, typename Attr, typename Skipper>
118 bool binary_test_attr(Char const* in, std::size_t size, Parser const& p,
119 Attr& attr, Skipper const& s, bool full_match = true)
120 {
121 Char const* last = in + size;
122 return boost::spirit::x3::phrase_parse(in, last, p, s, attr)
123 && (!full_match || (in == last));
124 }
125
126
127 template <typename... T>
128 constexpr bool always_true(T&&...) { return true; }
129
130 template <typename Parser>
131 constexpr bool test_ctors(Parser const& p)
132 {
133 return always_true(
134 static_cast<Parser>(static_cast<Parser&&>( // test move ctor
135 static_cast<Parser>(p)))); // test copy ctor
136 }
137}
138
139# define BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(...) \
140 static_assert(::spirit_test::test_ctors(__VA_ARGS__), "")
141
142#endif
143

source code of boost/libs/spirit/test/x3/test.hpp