test_sets.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /*
  2. *
  3. * Copyright (c) 2004
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. #include "test.hpp"
  12. #ifdef BOOST_MSVC
  13. #pragma warning(disable:4127)
  14. #endif
  15. void test_sets()
  16. {
  17. using namespace boost::regex_constants;
  18. // now test the set operator []
  19. TEST_REGEX_SEARCH("[abc]", boost::regex::extended, "a", match_default, make_array(0, 1, -2, -2));
  20. TEST_REGEX_SEARCH("[abc]", boost::regex::extended, "b", match_default, make_array(0, 1, -2, -2));
  21. TEST_REGEX_SEARCH("[abc]", boost::regex::extended, "c", match_default, make_array(0, 1, -2, -2));
  22. TEST_REGEX_SEARCH("[abc]", boost::regex::extended, "d", match_default, make_array(-2, -2));
  23. TEST_REGEX_SEARCH("[^bcd]", boost::regex::extended, "a", match_default, make_array(0, 1, -2, -2));
  24. TEST_REGEX_SEARCH("[^bcd]", boost::regex::extended, "b", match_default, make_array(-2, -2));
  25. TEST_REGEX_SEARCH("[^bcd]", boost::regex::extended, "d", match_default, make_array(-2, -2));
  26. TEST_REGEX_SEARCH("[^bcd]", boost::regex::extended, "e", match_default, make_array(0, 1, -2, -2));
  27. TEST_REGEX_SEARCH("a[b]c", boost::regex::extended, "abc", match_default, make_array(0, 3, -2, -2));
  28. TEST_REGEX_SEARCH("a[ab]c", boost::regex::extended, "abc", match_default, make_array(0, 3, -2, -2));
  29. TEST_REGEX_SEARCH("a[a^b]*c", boost::regex::extended, "aba^c", match_default, make_array(0, 5, -2, -2));
  30. TEST_REGEX_SEARCH("a[^ab]c", boost::regex::extended, "adc", match_default, make_array(0, 3, -2, -2));
  31. TEST_REGEX_SEARCH("a[]b]c", boost::regex::extended, "a]c", match_default, make_array(0, 3, -2, -2));
  32. TEST_REGEX_SEARCH("a[[b]c", boost::regex::extended, "a[c", match_default, make_array(0, 3, -2, -2));
  33. TEST_REGEX_SEARCH("a[-b]c", boost::regex::extended, "a-c", match_default, make_array(0, 3, -2, -2));
  34. TEST_REGEX_SEARCH("a[^]b]c", boost::regex::extended, "adc", match_default, make_array(0, 3, -2, -2));
  35. TEST_REGEX_SEARCH("a[^-b]c", boost::regex::extended, "adc", match_default, make_array(0, 3, -2, -2));
  36. TEST_REGEX_SEARCH("a[b-]c", boost::regex::extended, "a-c", match_default, make_array(0, 3, -2, -2));
  37. TEST_REGEX_SEARCH("a[a-z-]c", boost::regex::extended, "a-c", match_default, make_array(0, 3, -2, -2));
  38. TEST_REGEX_SEARCH("a[a-z-]+c", boost::regex::extended, "aaz-c", match_default, make_array(0, 5, -2, -2));
  39. TEST_INVALID_REGEX("a[b", boost::regex::extended);
  40. TEST_INVALID_REGEX("a[", boost::regex::extended);
  41. TEST_INVALID_REGEX("a[]", boost::regex::extended);
  42. // now some ranges:
  43. TEST_REGEX_SEARCH("[b-e]", boost::regex::extended, "a", match_default, make_array(-2, -2));
  44. TEST_REGEX_SEARCH("[b-e]", boost::regex::extended, "b", match_default, make_array(0, 1, -2, -2));
  45. TEST_REGEX_SEARCH("[b-e]", boost::regex::extended, "e", match_default, make_array(0, 1, -2, -2));
  46. TEST_REGEX_SEARCH("[b-e]", boost::regex::extended, "f", match_default, make_array(-2, -2));
  47. TEST_REGEX_SEARCH("[^b-e]", boost::regex::extended, "a", match_default, make_array(0, 1, -2, -2));
  48. TEST_REGEX_SEARCH("[^b-e]", boost::regex::extended, "b", match_default, make_array(-2, -2));
  49. TEST_REGEX_SEARCH("[^b-e]", boost::regex::extended, "e", match_default, make_array(-2, -2));
  50. TEST_REGEX_SEARCH("[^b-e]", boost::regex::extended, "f", match_default, make_array(0, 1, -2, -2));
  51. TEST_REGEX_SEARCH("a[1-3]c", boost::regex::extended, "a2c", match_default, make_array(0, 3, -2, -2));
  52. TEST_REGEX_SEARCH("a[-3]c", boost::regex::extended, "a-c", match_default, make_array(0, 3, -2, -2));
  53. TEST_REGEX_SEARCH("a[-3]c", boost::regex::extended, "a3c", match_default, make_array(0, 3, -2, -2));
  54. TEST_REGEX_SEARCH("a[^-3]c", boost::regex::extended, "a-c", match_default, make_array(-2, -2));
  55. TEST_REGEX_SEARCH("a[^-3]c", boost::regex::extended, "a3c", match_default, make_array(-2, -2));
  56. TEST_REGEX_SEARCH("a[^-3]c", boost::regex::extended, "axc", match_default, make_array(0, 3, -2, -2));
  57. TEST_INVALID_REGEX("a[3-1]c", boost::regex::extended & ~::boost::regex_constants::collate);
  58. TEST_INVALID_REGEX("a[1-3-5]c", boost::regex::extended);
  59. TEST_INVALID_REGEX("a[1-", boost::regex::extended);
  60. TEST_INVALID_REGEX("a[\\9]", perl);
  61. // and some classes
  62. TEST_REGEX_SEARCH("a[[:alpha:]]c", boost::regex::extended, "abc", match_default, make_array(0, 3, -2, -2));
  63. TEST_INVALID_REGEX("a[[:unknown:]]c", boost::regex::extended);
  64. TEST_INVALID_REGEX("a[[", boost::regex::extended);
  65. TEST_INVALID_REGEX("a[[:", boost::regex::extended);
  66. TEST_INVALID_REGEX("a[[:a", boost::regex::extended);
  67. TEST_INVALID_REGEX("a[[:alpha", boost::regex::extended);
  68. TEST_INVALID_REGEX("a[[:alpha:", boost::regex::extended);
  69. TEST_INVALID_REGEX("a[[:alpha:]", boost::regex::extended);
  70. TEST_INVALID_REGEX("a[[:alpha:!", boost::regex::extended);
  71. TEST_INVALID_REGEX("a[[:alpha,:]", boost::regex::extended);
  72. TEST_INVALID_REGEX("a[[:]:]]b", boost::regex::extended);
  73. TEST_INVALID_REGEX("a[[:-:]]b", boost::regex::extended);
  74. TEST_INVALID_REGEX("a[[:alph:]]", boost::regex::extended);
  75. TEST_INVALID_REGEX("a[[:alphabet:]]", boost::regex::extended);
  76. TEST_REGEX_SEARCH("[[:alnum:]]+", boost::regex::extended, "-%@a0X_-", match_default, make_array(3, 6, -2, -2));
  77. TEST_REGEX_SEARCH("[[:alpha:]]+", boost::regex::extended, " -%@aX_0-", match_default, make_array(4, 6, -2, -2));
  78. TEST_REGEX_SEARCH("[[:blank:]]+", boost::regex::extended, "a \tb", match_default, make_array(1, 4, -2, -2));
  79. TEST_REGEX_SEARCH("[[:cntrl:]]+", boost::regex::extended, " a\n\tb", match_default, make_array(2, 4, -2, -2));
  80. TEST_REGEX_SEARCH("[[:digit:]]+", boost::regex::extended, "a019b", match_default, make_array(1, 4, -2, -2));
  81. TEST_REGEX_SEARCH("[[:graph:]]+", boost::regex::extended, " a%b ", match_default, make_array(1, 4, -2, -2));
  82. TEST_REGEX_SEARCH("[[:lower:]]+", boost::regex::extended, "AabC", match_default, make_array(1, 3, -2, -2));
  83. TEST_REGEX_SEARCH("[[:print:]]+", boost::regex::extended, "AabC", match_default, make_array(0, 4, -2, -2));
  84. TEST_REGEX_SEARCH("[[:punct:]]+", boost::regex::extended, " %-&\t", match_default, make_array(1, 4, -2, -2));
  85. TEST_REGEX_SEARCH("[[:space:]]+", boost::regex::extended, "a \n\t\rb", match_default, make_array(1, 5, -2, -2));
  86. TEST_REGEX_SEARCH("[[:upper:]]+", boost::regex::extended, "aBCd", match_default, make_array(1, 3, -2, -2));
  87. TEST_REGEX_SEARCH("[[:xdigit:]]+", boost::regex::extended, "p0f3Cx", match_default, make_array(1, 5, -2, -2));
  88. TEST_REGEX_SEARCH("[\\d]+", perl, "a019b", match_default, make_array(1, 4, -2, -2));
  89. //
  90. // escapes are supported in character classes if we have either
  91. // perl or awk regular expressions:
  92. //
  93. TEST_REGEX_SEARCH("[\\n]", perl, "\n", match_default, make_array(0, 1, -2, -2));
  94. TEST_REGEX_SEARCH("[\\b]", perl, "\b", match_default, make_array(0, 1, -2, -2));
  95. TEST_REGEX_SEARCH("[\\n]", basic, "\n", match_default, make_array(-2, -2));
  96. TEST_REGEX_SEARCH("[\\n]", basic, "\\", match_default, make_array(0, 1, -2, -2));
  97. TEST_REGEX_SEARCH("[[:class:]", basic|no_char_classes, ":", match_default, make_array(0, 1, -2, -2));
  98. TEST_REGEX_SEARCH("[[:class:]", basic|no_char_classes, "[", match_default, make_array(0, 1, -2, -2));
  99. TEST_REGEX_SEARCH("[[:class:]", basic|no_char_classes, "c", match_default, make_array(0, 1, -2, -2));
  100. //
  101. // test single character escapes:
  102. //
  103. TEST_REGEX_SEARCH("\\w", perl, "A", match_default, make_array(0, 1, -2, -2));
  104. TEST_REGEX_SEARCH("\\w", perl, "Z", match_default, make_array(0, 1, -2, -2));
  105. TEST_REGEX_SEARCH("\\w", perl, "a", match_default, make_array(0, 1, -2, -2));
  106. TEST_REGEX_SEARCH("\\w", perl, "z", match_default, make_array(0, 1, -2, -2));
  107. TEST_REGEX_SEARCH("\\w", perl, "_", match_default, make_array(0, 1, -2, -2));
  108. TEST_REGEX_SEARCH("\\w", perl, "}", match_default, make_array(-2, -2));
  109. TEST_REGEX_SEARCH("\\w", perl, "`", match_default, make_array(-2, -2));
  110. TEST_REGEX_SEARCH("\\w", perl, "[", match_default, make_array(-2, -2));
  111. TEST_REGEX_SEARCH("\\w", perl, "@", match_default, make_array(-2, -2));
  112. TEST_REGEX_SEARCH("\\W", perl, "a", match_default, make_array(-2, -2));
  113. TEST_REGEX_SEARCH("\\W", perl, "z", match_default, make_array(-2, -2));
  114. TEST_REGEX_SEARCH("\\W", perl, "A", match_default, make_array(-2, -2));
  115. TEST_REGEX_SEARCH("\\W", perl, "Z", match_default, make_array(-2, -2));
  116. TEST_REGEX_SEARCH("\\W", perl, "_", match_default, make_array(-2, -2));
  117. TEST_REGEX_SEARCH("\\W", perl, "}", match_default, make_array(0, 1, -2, -2));
  118. TEST_REGEX_SEARCH("\\W", perl, "`", match_default, make_array(0, 1, -2, -2));
  119. TEST_REGEX_SEARCH("\\W", perl, "[", match_default, make_array(0, 1, -2, -2));
  120. TEST_REGEX_SEARCH("\\W", perl, "@", match_default, make_array(0, 1, -2, -2));
  121. TEST_REGEX_SEARCH("[[:lower:]]", perl|icase, "A", match_default, make_array(0, 1, -2, -2));
  122. TEST_REGEX_SEARCH("[[:upper:]]", perl|icase, "A", match_default, make_array(0, 1, -2, -2));
  123. TEST_REGEX_SEARCH("[[:alpha:]]", perl|icase, "A", match_default, make_array(0, 1, -2, -2));
  124. TEST_REGEX_SEARCH("[[:alnum:]]", perl|icase, "A", match_default, make_array(0, 1, -2, -2));
  125. TEST_REGEX_SEARCH("[[:lower:]]", perl|icase, "a", match_default, make_array(0, 1, -2, -2));
  126. TEST_REGEX_SEARCH("[[:upper:]]", perl|icase, "a", match_default, make_array(0, 1, -2, -2));
  127. TEST_REGEX_SEARCH("[[:alpha:]]", perl|icase, "a", match_default, make_array(0, 1, -2, -2));
  128. TEST_REGEX_SEARCH("[[:alnum:]]", perl|icase, "a", match_default, make_array(0, 1, -2, -2));
  129. TEST_REGEX_SEARCH("[[:lower:][:upper:]]", perl, "A", match_default, make_array(0, 1, -2, -2));
  130. TEST_REGEX_SEARCH("[[:lower:][:upper:]]", perl, "a", match_default, make_array(0, 1, -2, -2));
  131. TEST_REGEX_SEARCH("[[:lower:][:alpha:]]", perl, "A", match_default, make_array(0, 1, -2, -2));
  132. TEST_REGEX_SEARCH("[[:lower:][:alpha:]]", perl, "a", match_default, make_array(0, 1, -2, -2));
  133. }
  134. void test_sets2b();
  135. void test_sets2c();
  136. void test_sets2()
  137. {
  138. using namespace boost::regex_constants;
  139. // collating elements
  140. TEST_REGEX_SEARCH("[[.zero.]]", perl, "0", match_default, make_array(0, 1, -2, -2));
  141. TEST_REGEX_SEARCH("[[.one.]]", perl, "1", match_default, make_array(0, 1, -2, -2));
  142. TEST_REGEX_SEARCH("[[.two.]]", perl, "2", match_default, make_array(0, 1, -2, -2));
  143. TEST_REGEX_SEARCH("[[.three.]]", perl, "3", match_default, make_array(0, 1, -2, -2));
  144. TEST_REGEX_SEARCH("[[.a.]]", perl, "bac", match_default, make_array(1, 2, -2, -2));
  145. TEST_REGEX_SEARCH("[[.\xf0.]]", perl, "b\xf0x", match_default, make_array(1, 2, -2, -2));
  146. TEST_REGEX_SEARCH("[[.right-curly-bracket.]]", perl, "}", match_default, make_array(0, 1, -2, -2));
  147. TEST_REGEX_SEARCH("[[.NUL.]]", perl, "\0", match_default, make_array(0, 1, -2, -2));
  148. TEST_REGEX_SEARCH("[[.NUL.][.ae.]]", perl, "\0", match_default, make_array(0, 1, -2, -2));
  149. TEST_REGEX_SEARCH("[[.NUL.]-a]", boost::regex::extended, "\0", match_default, make_array(0, 1, -2, -2));
  150. TEST_REGEX_SEARCH("[[.NUL.]-a]", perl, "\0", match_default, make_array(0, 1, -2, -2));
  151. TEST_REGEX_SEARCH("[[.NUL.]-a]", boost::regex::extended, "a", match_default, make_array(0, 1, -2, -2));
  152. TEST_REGEX_SEARCH("[[.NUL.]-a]", perl, "a", match_default, make_array(0, 1, -2, -2));
  153. TEST_REGEX_SEARCH("[[.NUL.]-[.NUL.]a]", boost::regex::extended, "a", match_default, make_array(0, 1, -2, -2));
  154. TEST_REGEX_SEARCH("[[.NUL.]-[.NUL.]a]", perl, "a", match_default, make_array(0, 1, -2, -2));
  155. TEST_INVALID_REGEX("[[..]]", perl);
  156. TEST_INVALID_REGEX("[[.not-a-collating-element.]]", perl);
  157. TEST_INVALID_REGEX("[[.", perl);
  158. TEST_INVALID_REGEX("[[.N", perl);
  159. TEST_INVALID_REGEX("[[.NUL", perl);
  160. TEST_INVALID_REGEX("[[.NUL.", perl);
  161. TEST_INVALID_REGEX("[[.NUL.]", perl);
  162. TEST_INVALID_REGEX("[[:<:]z]", perl);
  163. TEST_INVALID_REGEX("[a[:>:]]", perl);
  164. TEST_REGEX_SEARCH("[[.A.]]", boost::regex::extended|icase, "A", match_default, make_array(0, 1, -2, -2));
  165. TEST_REGEX_SEARCH("[[.A.]]", boost::regex::extended|icase, "a", match_default, make_array(0, 1, -2, -2));
  166. TEST_REGEX_SEARCH("[[.A.]-b]+", boost::regex::extended|icase, "AaBb", match_default, make_array(0, 4, -2, -2));
  167. TEST_REGEX_SEARCH("[A-[.b.]]+", boost::regex::extended|icase, "AaBb", match_default, make_array(0, 4, -2, -2));
  168. TEST_REGEX_SEARCH("[[.a.]-B]+", boost::regex::extended|icase, "AaBb", match_default, make_array(0, 4, -2, -2));
  169. TEST_REGEX_SEARCH("[a-[.B.]]+", boost::regex::extended|icase, "AaBb", match_default, make_array(0, 4, -2, -2));
  170. TEST_REGEX_SEARCH("[\x61]", boost::regex::extended, "a", match_default, make_array(0, 1, -2, -2));
  171. TEST_REGEX_SEARCH("[\x61-c]+", boost::regex::extended, "abcd", match_default, make_array(0, 3, -2, -2));
  172. TEST_REGEX_SEARCH("[a-\x63]+", boost::regex::extended, "abcd", match_default, make_array(0, 3, -2, -2));
  173. TEST_REGEX_SEARCH("[[.a.]-c]+", boost::regex::extended, "abcd", match_default, make_array(0, 3, -2, -2));
  174. TEST_REGEX_SEARCH("[a-[.c.]]+", boost::regex::extended, "abcd", match_default, make_array(0, 3, -2, -2));
  175. TEST_INVALID_REGEX("[[:alpha:]-a]", boost::regex::extended);
  176. TEST_INVALID_REGEX("[a-[:alpha:]]", boost::regex::extended);
  177. TEST_REGEX_SEARCH("[[.ae.]]", basic, "ae", match_default, make_array(0, 2, -2, -2));
  178. TEST_REGEX_SEARCH("[[.ae.]]", basic, "aE", match_default, make_array(-2, -2));
  179. TEST_REGEX_SEARCH("[[.AE.]]", basic, "AE", match_default, make_array(0, 2, -2, -2));
  180. TEST_REGEX_SEARCH("[[.Ae.]]", basic, "Ae", match_default, make_array(0, 2, -2, -2));
  181. TEST_REGEX_SEARCH("[[.ae.]-b]", basic, "a", match_default, make_array(-2, -2));
  182. TEST_REGEX_SEARCH("[[.ae.]-b]", basic, "b", match_default, make_array(0, 1, -2, -2));
  183. TEST_REGEX_SEARCH("[[.ae.]-b]", basic, "ae", match_default, make_array(0, 2, -2, -2));
  184. TEST_REGEX_SEARCH("[a-[.ae.]]", basic, "a", match_default, make_array(0, 1, -2, -2));
  185. TEST_REGEX_SEARCH("[a-[.ae.]]", basic, "b", match_default, make_array(-2, -2));
  186. TEST_REGEX_SEARCH("[a-[.ae.]]", basic, "ae", match_default, make_array(0, 2, -2, -2));
  187. TEST_REGEX_SEARCH("[[.ae.]]", basic|icase, "AE", match_default, make_array(0, 2, -2, -2));
  188. TEST_REGEX_SEARCH("[[.ae.]]", basic|icase, "Ae", match_default, make_array(0, 2, -2, -2));
  189. TEST_REGEX_SEARCH("[[.AE.]]", basic|icase, "Ae", match_default, make_array(0, 2, -2, -2));
  190. TEST_REGEX_SEARCH("[[.Ae.]]", basic|icase, "aE", match_default, make_array(0, 2, -2, -2));
  191. TEST_REGEX_SEARCH("[[.AE.]-B]", basic|icase, "a", match_default, make_array(-2, -2));
  192. TEST_REGEX_SEARCH("[[.Ae.]-b]", basic|icase, "b", match_default, make_array(0, 1, -2, -2));
  193. TEST_REGEX_SEARCH("[[.Ae.]-b]", basic|icase, "B", match_default, make_array(0, 1, -2, -2));
  194. TEST_REGEX_SEARCH("[[.ae.]-b]", basic|icase, "AE", match_default, make_array(0, 2, -2, -2));
  195. TEST_REGEX_SEARCH("[[.ae.]]", perl, "ae", match_default, make_array(0, 2, -2, -2));
  196. TEST_REGEX_SEARCH("[[.ae.]]", perl, "aE", match_default, make_array(-2, -2));
  197. TEST_REGEX_SEARCH("[[.AE.]]", perl, "AE", match_default, make_array(0, 2, -2, -2));
  198. TEST_REGEX_SEARCH("[[.Ae.]]", perl, "Ae", match_default, make_array(0, 2, -2, -2));
  199. TEST_REGEX_SEARCH("[[.ae.]-b]", perl, "a", match_default, make_array(-2, -2));
  200. TEST_REGEX_SEARCH("[[.ae.]-b]", perl, "b", match_default, make_array(0, 1, -2, -2));
  201. TEST_REGEX_SEARCH("[[.ae.]-b]", perl, "ae", match_default, make_array(0, 2, -2, -2));
  202. TEST_REGEX_SEARCH("[a-[.ae.]]", perl, "a", match_default, make_array(0, 1, -2, -2));
  203. TEST_REGEX_SEARCH("[a-[.ae.]]", perl, "b", match_default, make_array(-2, -2));
  204. TEST_REGEX_SEARCH("[a-[.ae.]]", perl, "ae", match_default, make_array(0, 2, -2, -2));
  205. TEST_REGEX_SEARCH("[[.ae.]]", perl|icase, "AE", match_default, make_array(0, 2, -2, -2));
  206. TEST_REGEX_SEARCH("[[.ae.]]", perl|icase, "Ae", match_default, make_array(0, 2, -2, -2));
  207. TEST_REGEX_SEARCH("[[.AE.]]", perl|icase, "Ae", match_default, make_array(0, 2, -2, -2));
  208. TEST_REGEX_SEARCH("[[.Ae.]]", perl|icase, "aE", match_default, make_array(0, 2, -2, -2));
  209. TEST_REGEX_SEARCH("[[.AE.]-B]", perl|icase, "a", match_default, make_array(-2, -2));
  210. TEST_REGEX_SEARCH("[[.Ae.]-b]", perl|icase, "b", match_default, make_array(0, 1, -2, -2));
  211. TEST_REGEX_SEARCH("[[.Ae.]-b]", perl|icase, "B", match_default, make_array(0, 1, -2, -2));
  212. TEST_REGEX_SEARCH("[[.ae.]-b]", perl|icase, "AE", match_default, make_array(0, 2, -2, -2));
  213. TEST_REGEX_SEARCH("[[.ae.][:lower:]]", perl|icase, "AE", match_default, make_array(0, 2, -2, -2));
  214. TEST_REGEX_SEARCH("[[.ae.][:lower:]]", perl|icase, "A", match_default, make_array(0, 1, -2, -2));
  215. TEST_REGEX_SEARCH("[[.ae.][=a=]]+", perl, "zzaA", match_default, make_array(2, 4, -2, -2));
  216. TEST_INVALID_REGEX("[d-[.ae.]]", perl);
  217. //
  218. // try some equivalence classes:
  219. //
  220. TEST_REGEX_SEARCH("[[=a=]]", basic, "a", match_default, make_array(0, 1, -2, -2));
  221. TEST_REGEX_SEARCH("[[=a=]]", basic, "A", match_default, make_array(0, 1, -2, -2));
  222. TEST_REGEX_SEARCH("[[=ae=]]", basic, "ae", match_default, make_array(0, 2, -2, -2));
  223. TEST_REGEX_SEARCH("[[=right-curly-bracket=]]", basic, "}", match_default, make_array(0, 1, -2, -2));
  224. TEST_REGEX_SEARCH("[[=NUL=]]", basic, "\x0", match_default, make_array(0, 1, -2, -2));
  225. TEST_REGEX_SEARCH("[[=NUL=]]", perl, "\x0", match_default, make_array(0, 1, -2, -2));
  226. TEST_INVALID_REGEX("[[=", perl);
  227. TEST_INVALID_REGEX("[[=a", perl);
  228. TEST_INVALID_REGEX("[[=ae", perl);
  229. TEST_INVALID_REGEX("[[=ae=", perl);
  230. TEST_INVALID_REGEX("[[=ae=]", perl);
  231. //
  232. // now some perl style single character classes:
  233. //
  234. TEST_REGEX_SEARCH("\\l+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  235. TEST_REGEX_SEARCH("[\\l]+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  236. TEST_INVALID_REGEX("[\\l-a]", perl);
  237. TEST_REGEX_SEARCH("[\\L]+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
  238. TEST_REGEX_SEARCH("[[:^lower:]]+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
  239. TEST_REGEX_SEARCH("\\L+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
  240. TEST_REGEX_SEARCH("\\u+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
  241. TEST_REGEX_SEARCH("[\\u]+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
  242. TEST_REGEX_SEARCH("[\\U]+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  243. TEST_REGEX_SEARCH("[[:^upper:]]+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  244. TEST_REGEX_SEARCH("\\U+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  245. TEST_REGEX_SEARCH("\\d+", perl, "AB012AB", match_default, make_array(2, 5, -2, -2));
  246. TEST_REGEX_SEARCH("[\\d]+", perl, "AB012AB", match_default, make_array(2, 5, -2, -2));
  247. TEST_REGEX_SEARCH("[\\D]+", perl, "01abc01", match_default, make_array(2, 5, -2, -2));
  248. TEST_REGEX_SEARCH("[[:^digit:]]+", perl, "01abc01", match_default, make_array(2, 5, -2, -2));
  249. TEST_REGEX_SEARCH("\\D+", perl, "01abc01", match_default, make_array(2, 5, -2, -2));
  250. TEST_REGEX_SEARCH("\\s+", perl, "AB AB", match_default, make_array(2, 5, -2, -2));
  251. TEST_REGEX_SEARCH("[\\s]+", perl, "AB AB", match_default, make_array(2, 5, -2, -2));
  252. TEST_REGEX_SEARCH("[\\S]+", perl, " abc ", match_default, make_array(2, 5, -2, -2));
  253. TEST_REGEX_SEARCH("[[:^space:]]+", perl, " abc ", match_default, make_array(2, 5, -2, -2));
  254. TEST_REGEX_SEARCH("\\S+", perl, " abc ", match_default, make_array(2, 5, -2, -2));
  255. TEST_REGEX_SEARCH("\\s+", perl, "AB AB", match_default, make_array(2, 5, -2, -2));
  256. TEST_REGEX_SEARCH("[\\w]+", perl, "AB_ AB", match_default, make_array(0, 3, -2, 6, 8, -2, -2));
  257. TEST_REGEX_SEARCH("[\\W]+", perl, "AB_ AB", match_default, make_array(3, 6, -2, -2));
  258. TEST_REGEX_SEARCH("[[:^word:]]+", perl, "AB_ AB", match_default, make_array(3, 6, -2, -2));
  259. TEST_REGEX_SEARCH("\\W+", perl, "AB_ AB", match_default, make_array(3, 6, -2, -2));
  260. TEST_REGEX_SEARCH("\\h+", perl, "\v\f\r\n \t\n", match_default, make_array(4, 6, -2, -2));
  261. TEST_REGEX_SEARCH("\\V+", perl, "\v\f\r\n \t\n", match_default, make_array(4, 6, -2, -2));
  262. TEST_REGEX_SEARCH("\\H+", perl, " \t\v\f\r\n ", match_default, make_array(2, 6, -2, -2));
  263. TEST_REGEX_SEARCH("\\v+", perl, " \t\v\f\r\n ", match_default, make_array(2, 6, -2, -2));
  264. test_sets2c();
  265. }
  266. void test_sets2c()
  267. {
  268. using namespace boost::regex_constants;
  269. // and some Perl style properties:
  270. TEST_REGEX_SEARCH("\\pl+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  271. TEST_REGEX_SEARCH("\\Pl+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
  272. TEST_REGEX_SEARCH("\\pu+", perl, "abABCab", match_default, make_array(2, 5, -2, -2));
  273. TEST_REGEX_SEARCH("\\Pu+", perl, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  274. TEST_REGEX_SEARCH("\\pd+", perl, "AB012AB", match_default, make_array(2, 5, -2, -2));
  275. TEST_REGEX_SEARCH("\\PD+", perl, "01abc01", match_default, make_array(2, 5, -2, -2));
  276. TEST_REGEX_SEARCH("\\ps+", perl, "AB AB", match_default, make_array(2, 5, -2, -2));
  277. TEST_REGEX_SEARCH("\\PS+", perl, " abc ", match_default, make_array(2, 5, -2, -2));
  278. TEST_REGEX_SEARCH("\\p{alnum}+", perl, "-%@a0X_-", match_default, make_array(3, 6, -2, -2));
  279. TEST_REGEX_SEARCH("\\p{alpha}+", perl, " -%@aX_0-", match_default, make_array(4, 6, -2, -2));
  280. TEST_REGEX_SEARCH("\\p{blank}+", perl, "a \tb", match_default, make_array(1, 4, -2, -2));
  281. TEST_REGEX_SEARCH("\\p{cntrl}+", perl, " a\n\tb", match_default, make_array(2, 4, -2, -2));
  282. TEST_REGEX_SEARCH("\\p{digit}+", perl, "a019b", match_default, make_array(1, 4, -2, -2));
  283. TEST_REGEX_SEARCH("\\p{graph}+", perl, " a%b ", match_default, make_array(1, 4, -2, -2));
  284. TEST_REGEX_SEARCH("\\p{lower}+", perl, "AabC", match_default, make_array(1, 3, -2, -2));
  285. TEST_REGEX_SEARCH("\\p{print}+", perl, "AabC", match_default, make_array(0, 4, -2, -2));
  286. TEST_REGEX_SEARCH("\\p{punct}+", perl, " %-&\t", match_default, make_array(1, 4, -2, -2));
  287. TEST_REGEX_SEARCH("\\p{space}+", perl, "a \n\t\rb", match_default, make_array(1, 5, -2, -2));
  288. TEST_REGEX_SEARCH("\\p{upper}+", perl, "aBCd", match_default, make_array(1, 3, -2, -2));
  289. TEST_REGEX_SEARCH("\\p{xdigit}+", perl, "p0f3Cx", match_default, make_array(1, 5, -2, -2));
  290. TEST_REGEX_SEARCH("\\P{alnum}+", perl, "-%@a", match_default, make_array(0, 3, -2, -2));
  291. TEST_REGEX_SEARCH("\\P{alpha}+", perl, " -%@a", match_default, make_array(0, 4, -2, -2));
  292. TEST_REGEX_SEARCH("\\P{blank}+", perl, "a ", match_default, make_array(0, 1, -2, -2));
  293. TEST_REGEX_SEARCH("\\P{cntrl}+", perl, " a\n", match_default, make_array(0, 2, -2, -2));
  294. TEST_REGEX_SEARCH("\\P{digit}+", perl, "a0", match_default, make_array(0, 1, -2, -2));
  295. TEST_REGEX_SEARCH("\\P{graph}+", perl, " a", match_default, make_array(0, 1, -2, -2));
  296. TEST_REGEX_SEARCH("\\P{lower}+", perl, "Aa", match_default, make_array(0, 1, -2, -2));
  297. TEST_REGEX_SEARCH("\\P{print}+", perl, "Absc", match_default, make_array(-2, -2));
  298. TEST_REGEX_SEARCH("\\P{punct}+", perl, " %", match_default, make_array(0, 1, -2, -2));
  299. TEST_REGEX_SEARCH("\\P{space}+", perl, "a ", match_default, make_array(0, 1, -2, -2));
  300. TEST_REGEX_SEARCH("\\P{upper}+", perl, "aB", match_default, make_array(0, 1, -2, -2));
  301. TEST_REGEX_SEARCH("\\P{xdigit}+", perl, "pf", match_default, make_array(0, 1, -2, -2));
  302. TEST_INVALID_REGEX("\\p{invalid class}", perl);
  303. TEST_INVALID_REGEX("\\p{upper", perl);
  304. TEST_INVALID_REGEX("\\p{", perl);
  305. TEST_INVALID_REGEX("\\p", perl);
  306. TEST_INVALID_REGEX("\\P{invalid class}", perl);
  307. TEST_INVALID_REGEX("\\P{upper", perl);
  308. TEST_INVALID_REGEX("\\P{", perl);
  309. TEST_INVALID_REGEX("\\P", perl);
  310. // try named characters:
  311. TEST_REGEX_SEARCH("\\N{zero}", perl, "0", match_default, make_array(0, 1, -2, -2));
  312. TEST_REGEX_SEARCH("\\N{one}", perl, "1", match_default, make_array(0, 1, -2, -2));
  313. TEST_REGEX_SEARCH("\\N{two}", perl, "2", match_default, make_array(0, 1, -2, -2));
  314. TEST_REGEX_SEARCH("\\N{three}", perl, "3", match_default, make_array(0, 1, -2, -2));
  315. TEST_REGEX_SEARCH("\\N{a}", perl, "bac", match_default, make_array(1, 2, -2, -2));
  316. TEST_REGEX_SEARCH("\\N{\xf0}", perl, "b\xf0x", match_default, make_array(1, 2, -2, -2));
  317. TEST_REGEX_SEARCH("\\N{right-curly-bracket}", perl, "}", match_default, make_array(0, 1, -2, -2));
  318. TEST_REGEX_SEARCH("\\N{NUL}", perl, "\0", match_default, make_array(0, 1, -2, -2));
  319. TEST_REGEX_SEARCH("[\\N{zero}-\\N{nine}]+", perl, " 0123456789 ", match_default, make_array(1, 11, -2, -2));
  320. TEST_INVALID_REGEX("\\N", perl);
  321. TEST_INVALID_REGEX("\\N{", perl);
  322. TEST_INVALID_REGEX("\\N{}", perl);
  323. TEST_INVALID_REGEX("\\N{invalid-name}", perl);
  324. TEST_INVALID_REGEX("\\N{zero", perl);
  325. test_sets2b();
  326. }
  327. void test_sets2b()
  328. {
  329. using namespace boost::regex_constants;
  330. // and repeat with POSIX-boost::regex::extended syntax:
  331. TEST_REGEX_SEARCH("\\pl+", boost::regex::extended, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  332. TEST_REGEX_SEARCH("\\Pl+", boost::regex::extended, "abABCab", match_default, make_array(2, 5, -2, -2));
  333. TEST_REGEX_SEARCH("\\pu+", boost::regex::extended, "abABCab", match_default, make_array(2, 5, -2, -2));
  334. TEST_REGEX_SEARCH("\\Pu+", boost::regex::extended, "ABabcAB", match_default, make_array(2, 5, -2, -2));
  335. TEST_REGEX_SEARCH("\\pd+", boost::regex::extended, "AB012AB", match_default, make_array(2, 5, -2, -2));
  336. TEST_REGEX_SEARCH("\\PD+", boost::regex::extended, "01abc01", match_default, make_array(2, 5, -2, -2));
  337. TEST_REGEX_SEARCH("\\ps+", boost::regex::extended, "AB AB", match_default, make_array(2, 5, -2, -2));
  338. TEST_REGEX_SEARCH("\\PS+", boost::regex::extended, " abc ", match_default, make_array(2, 5, -2, -2));
  339. TEST_REGEX_SEARCH("\\p{alnum}+", boost::regex::extended, "-%@a0X_-", match_default, make_array(3, 6, -2, -2));
  340. TEST_REGEX_SEARCH("\\p{alpha}+", boost::regex::extended, " -%@aX_0-", match_default, make_array(4, 6, -2, -2));
  341. TEST_REGEX_SEARCH("\\p{blank}+", boost::regex::extended, "a \tb", match_default, make_array(1, 4, -2, -2));
  342. TEST_REGEX_SEARCH("\\p{cntrl}+", boost::regex::extended, " a\n\tb", match_default, make_array(2, 4, -2, -2));
  343. TEST_REGEX_SEARCH("\\p{digit}+", boost::regex::extended, "a019b", match_default, make_array(1, 4, -2, -2));
  344. TEST_REGEX_SEARCH("\\p{graph}+", boost::regex::extended, " a%b ", match_default, make_array(1, 4, -2, -2));
  345. TEST_REGEX_SEARCH("\\p{lower}+", boost::regex::extended, "AabC", match_default, make_array(1, 3, -2, -2));
  346. TEST_REGEX_SEARCH("\\p{print}+", boost::regex::extended, "AabC", match_default, make_array(0, 4, -2, -2));
  347. TEST_REGEX_SEARCH("\\p{punct}+", boost::regex::extended, " %-&\t", match_default, make_array(1, 4, -2, -2));
  348. TEST_REGEX_SEARCH("\\p{space}+", boost::regex::extended, "a \n\t\rb", match_default, make_array(1, 5, -2, -2));
  349. TEST_REGEX_SEARCH("\\p{upper}+", boost::regex::extended, "aBCd", match_default, make_array(1, 3, -2, -2));
  350. TEST_REGEX_SEARCH("\\p{xdigit}+", boost::regex::extended, "p0f3Cx", match_default, make_array(1, 5, -2, -2));
  351. TEST_REGEX_SEARCH("\\P{alnum}+", boost::regex::extended, "-%@a", match_default, make_array(0, 3, -2, -2));
  352. TEST_REGEX_SEARCH("\\P{alpha}+", boost::regex::extended, " -%@a", match_default, make_array(0, 4, -2, -2));
  353. TEST_REGEX_SEARCH("\\P{blank}+", boost::regex::extended, "a ", match_default, make_array(0, 1, -2, -2));
  354. TEST_REGEX_SEARCH("\\P{cntrl}+", boost::regex::extended, " a\n", match_default, make_array(0, 2, -2, -2));
  355. TEST_REGEX_SEARCH("\\P{digit}+", boost::regex::extended, "a0", match_default, make_array(0, 1, -2, -2));
  356. TEST_REGEX_SEARCH("\\P{graph}+", boost::regex::extended, " a", match_default, make_array(0, 1, -2, -2));
  357. TEST_REGEX_SEARCH("\\P{lower}+", boost::regex::extended, "Aa", match_default, make_array(0, 1, -2, -2));
  358. TEST_REGEX_SEARCH("\\P{print}+", boost::regex::extended, "Absc", match_default, make_array(-2, -2));
  359. TEST_REGEX_SEARCH("\\P{punct}+", boost::regex::extended, " %", match_default, make_array(0, 1, -2, -2));
  360. TEST_REGEX_SEARCH("\\P{space}+", boost::regex::extended, "a ", match_default, make_array(0, 1, -2, -2));
  361. TEST_REGEX_SEARCH("\\P{upper}+", boost::regex::extended, "aB", match_default, make_array(0, 1, -2, -2));
  362. TEST_REGEX_SEARCH("\\P{xdigit}+", boost::regex::extended, "pf", match_default, make_array(0, 1, -2, -2));
  363. TEST_INVALID_REGEX("\\p{invalid class}", boost::regex::extended);
  364. TEST_INVALID_REGEX("\\p{upper", boost::regex::extended);
  365. TEST_INVALID_REGEX("\\p{", boost::regex::extended);
  366. TEST_INVALID_REGEX("\\p", boost::regex::extended);
  367. TEST_INVALID_REGEX("\\P{invalid class}", boost::regex::extended);
  368. TEST_INVALID_REGEX("\\P{upper", boost::regex::extended);
  369. TEST_INVALID_REGEX("\\P{", boost::regex::extended);
  370. TEST_INVALID_REGEX("\\P", boost::regex::extended);
  371. // try named characters:
  372. TEST_REGEX_SEARCH("\\N{zero}", boost::regex::extended, "0", match_default, make_array(0, 1, -2, -2));
  373. TEST_REGEX_SEARCH("\\N{one}", boost::regex::extended, "1", match_default, make_array(0, 1, -2, -2));
  374. TEST_REGEX_SEARCH("\\N{two}", boost::regex::extended, "2", match_default, make_array(0, 1, -2, -2));
  375. TEST_REGEX_SEARCH("\\N{three}", boost::regex::extended, "3", match_default, make_array(0, 1, -2, -2));
  376. TEST_REGEX_SEARCH("\\N{a}", boost::regex::extended, "bac", match_default, make_array(1, 2, -2, -2));
  377. TEST_REGEX_SEARCH("\\N{\xf0}", boost::regex::extended, "b\xf0x", match_default, make_array(1, 2, -2, -2));
  378. TEST_REGEX_SEARCH("\\N{right-curly-bracket}", boost::regex::extended, "}", match_default, make_array(0, 1, -2, -2));
  379. TEST_REGEX_SEARCH("\\N{NUL}", boost::regex::extended, "\0", match_default, make_array(0, 1, -2, -2));
  380. TEST_INVALID_REGEX("\\N", boost::regex::extended);
  381. TEST_INVALID_REGEX("\\N{", boost::regex::extended);
  382. TEST_INVALID_REGEX("\\N{}", boost::regex::extended);
  383. TEST_INVALID_REGEX("\\N{invalid-name}", boost::regex::extended);
  384. TEST_INVALID_REGEX("\\N{zero", boost::regex::extended);
  385. }