test2.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // test2.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. // "(\\+|-)?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE](\\+|-)?[0-9]+)?"
  18. static regex_type const test21 = !(s1= as_xpr(L('+'))|L('-')) >> (s2= +range(L('0'),L('9')) >> !as_xpr(L('.')) >> *range(L('0'),L('9')) |
  19. L('.') >> +range(L('0'),L('9'))) >> !(s3= (set=L('e'),L('E')) >> !(s4= as_xpr(L('+'))|L('-')) >> +range(L('0'),L('9')));
  20. // "^(\\+|-)?([0-9]+\\.?[0-9]*|\\.[0-9]+)([eE](\\+|-)?[0-9]+)?$"
  21. static regex_type const test23 = bos >> test21 >> eos;
  22. static char_type const *nilbr = 0;
  23. static xpr_test_case const test_cases[] =
  24. {
  25. xpr_test_case
  26. (
  27. "test21"
  28. , L("-1234.56789")
  29. , test21
  30. , backrefs(L("-1234.56789"), L("-"), L("1234.56789"), L(""), L(""), nilbr)
  31. )
  32. , xpr_test_case
  33. (
  34. "test22"
  35. , L("-1234.56789e-123123123")
  36. , test21
  37. , backrefs(L("-1234.56789e-123123123"), L("-"), L("1234.56789"), L("e-123123123"), L("-"), nilbr)
  38. )
  39. , xpr_test_case
  40. (
  41. "test23"
  42. , L("-.1234.56789")
  43. , test23
  44. , no_match
  45. )
  46. , xpr_test_case
  47. (
  48. "test24"
  49. , L("-1234.56789e-12312e123")
  50. , test23
  51. , no_match
  52. )
  53. , xpr_test_case
  54. (
  55. "test25"
  56. , L("aaaaaaaaac")
  57. , regex_type(*as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> *as_xpr(L('a')) >> L('b'))
  58. , no_match
  59. )
  60. , xpr_test_case
  61. (
  62. "test26"
  63. , L("ThIs iS a TeSt")
  64. , regex_type(*set[range(L('a'),L('z')) | range(L('A'),L('Z'))])
  65. , backrefs(L("ThIs"), nilbr)
  66. )
  67. , xpr_test_case
  68. (
  69. "test27"
  70. , L("a^b")
  71. , regex_type(L('a') >> bos >> L('b'))
  72. , no_match
  73. )
  74. , xpr_test_case
  75. (
  76. "test28"
  77. , L("a^b")
  78. , regex_type(as_xpr(L("a^b")))
  79. , backrefs(L("a^b"), nilbr)
  80. )
  81. , xpr_test_case
  82. (
  83. "test29"
  84. , L("a^b")
  85. , regex_type(L('a') >> ~set[L(' ')] >> L('b'))
  86. , backrefs(L("a^b"), nilbr)
  87. )
  88. , xpr_test_case
  89. (
  90. "test30"
  91. , L("a^b")
  92. , regex_type(L('a') >> ~set[L('^')] >> L('b'))
  93. , no_match
  94. )
  95. , xpr_test_case
  96. (
  97. "test31"
  98. , L("a^b")
  99. , regex_type(L('a') >> ~set[L('^')] >> L('b'))
  100. , no_match
  101. )
  102. , xpr_test_case
  103. (
  104. "test31.1"
  105. , L("a^b")
  106. , regex_type(L('a') >> set[L('^')] >> L('b'))
  107. , backrefs(L("a^b"), nilbr)
  108. )
  109. , xpr_test_case
  110. (
  111. "test32"
  112. , L("foobazFOObar")
  113. , regex_type(icase(L("foo") >> before(L("bar"))))
  114. , backrefs(L("FOO"), nilbr)
  115. )
  116. , xpr_test_case
  117. (
  118. "test33"
  119. , L("foobarFOObaz")
  120. , regex_type(icase(L("foo") >> ~before(L("bar"))))
  121. , backrefs(L("FOO"), nilbr)
  122. )
  123. , xpr_test_case
  124. (
  125. "test34"
  126. , L("foobarFOO")
  127. , regex_type(icase(L("foo") >> ~before(L("bar"))))
  128. , backrefs(L("FOO"), nilbr)
  129. )
  130. , xpr_test_case
  131. (
  132. "test35"
  133. , L("foobarFOObarfoo")
  134. , regex_type(icase(+(s1= keep(s2= L("foo")) >> L("bar"))))
  135. , backrefs(L("foobarFOObar"), L("FOObar"), L("FOO"), nilbr)
  136. )
  137. , xpr_test_case
  138. (
  139. "test37"
  140. , L("foobar")
  141. , regex_type(+(s1= L("bar") | (s2= L("foo"))))
  142. , backrefs(L("foobar"), L("bar"), L("foo"), nilbr)
  143. )
  144. , xpr_test_case
  145. (
  146. "test38"
  147. , L("foobar")
  148. , regex_type(+(s1= (s2= L("bar")) | L("foo")))
  149. , backrefs(L("foobar"), L("bar"), L("bar"), nilbr)
  150. )
  151. , xpr_test_case
  152. (
  153. "test39"
  154. , L("foobar")
  155. , regex_type(+(s1= L("foo") | (s2= L("bar"))))
  156. , backrefs(L("foobar"), L("bar"), L("bar"), nilbr)
  157. )
  158. , xpr_test_case
  159. (
  160. "test40"
  161. , L("foobar")
  162. , regex_type(+(s1= (s2= L("foo")) | L("bar")))
  163. , backrefs(L("foobar"), L("bar"), L("foo"), nilbr)
  164. )
  165. };
  166. return boost::make_iterator_range(test_cases);
  167. }