123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
- // Distributed under the Boost Software License, Version 1.0.
- // (See accompanying file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt)
- #include <boost/metaparse/source_position.hpp>
- #include <boost/metaparse/start.hpp>
- #include <boost/metaparse/next_char.hpp>
- #include <boost/metaparse/next_line.hpp>
- #include <boost/metaparse/get_prev_char.hpp>
- #include <boost/metaparse/get_line.hpp>
- #include <boost/metaparse/get_col.hpp>
- #include "common.hpp"
- #include <boost/mpl/equal_to.hpp>
- #include <boost/mpl/not_equal_to.hpp>
- #include <boost/mpl/assert.hpp>
- #include <boost/mpl/less.hpp>
- #include <boost/mpl/greater.hpp>
- #include <boost/mpl/greater_equal.hpp>
- #include <boost/mpl/less_equal.hpp>
- #include <boost/mpl/not.hpp>
- #include "test_case.hpp"
- namespace
- {
- using boost::metaparse::source_position;
- using boost::metaparse::next_char;
- using boost::metaparse::start;
- typedef source_position<int11, int13, int1> sp;
- typedef next_char<start, char_0> next0;
- }
- BOOST_METAPARSE_TEST_CASE(source_position)
- {
- using boost::metaparse::get_line;
- using boost::metaparse::get_col;
- using boost::metaparse::get_prev_char;
- using boost::metaparse::next_line;
-
- using boost::mpl::equal_to;
- using boost::mpl::not_equal_to;
- using boost::mpl::not_;
- using boost::mpl::less;
- using boost::mpl::greater;
- using boost::mpl::greater_equal;
- using boost::mpl::less_equal;
-
- // test_get_line
- BOOST_MPL_ASSERT((equal_to<int11, get_line<sp>::type>));
- // test_get_col
- BOOST_MPL_ASSERT((equal_to<int13, get_col<sp>::type>));
-
- // test_get_prev_char
- BOOST_MPL_ASSERT((equal_to<int1, get_prev_char<sp>::type>));
- // test_line_of_start
- BOOST_MPL_ASSERT((equal_to<int1, get_line<start>::type>));
- // test_col_of_start
- BOOST_MPL_ASSERT((equal_to<int1, get_col<start>::type>));
- // test_next_chars_char
- BOOST_MPL_ASSERT((equal_to<int2, get_col<next0>::type>));
- // test_next_chars_line
- BOOST_MPL_ASSERT((equal_to<int1, get_line<next0>::type>));
- // test_next_lines_char
- BOOST_MPL_ASSERT((
- equal_to<int1, get_col<next_line<next0, char_0> >::type>
- ));
- // test_next_lines_line
- BOOST_MPL_ASSERT((
- equal_to<int2, get_line<next_line<start, char_0> >::type>
- ));
- // test_next_chars_prev_char
- BOOST_MPL_ASSERT((
- equal_to<char_1, get_prev_char< next_char<start, char_1> >::type>
- ));
- // test_next_lines_prev_char
- BOOST_MPL_ASSERT((
- equal_to<char_1, get_prev_char<next_line<start, char_1> >::type>
- ));
- // test_equal_source_positions
- BOOST_MPL_ASSERT((equal_to<sp, sp>));
- // test_equal_source_positions_when_prev_char_is_different
- BOOST_MPL_ASSERT((
- not_<
- equal_to<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_b>
- >::type
- >
- ));
- // test_not_equal_source_positions_when_line_is_different
- BOOST_MPL_ASSERT((
- not_equal_to<
- source_position<int11, int13, char_a>,
- source_position<int13, int13, char_a>
- >
- ));
- // test_not_equal_source_positions_when_col_is_different
- BOOST_MPL_ASSERT((
- not_equal_to<
- source_position<int11, int11, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_is_not_less_than_itself
- BOOST_MPL_ASSERT((
- not_<
- less<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_a>
- >::type
- >
- ));
- // test_source_position_earlier_in_the_same_line_is_less
- BOOST_MPL_ASSERT((
- less<
- source_position<int11, int11, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_later_in_the_same_line_is_not_less
- BOOST_MPL_ASSERT((
- not_<
- less<
- source_position<int11, int13, char_a>,
- source_position<int11, int11, char_a>
- >::type
- >
- ));
- // test_source_position_in_the_same_pos_with_less_char_is_less
- BOOST_MPL_ASSERT((
- less<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_b>
- >
- ));
- // test_source_position_earlier_line_is_less
- BOOST_MPL_ASSERT((
- less<
- source_position<int1, int28, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_later_line_is_not_less
- BOOST_MPL_ASSERT((
- not_<
- less<
- source_position<int28, int2, char_a>,
- source_position<int11, int13, char_a>
- >::type
- >
- ));
- // test_source_position_is_greater_equal_to_itself
- BOOST_MPL_ASSERT((
- greater_equal<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_earlier_in_the_same_line_is_not_greater_equal
- BOOST_MPL_ASSERT((
- not_<
- greater_equal<
- source_position<int11, int11, char_a>,
- source_position<int11, int13, char_a>
- >::type
- >
- ));
- // test_source_position_later_in_the_same_line_is_greater_equal
- BOOST_MPL_ASSERT((
- greater_equal<
- source_position<int11, int13, char_a>,
- source_position<int11, int11, char_a>
- >
- ));
- // test_source_position_in_the_same_pos_with_less_char_is_not_greater_equal
- BOOST_MPL_ASSERT((
- not_<
- greater_equal<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_b>
- >::type
- >
- ));
- // test_source_position_earlier_line_is_not_greater_equal
- BOOST_MPL_ASSERT((
- not_<
- greater_equal<
- source_position<int1, int28, char_a>,
- source_position<int11, int13, char_a>
- >::type
- >
- ));
- // test_source_position_later_line_is_greater_equal
- BOOST_MPL_ASSERT((
- greater_equal<
- source_position<int28, int2, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_is_not_greater_than_itself
- BOOST_MPL_ASSERT((
- not_<
- greater<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_a>
- >::type
- >
- ));
- // test_source_position_earlier_in_the_same_line_is_not_greater
- BOOST_MPL_ASSERT((
- not_<
- greater<
- source_position<int11, int11, char_a>,
- source_position<int11, int13, char_a>
- >::type
- >
- ));
- // test_source_position_later_in_the_same_line_is_greater
- BOOST_MPL_ASSERT((
- greater<
- source_position<int11, int13, char_a>,
- source_position<int11, int11, char_a>
- >
- ));
- // test_source_position_in_the_same_pos_with_less_char_is_not_greater
- BOOST_MPL_ASSERT((
- not_<
- greater<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_b>
- >::type
- >
- ));
- // test_source_position_earlier_line_is_not_greater
- BOOST_MPL_ASSERT((
- not_<
- greater<
- source_position<int1, int28, char_a>,
- source_position<int11, int13, char_a>
- >::type
- >
- ));
- // test_source_position_later_line_is_greater
- BOOST_MPL_ASSERT((
- greater<
- source_position<int28, int2, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_is_less_equal_to_itself
- BOOST_MPL_ASSERT((
- less_equal<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_earlier_in_the_same_line_is_less_equal
- BOOST_MPL_ASSERT((
- less_equal<
- source_position<int11, int11, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_later_in_the_same_line_is_not_less_equal
- BOOST_MPL_ASSERT((
- not_<
- less_equal<
- source_position<int11, int13, char_a>,
- source_position<int11, int11, char_a>
- >::type
- >
- ));
- // test_source_position_in_the_same_pos_with_less_char_is_less_equal
- BOOST_MPL_ASSERT((
- less_equal<
- source_position<int11, int13, char_a>,
- source_position<int11, int13, char_b>
- >
- ));
- // test_source_position_earlier_line_is_less_equal
- BOOST_MPL_ASSERT((
- less_equal<
- source_position<int1, int28, char_a>,
- source_position<int11, int13, char_a>
- >
- ));
- // test_source_position_later_line_is_not_less_equal
- BOOST_MPL_ASSERT((
- not_<
- less_equal<
- source_position<int28, int2, char_a>,
- source_position<int11, int13, char_a>
- >::type
- >
- ));
- }
|