]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/regression_reorder.cpp
1 // Copyright (c) 2010 Olaf Peter
2 // Copyright (c) 2001-2010 Hartmut Kaiser
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)
7 #include <boost/spirit/include/qi_operator.hpp>
8 #include <boost/spirit/include/qi_char.hpp>
9 #include <boost/spirit/include/qi_string.hpp>
10 #include <boost/spirit/include/qi_numeric.hpp>
11 #include <boost/spirit/include/qi_directive.hpp>
12 #include <boost/spirit/include/qi_nonterminal.hpp>
14 #include <boost/core/lightweight_test.hpp>
15 #include <boost/fusion/include/nview.hpp>
17 namespace qi
= boost::spirit::qi
;
18 namespace ascii
= boost::spirit::ascii
;
19 namespace fusion
= boost::fusion
;
20 namespace mpl
= boost::mpl
;
24 using fusion::result_of::as_nview
;
26 using boost::optional
;
28 using ascii::space_type
;
33 typedef fusion::vector
<
34 optional
<double>, // 0 - U
35 optional
<double>, // 1 - V
36 optional
<double> // 2 - W
39 typedef as_nview
<uvw_type
, 0, 1, 2>::type uvw_reordered_type
;
40 typedef as_nview
<uvw_type
, 2, 0, 1>::type vwu_reordered_type
;
42 typedef char const* iterator_type
;
44 qi::rule
<iterator_type
, optional
<double>(), space_type
> u
,v
,w
;
45 qi::rule
<iterator_type
, uvw_reordered_type(), space_type
> uvw
;
46 qi::rule
<iterator_type
, vwu_reordered_type(), space_type
> vwu
;
48 u
= no_case
[ "NA" ] | ( double_
>> -lit( "U" ) );
49 v
= no_case
[ "NA" ] | ( double_
>> -lit( "V" ) );
50 w
= no_case
[ "NA" ] | ( double_
>> -lit( "W" ) );
57 iterator_type first
= "1U 2V 3W";
58 iterator_type last
= first
+ std::strlen(first
);
60 uvw_reordered_type
uvw_result( uvw_data
);
62 BOOST_TEST(qi::phrase_parse(first
, last
, uvw
, ascii::space
, uvw_result
));
63 BOOST_TEST(fusion::at_c
<0>(uvw_result
) && *fusion::at_c
<0>(uvw_result
) == 1);
64 BOOST_TEST(fusion::at_c
<1>(uvw_result
) && *fusion::at_c
<1>(uvw_result
) == 2);
65 BOOST_TEST(fusion::at_c
<2>(uvw_result
) && *fusion::at_c
<2>(uvw_result
) == 3);
69 iterator_type first
= "2V 3W 1U";
70 iterator_type last
= first
+ std::strlen(first
);
72 vwu_reordered_type
uvw_result(uvw_data
);
74 BOOST_TEST(qi::phrase_parse(first
, last
, vwu
, ascii::space
, uvw_result
));
75 BOOST_TEST(fusion::at_c
<0>(uvw_result
) && *fusion::at_c
<0>(uvw_result
) == 2);
76 BOOST_TEST(fusion::at_c
<1>(uvw_result
) && *fusion::at_c
<1>(uvw_result
) == 3);
77 BOOST_TEST(fusion::at_c
<2>(uvw_result
) && *fusion::at_c
<2>(uvw_result
) == 1);
80 return boost::report_errors();