source_position.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/metaparse/source_position.hpp>
  6. #include <boost/metaparse/start.hpp>
  7. #include <boost/metaparse/next_char.hpp>
  8. #include <boost/metaparse/next_line.hpp>
  9. #include <boost/metaparse/get_prev_char.hpp>
  10. #include <boost/metaparse/get_line.hpp>
  11. #include <boost/metaparse/get_col.hpp>
  12. #include "common.hpp"
  13. #include <boost/mpl/equal_to.hpp>
  14. #include <boost/mpl/not_equal_to.hpp>
  15. #include <boost/mpl/assert.hpp>
  16. #include <boost/mpl/less.hpp>
  17. #include <boost/mpl/greater.hpp>
  18. #include <boost/mpl/greater_equal.hpp>
  19. #include <boost/mpl/less_equal.hpp>
  20. #include <boost/mpl/not.hpp>
  21. #include "test_case.hpp"
  22. namespace
  23. {
  24. using boost::metaparse::source_position;
  25. using boost::metaparse::next_char;
  26. using boost::metaparse::start;
  27. typedef source_position<int11, int13, int1> sp;
  28. typedef next_char<start, char_0> next0;
  29. }
  30. BOOST_METAPARSE_TEST_CASE(source_position)
  31. {
  32. using boost::metaparse::get_line;
  33. using boost::metaparse::get_col;
  34. using boost::metaparse::get_prev_char;
  35. using boost::metaparse::next_line;
  36. using boost::mpl::equal_to;
  37. using boost::mpl::not_equal_to;
  38. using boost::mpl::not_;
  39. using boost::mpl::less;
  40. using boost::mpl::greater;
  41. using boost::mpl::greater_equal;
  42. using boost::mpl::less_equal;
  43. // test_get_line
  44. BOOST_MPL_ASSERT((equal_to<int11, get_line<sp>::type>));
  45. // test_get_col
  46. BOOST_MPL_ASSERT((equal_to<int13, get_col<sp>::type>));
  47. // test_get_prev_char
  48. BOOST_MPL_ASSERT((equal_to<int1, get_prev_char<sp>::type>));
  49. // test_line_of_start
  50. BOOST_MPL_ASSERT((equal_to<int1, get_line<start>::type>));
  51. // test_col_of_start
  52. BOOST_MPL_ASSERT((equal_to<int1, get_col<start>::type>));
  53. // test_next_chars_char
  54. BOOST_MPL_ASSERT((equal_to<int2, get_col<next0>::type>));
  55. // test_next_chars_line
  56. BOOST_MPL_ASSERT((equal_to<int1, get_line<next0>::type>));
  57. // test_next_lines_char
  58. BOOST_MPL_ASSERT((
  59. equal_to<int1, get_col<next_line<next0, char_0> >::type>
  60. ));
  61. // test_next_lines_line
  62. BOOST_MPL_ASSERT((
  63. equal_to<int2, get_line<next_line<start, char_0> >::type>
  64. ));
  65. // test_next_chars_prev_char
  66. BOOST_MPL_ASSERT((
  67. equal_to<char_1, get_prev_char< next_char<start, char_1> >::type>
  68. ));
  69. // test_next_lines_prev_char
  70. BOOST_MPL_ASSERT((
  71. equal_to<char_1, get_prev_char<next_line<start, char_1> >::type>
  72. ));
  73. // test_equal_source_positions
  74. BOOST_MPL_ASSERT((equal_to<sp, sp>));
  75. // test_equal_source_positions_when_prev_char_is_different
  76. BOOST_MPL_ASSERT((
  77. not_<
  78. equal_to<
  79. source_position<int11, int13, char_a>,
  80. source_position<int11, int13, char_b>
  81. >::type
  82. >
  83. ));
  84. // test_not_equal_source_positions_when_line_is_different
  85. BOOST_MPL_ASSERT((
  86. not_equal_to<
  87. source_position<int11, int13, char_a>,
  88. source_position<int13, int13, char_a>
  89. >
  90. ));
  91. // test_not_equal_source_positions_when_col_is_different
  92. BOOST_MPL_ASSERT((
  93. not_equal_to<
  94. source_position<int11, int11, char_a>,
  95. source_position<int11, int13, char_a>
  96. >
  97. ));
  98. // test_source_position_is_not_less_than_itself
  99. BOOST_MPL_ASSERT((
  100. not_<
  101. less<
  102. source_position<int11, int13, char_a>,
  103. source_position<int11, int13, char_a>
  104. >::type
  105. >
  106. ));
  107. // test_source_position_earlier_in_the_same_line_is_less
  108. BOOST_MPL_ASSERT((
  109. less<
  110. source_position<int11, int11, char_a>,
  111. source_position<int11, int13, char_a>
  112. >
  113. ));
  114. // test_source_position_later_in_the_same_line_is_not_less
  115. BOOST_MPL_ASSERT((
  116. not_<
  117. less<
  118. source_position<int11, int13, char_a>,
  119. source_position<int11, int11, char_a>
  120. >::type
  121. >
  122. ));
  123. // test_source_position_in_the_same_pos_with_less_char_is_less
  124. BOOST_MPL_ASSERT((
  125. less<
  126. source_position<int11, int13, char_a>,
  127. source_position<int11, int13, char_b>
  128. >
  129. ));
  130. // test_source_position_earlier_line_is_less
  131. BOOST_MPL_ASSERT((
  132. less<
  133. source_position<int1, int28, char_a>,
  134. source_position<int11, int13, char_a>
  135. >
  136. ));
  137. // test_source_position_later_line_is_not_less
  138. BOOST_MPL_ASSERT((
  139. not_<
  140. less<
  141. source_position<int28, int2, char_a>,
  142. source_position<int11, int13, char_a>
  143. >::type
  144. >
  145. ));
  146. // test_source_position_is_greater_equal_to_itself
  147. BOOST_MPL_ASSERT((
  148. greater_equal<
  149. source_position<int11, int13, char_a>,
  150. source_position<int11, int13, char_a>
  151. >
  152. ));
  153. // test_source_position_earlier_in_the_same_line_is_not_greater_equal
  154. BOOST_MPL_ASSERT((
  155. not_<
  156. greater_equal<
  157. source_position<int11, int11, char_a>,
  158. source_position<int11, int13, char_a>
  159. >::type
  160. >
  161. ));
  162. // test_source_position_later_in_the_same_line_is_greater_equal
  163. BOOST_MPL_ASSERT((
  164. greater_equal<
  165. source_position<int11, int13, char_a>,
  166. source_position<int11, int11, char_a>
  167. >
  168. ));
  169. // test_source_position_in_the_same_pos_with_less_char_is_not_greater_equal
  170. BOOST_MPL_ASSERT((
  171. not_<
  172. greater_equal<
  173. source_position<int11, int13, char_a>,
  174. source_position<int11, int13, char_b>
  175. >::type
  176. >
  177. ));
  178. // test_source_position_earlier_line_is_not_greater_equal
  179. BOOST_MPL_ASSERT((
  180. not_<
  181. greater_equal<
  182. source_position<int1, int28, char_a>,
  183. source_position<int11, int13, char_a>
  184. >::type
  185. >
  186. ));
  187. // test_source_position_later_line_is_greater_equal
  188. BOOST_MPL_ASSERT((
  189. greater_equal<
  190. source_position<int28, int2, char_a>,
  191. source_position<int11, int13, char_a>
  192. >
  193. ));
  194. // test_source_position_is_not_greater_than_itself
  195. BOOST_MPL_ASSERT((
  196. not_<
  197. greater<
  198. source_position<int11, int13, char_a>,
  199. source_position<int11, int13, char_a>
  200. >::type
  201. >
  202. ));
  203. // test_source_position_earlier_in_the_same_line_is_not_greater
  204. BOOST_MPL_ASSERT((
  205. not_<
  206. greater<
  207. source_position<int11, int11, char_a>,
  208. source_position<int11, int13, char_a>
  209. >::type
  210. >
  211. ));
  212. // test_source_position_later_in_the_same_line_is_greater
  213. BOOST_MPL_ASSERT((
  214. greater<
  215. source_position<int11, int13, char_a>,
  216. source_position<int11, int11, char_a>
  217. >
  218. ));
  219. // test_source_position_in_the_same_pos_with_less_char_is_not_greater
  220. BOOST_MPL_ASSERT((
  221. not_<
  222. greater<
  223. source_position<int11, int13, char_a>,
  224. source_position<int11, int13, char_b>
  225. >::type
  226. >
  227. ));
  228. // test_source_position_earlier_line_is_not_greater
  229. BOOST_MPL_ASSERT((
  230. not_<
  231. greater<
  232. source_position<int1, int28, char_a>,
  233. source_position<int11, int13, char_a>
  234. >::type
  235. >
  236. ));
  237. // test_source_position_later_line_is_greater
  238. BOOST_MPL_ASSERT((
  239. greater<
  240. source_position<int28, int2, char_a>,
  241. source_position<int11, int13, char_a>
  242. >
  243. ));
  244. // test_source_position_is_less_equal_to_itself
  245. BOOST_MPL_ASSERT((
  246. less_equal<
  247. source_position<int11, int13, char_a>,
  248. source_position<int11, int13, char_a>
  249. >
  250. ));
  251. // test_source_position_earlier_in_the_same_line_is_less_equal
  252. BOOST_MPL_ASSERT((
  253. less_equal<
  254. source_position<int11, int11, char_a>,
  255. source_position<int11, int13, char_a>
  256. >
  257. ));
  258. // test_source_position_later_in_the_same_line_is_not_less_equal
  259. BOOST_MPL_ASSERT((
  260. not_<
  261. less_equal<
  262. source_position<int11, int13, char_a>,
  263. source_position<int11, int11, char_a>
  264. >::type
  265. >
  266. ));
  267. // test_source_position_in_the_same_pos_with_less_char_is_less_equal
  268. BOOST_MPL_ASSERT((
  269. less_equal<
  270. source_position<int11, int13, char_a>,
  271. source_position<int11, int13, char_b>
  272. >
  273. ));
  274. // test_source_position_earlier_line_is_less_equal
  275. BOOST_MPL_ASSERT((
  276. less_equal<
  277. source_position<int1, int28, char_a>,
  278. source_position<int11, int13, char_a>
  279. >
  280. ));
  281. // test_source_position_later_line_is_not_less_equal
  282. BOOST_MPL_ASSERT((
  283. not_<
  284. less_equal<
  285. source_position<int28, int2, char_a>,
  286. source_position<int11, int13, char_a>
  287. >::type
  288. >
  289. ));
  290. }