test3.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // test3.hpp
  3. //
  4. // Copyright 2008 Eric Niebler. Distributed under the Boost
  5. // Software License, Version 1.0. (See accompanying file
  6. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #include "./test.hpp"
  8. ///////////////////////////////////////////////////////////////////////////////
  9. // get_test_cases
  10. //
  11. template<typename BidiIterT>
  12. boost::iterator_range<xpr_test_case<BidiIterT> const *> get_test_cases()
  13. {
  14. typedef typename boost::iterator_value<BidiIterT>::type char_type;
  15. typedef xpr_test_case<BidiIterT> xpr_test_case;
  16. typedef basic_regex<BidiIterT> regex_type;
  17. static char_type const *nilbr = 0;
  18. static xpr_test_case const test_cases[] =
  19. {
  20. xpr_test_case
  21. (
  22. "test41"
  23. , L("foobarFOObarfoo")
  24. , regex_type((s1= icase(L("FOO"))) >> (s2= -*_) >> s1)
  25. , backrefs(L("foobarFOObarfoo"), L("foo"), L("barFOObar"), nilbr)
  26. )
  27. , xpr_test_case
  28. (
  29. "test42"
  30. , L("foobarFOObarfoo")
  31. , regex_type((s1= icase(L("FOO"))) >> (s2= -*_) >> icase(s1))
  32. , backrefs(L("foobarFOO"), L("foo"), L("bar"), nilbr)
  33. )
  34. , xpr_test_case
  35. (
  36. "test42.1"
  37. , L("fooFOOOFOOOOObar")
  38. , regex_type(+(s1= L("foo") | icase(s1 >> L('O'))))
  39. , backrefs(L("fooFOOOFOOOO"), L("FOOOO"), nilbr)
  40. )
  41. , xpr_test_case
  42. (
  43. "test43"
  44. , L("zoo")
  45. , regex_type(bos >> set[range(L('A'),L('Z')) | range(L('a'),L('m'))])
  46. , no_match
  47. )
  48. , xpr_test_case
  49. (
  50. "test44"
  51. , L("Here is a URL: http://www.cnn.com. OK?")
  52. , regex_type((s1= L("http") >> !as_xpr(L('s')) >> L(":/") | L("www."))
  53. >> +set[_w | (set=L('.'),L('/'),L(','),L('?'),L('@'),L('#'),L('%'),L('!'),L('_'),L('='),L('~'),L('&'),L('-'))]
  54. >> _w)
  55. , backrefs(L("http://www.cnn.com"), L("http:/"), nilbr)
  56. )
  57. , xpr_test_case
  58. (
  59. "test45"
  60. , L("fooooooooo")
  61. , regex_type(L('f') >> repeat<2,5>(L('o')))
  62. , backrefs(L("fooooo"), nilbr)
  63. )
  64. , xpr_test_case
  65. (
  66. "test46"
  67. , L("fooooooooo")
  68. , regex_type(L('f') >> -repeat<2,5>(L('o')))
  69. , backrefs(L("foo"), nilbr)
  70. )
  71. , xpr_test_case
  72. (
  73. "test45.1"
  74. , L("fooooooooo")
  75. , regex_type(L('f') >> repeat<2,5>(L('o')) >> L('o'))
  76. , backrefs(L("foooooo"), nilbr)
  77. )
  78. , xpr_test_case
  79. (
  80. "test46.1"
  81. , L("fooooooooo")
  82. , regex_type(L('f') >> -repeat<2,5>(L('o')) >> L('o'))
  83. , backrefs(L("fooo"), nilbr)
  84. )
  85. , xpr_test_case
  86. (
  87. "test47"
  88. , L("{match this}")
  89. , regex_type(bos >> L('{') >> *_ >> L('}') >> eos)
  90. , backrefs(L("{match this}"), nilbr)
  91. )
  92. , xpr_test_case
  93. (
  94. "test48"
  95. , L("+-+-")
  96. , regex_type(+(set=L('+'),L('-')))
  97. , backrefs(L("+-+-"), nilbr)
  98. )
  99. , xpr_test_case
  100. (
  101. "test49"
  102. , L("+-+-")
  103. , regex_type(+(set=L('-'),L('+')))
  104. , backrefs(L("+-+-"), nilbr)
  105. )
  106. , xpr_test_case
  107. (
  108. "test50"
  109. , L("\\05g-9e")
  110. , regex_type(+set[_d | L('-') | L('g')])
  111. , backrefs(L("05g-9"), nilbr)
  112. )
  113. , xpr_test_case
  114. (
  115. "test51"
  116. , L("\\05g-9e")
  117. , regex_type(+set[_d | L('-') | L('g')])
  118. , backrefs(L("05g-9"), nilbr)
  119. )
  120. , xpr_test_case
  121. (
  122. "test52"
  123. , L("\\05g-9e")
  124. , regex_type(+set[L('g') | as_xpr(L('-')) | _d])
  125. , backrefs(L("05g-9"), nilbr)
  126. )
  127. , xpr_test_case
  128. (
  129. "test53"
  130. , L("\\05g-9e")
  131. , regex_type(+set[L('g') | as_xpr(L('-')) | _d])
  132. , backrefs(L("05g-9"), nilbr)
  133. )
  134. , xpr_test_case
  135. (
  136. "test54"
  137. , L("aBcdefg\\")
  138. , regex_type(icase(+range(L('a'),L('g'))))
  139. , backrefs(L("aBcdefg"), nilbr)
  140. )
  141. , xpr_test_case
  142. (
  143. "test55"
  144. , L("ab/.-ba")
  145. , regex_type(+range(L('-'),L('/')))
  146. , backrefs(L("/.-"), nilbr)
  147. )
  148. , xpr_test_case
  149. (
  150. "test56"
  151. , L("ab+,-ba")
  152. , regex_type(+range(L('+'),L('-')))
  153. , backrefs(L("+,-"), nilbr)
  154. )
  155. , xpr_test_case
  156. (
  157. "test56.1"
  158. , L("aaabbbb----")
  159. , regex_type(+range(L('b'),L('b')))
  160. , backrefs(L("bbbb"), nilbr)
  161. )
  162. , xpr_test_case
  163. (
  164. "test57"
  165. , L("foobarFOO5")
  166. , regex_type(icase((s1= L("foo")) >> *_ >> L('\15')))
  167. , no_match
  168. )
  169. , xpr_test_case
  170. (
  171. "test58"
  172. , L("Her number is 804-867-5309.")
  173. , regex_type(repeat<2>(repeat<3>(_d) >> L('-')) >> repeat<4>(_d))
  174. , backrefs(L("804-867-5309"), nilbr)
  175. )
  176. , xpr_test_case
  177. (
  178. "test59"
  179. , L("foo")
  180. , regex_type(L('f') >> +as_xpr(L('o')))
  181. , backrefs(L("foo"), nilbr)
  182. )
  183. , xpr_test_case
  184. (
  185. "test60"
  186. , L("fooFOObar")
  187. , regex_type(icase(+(s1= L("foo")) >> L("foobar")))
  188. , backrefs(L("fooFOObar"), L("foo"), nilbr)
  189. )
  190. };
  191. return boost::make_iterator_range(test_cases);
  192. }