]>
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/detail/lightweight_test.hpp>
9 #include <boost/spirit/include/qi.hpp>
10 #include <boost/fusion/include/nview.hpp>
12 namespace qi
= boost::spirit::qi
;
13 namespace ascii
= boost::spirit::ascii
;
14 namespace phx
= boost::phoenix
;
15 namespace fusion
= boost::fusion
;
16 namespace mpl
= boost::mpl
;
20 using fusion::result_of::as_nview
;
22 using boost::optional
;
24 using ascii::space_type
;
29 typedef fusion::vector
<
30 optional
<double>, // 0 - U
31 optional
<double>, // 1 - V
32 optional
<double> // 2 - W
35 typedef as_nview
<uvw_type
, 0, 1, 2>::type uvw_reordered_type
;
36 typedef as_nview
<uvw_type
, 2, 0, 1>::type vwu_reordered_type
;
38 typedef char const* iterator_type
;
40 qi::rule
<iterator_type
, optional
<double>(), space_type
> u
,v
,w
;
41 qi::rule
<iterator_type
, uvw_reordered_type(), space_type
> uvw
;
42 qi::rule
<iterator_type
, vwu_reordered_type(), space_type
> vwu
;
44 u
= no_case
[ "NA" ] | ( double_
>> -lit( "U" ) );
45 v
= no_case
[ "NA" ] | ( double_
>> -lit( "V" ) );
46 w
= no_case
[ "NA" ] | ( double_
>> -lit( "W" ) );
53 iterator_type first
= "1U 2V 3W";
54 iterator_type last
= first
+ std::strlen(first
);
56 uvw_reordered_type
uvw_result( uvw_data
);
58 BOOST_TEST(qi::phrase_parse(first
, last
, uvw
, ascii::space
, uvw_result
));
59 BOOST_TEST(fusion::at_c
<0>(uvw_result
) && *fusion::at_c
<0>(uvw_result
) == 1);
60 BOOST_TEST(fusion::at_c
<1>(uvw_result
) && *fusion::at_c
<1>(uvw_result
) == 2);
61 BOOST_TEST(fusion::at_c
<2>(uvw_result
) && *fusion::at_c
<2>(uvw_result
) == 3);
65 iterator_type first
= "2V 3W 1U";
66 iterator_type last
= first
+ std::strlen(first
);
68 vwu_reordered_type
uvw_result(uvw_data
);
70 BOOST_TEST(qi::phrase_parse(first
, last
, vwu
, ascii::space
, uvw_result
));
71 BOOST_TEST(fusion::at_c
<0>(uvw_result
) && *fusion::at_c
<0>(uvw_result
) == 2);
72 BOOST_TEST(fusion::at_c
<1>(uvw_result
) && *fusion::at_c
<1>(uvw_result
) == 3);
73 BOOST_TEST(fusion::at_c
<2>(uvw_result
) && *fusion::at_c
<2>(uvw_result
) == 1);
76 return boost::report_errors();