ecma.pass.cpp 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // NetBSD does not support LC_COLLATE at the moment
  10. // XFAIL: netbsd
  11. // REQUIRES: locale.cs_CZ.ISO8859-2
  12. // <regex>
  13. // template <class BidirectionalIterator, class Allocator, class charT, class traits>
  14. // bool
  15. // regex_match(BidirectionalIterator first, BidirectionalIterator last,
  16. // match_results<BidirectionalIterator, Allocator>& m,
  17. // const basic_regex<charT, traits>& e,
  18. // regex_constants::match_flag_type flags = regex_constants::match_default);
  19. // TODO: investigation needed
  20. // XFAIL: linux-gnu
  21. #include <regex>
  22. #include <cassert>
  23. #include "test_macros.h"
  24. #include "test_iterators.h"
  25. #include "platform_support.h" // locale name macros
  26. int main(int, char**)
  27. {
  28. {
  29. std::cmatch m;
  30. const char s[] = "a";
  31. assert(std::regex_match(s, m, std::regex("a")));
  32. assert(m.size() == 1);
  33. assert(!m.empty());
  34. assert(!m.prefix().matched);
  35. assert(m.prefix().first == s);
  36. assert(m.prefix().second == m[0].first);
  37. assert(!m.suffix().matched);
  38. assert(m.suffix().first == m[0].second);
  39. assert(m.suffix().second == s+1);
  40. assert(m.length(0) == 1);
  41. assert(m.position(0) == 0);
  42. assert(m.str(0) == "a");
  43. }
  44. {
  45. std::cmatch m;
  46. const char s[] = "ab";
  47. assert(std::regex_match(s, m, std::regex("ab")));
  48. assert(m.size() == 1);
  49. assert(!m.prefix().matched);
  50. assert(m.prefix().first == s);
  51. assert(m.prefix().second == m[0].first);
  52. assert(!m.suffix().matched);
  53. assert(m.suffix().first == m[0].second);
  54. assert(m.suffix().second == s+2);
  55. assert(m.length(0) == 2);
  56. assert(m.position(0) == 0);
  57. assert(m.str(0) == "ab");
  58. }
  59. {
  60. std::cmatch m;
  61. const char s[] = "ab";
  62. assert(!std::regex_match(s, m, std::regex("ba")));
  63. assert(m.size() == 0);
  64. assert(m.empty());
  65. }
  66. {
  67. std::cmatch m;
  68. const char s[] = "aab";
  69. assert(!std::regex_match(s, m, std::regex("ab")));
  70. assert(m.size() == 0);
  71. }
  72. {
  73. std::cmatch m;
  74. const char s[] = "aab";
  75. assert(!std::regex_match(s, m, std::regex("ab"),
  76. std::regex_constants::match_continuous));
  77. assert(m.size() == 0);
  78. }
  79. {
  80. std::cmatch m;
  81. const char s[] = "abcd";
  82. assert(!std::regex_match(s, m, std::regex("bc")));
  83. assert(m.size() == 0);
  84. }
  85. {
  86. std::cmatch m;
  87. const char s[] = "abbc";
  88. assert(std::regex_match(s, m, std::regex("ab*c")));
  89. assert(m.size() == 1);
  90. assert(!m.prefix().matched);
  91. assert(m.prefix().first == s);
  92. assert(m.prefix().second == m[0].first);
  93. assert(!m.suffix().matched);
  94. assert(m.suffix().first == m[0].second);
  95. assert(m.suffix().second == s+4);
  96. assert(m.length(0) == 4);
  97. assert(m.position(0) == 0);
  98. assert(m.str(0) == s);
  99. }
  100. {
  101. std::cmatch m;
  102. const char s[] = "ababc";
  103. assert(std::regex_match(s, m, std::regex("(ab)*c")));
  104. assert(m.size() == 2);
  105. assert(!m.prefix().matched);
  106. assert(m.prefix().first == s);
  107. assert(m.prefix().second == m[0].first);
  108. assert(!m.suffix().matched);
  109. assert(m.suffix().first == m[0].second);
  110. assert(m.suffix().second == s+5);
  111. assert(m.length(0) == 5);
  112. assert(m.position(0) == 0);
  113. assert(m.str(0) == s);
  114. assert(m.length(1) == 2);
  115. assert(m.position(1) == 2);
  116. assert(m.str(1) == "ab");
  117. }
  118. {
  119. std::cmatch m;
  120. const char s[] = "abcdefghijk";
  121. assert(!std::regex_match(s, m, std::regex("cd((e)fg)hi")));
  122. assert(m.size() == 0);
  123. }
  124. {
  125. std::cmatch m;
  126. const char s[] = "abc";
  127. assert(std::regex_match(s, m, std::regex("^abc")));
  128. assert(m.size() == 1);
  129. assert(!m.prefix().matched);
  130. assert(m.prefix().first == s);
  131. assert(m.prefix().second == m[0].first);
  132. assert(!m.suffix().matched);
  133. assert(m.suffix().first == m[0].second);
  134. assert(m.suffix().second == s+3);
  135. assert(m.length(0) == 3);
  136. assert(m.position(0) == 0);
  137. assert(m.str(0) == s);
  138. }
  139. {
  140. std::cmatch m;
  141. const char s[] = "abcd";
  142. assert(!std::regex_match(s, m, std::regex("^abc")));
  143. assert(m.size() == 0);
  144. }
  145. {
  146. std::cmatch m;
  147. const char s[] = "aabc";
  148. assert(!std::regex_match(s, m, std::regex("^abc")));
  149. assert(m.size() == 0);
  150. }
  151. {
  152. std::cmatch m;
  153. const char s[] = "abc";
  154. assert(std::regex_match(s, m, std::regex("abc$")));
  155. assert(m.size() == 1);
  156. assert(!m.prefix().matched);
  157. assert(m.prefix().first == s);
  158. assert(m.prefix().second == m[0].first);
  159. assert(!m.suffix().matched);
  160. assert(m.suffix().first == m[0].second);
  161. assert(m.suffix().second == s+3);
  162. assert(m.length(0) == 3);
  163. assert(m.position(0) == 0);
  164. assert(m.str(0) == s);
  165. }
  166. {
  167. std::cmatch m;
  168. const char s[] = "efabc";
  169. assert(!std::regex_match(s, m, std::regex("abc$")));
  170. assert(m.size() == 0);
  171. }
  172. {
  173. std::cmatch m;
  174. const char s[] = "efabcg";
  175. assert(!std::regex_match(s, m, std::regex("abc$")));
  176. assert(m.size() == 0);
  177. }
  178. {
  179. std::cmatch m;
  180. const char s[] = "abc";
  181. assert(std::regex_match(s, m, std::regex("a.c")));
  182. assert(m.size() == 1);
  183. assert(!m.prefix().matched);
  184. assert(m.prefix().first == s);
  185. assert(m.prefix().second == m[0].first);
  186. assert(!m.suffix().matched);
  187. assert(m.suffix().first == m[0].second);
  188. assert(m.suffix().second == s+3);
  189. assert(m.length(0) == 3);
  190. assert(m.position(0) == 0);
  191. assert(m.str(0) == s);
  192. }
  193. {
  194. std::cmatch m;
  195. const char s[] = "acc";
  196. assert(std::regex_match(s, m, std::regex("a.c")));
  197. assert(m.size() == 1);
  198. assert(!m.prefix().matched);
  199. assert(m.prefix().first == s);
  200. assert(m.prefix().second == m[0].first);
  201. assert(!m.suffix().matched);
  202. assert(m.suffix().first == m[0].second);
  203. assert(m.suffix().second == s+3);
  204. assert(m.length(0) == 3);
  205. assert(m.position(0) == 0);
  206. assert(m.str(0) == s);
  207. }
  208. {
  209. std::cmatch m;
  210. const char s[] = "acc";
  211. assert(std::regex_match(s, m, std::regex("a.c")));
  212. assert(m.size() == 1);
  213. assert(!m.prefix().matched);
  214. assert(m.prefix().first == s);
  215. assert(m.prefix().second == m[0].first);
  216. assert(!m.suffix().matched);
  217. assert(m.suffix().first == m[0].second);
  218. assert(m.suffix().second == s+3);
  219. assert(m.length(0) == 3);
  220. assert(m.position(0) == 0);
  221. assert(m.str(0) == s);
  222. }
  223. {
  224. std::cmatch m;
  225. const char s[] = "abcdef";
  226. assert(std::regex_match(s, m, std::regex("(.*).*")));
  227. assert(m.size() == 2);
  228. assert(!m.prefix().matched);
  229. assert(m.prefix().first == s);
  230. assert(m.prefix().second == m[0].first);
  231. assert(!m.suffix().matched);
  232. assert(m.suffix().first == m[0].second);
  233. assert(m.suffix().second == s+6);
  234. assert(m.length(0) == 6);
  235. assert(m.position(0) == 0);
  236. assert(m.str(0) == s);
  237. assert(m.length(1) == 6);
  238. assert(m.position(1) == 0);
  239. assert(m.str(1) == s);
  240. }
  241. {
  242. std::cmatch m;
  243. const char s[] = "bc";
  244. assert(!std::regex_match(s, m, std::regex("(a*)*")));
  245. assert(m.size() == 0);
  246. }
  247. {
  248. std::cmatch m;
  249. const char s[] = "abbc";
  250. assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
  251. assert(m.size() == 0);
  252. }
  253. {
  254. std::cmatch m;
  255. const char s[] = "abbbc";
  256. assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
  257. assert(m.size() == 1);
  258. assert(!m.prefix().matched);
  259. assert(m.prefix().first == s);
  260. assert(m.prefix().second == m[0].first);
  261. assert(!m.suffix().matched);
  262. assert(m.suffix().first == m[0].second);
  263. assert(m.suffix().second == m[0].second);
  264. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  265. assert(m.position(0) == 0);
  266. assert(m.str(0) == s);
  267. }
  268. {
  269. std::cmatch m;
  270. const char s[] = "abbbbc";
  271. assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
  272. assert(m.size() == 1);
  273. assert(!m.prefix().matched);
  274. assert(m.prefix().first == s);
  275. assert(m.prefix().second == m[0].first);
  276. assert(!m.suffix().matched);
  277. assert(m.suffix().first == m[0].second);
  278. assert(m.suffix().second == m[0].second);
  279. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  280. assert(m.position(0) == 0);
  281. assert(m.str(0) == s);
  282. }
  283. {
  284. std::cmatch m;
  285. const char s[] = "abbbbbc";
  286. assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
  287. assert(m.size() == 1);
  288. assert(!m.prefix().matched);
  289. assert(m.prefix().first == s);
  290. assert(m.prefix().second == m[0].first);
  291. assert(!m.suffix().matched);
  292. assert(m.suffix().first == m[0].second);
  293. assert(m.suffix().second == m[0].second);
  294. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  295. assert(m.position(0) == 0);
  296. assert(m.str(0) == s);
  297. }
  298. {
  299. std::cmatch m;
  300. const char s[] = "adefc";
  301. assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
  302. assert(m.size() == 0);
  303. }
  304. {
  305. std::cmatch m;
  306. const char s[] = "abbbbbbc";
  307. assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
  308. assert(m.size() == 0);
  309. }
  310. {
  311. std::cmatch m;
  312. const char s[] = "adec";
  313. assert(!std::regex_match(s, m, std::regex("a.{3,5}c")));
  314. assert(m.size() == 0);
  315. }
  316. {
  317. std::cmatch m;
  318. const char s[] = "adefc";
  319. assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
  320. assert(m.size() == 1);
  321. assert(!m.prefix().matched);
  322. assert(m.prefix().first == s);
  323. assert(m.prefix().second == m[0].first);
  324. assert(!m.suffix().matched);
  325. assert(m.suffix().first == m[0].second);
  326. assert(m.suffix().second == m[0].second);
  327. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  328. assert(m.position(0) == 0);
  329. assert(m.str(0) == s);
  330. }
  331. {
  332. std::cmatch m;
  333. const char s[] = "adefgc";
  334. assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
  335. assert(m.size() == 1);
  336. assert(!m.prefix().matched);
  337. assert(m.prefix().first == s);
  338. assert(m.prefix().second == m[0].first);
  339. assert(!m.suffix().matched);
  340. assert(m.suffix().first == m[0].second);
  341. assert(m.suffix().second == m[0].second);
  342. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  343. assert(m.position(0) == 0);
  344. assert(m.str(0) == s);
  345. }
  346. {
  347. std::cmatch m;
  348. const char s[] = "adefghc";
  349. assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
  350. assert(m.size() == 1);
  351. assert(!m.prefix().matched);
  352. assert(m.prefix().first == s);
  353. assert(m.prefix().second == m[0].first);
  354. assert(!m.suffix().matched);
  355. assert(m.suffix().first == m[0].second);
  356. assert(m.suffix().second == m[0].second);
  357. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  358. assert(m.position(0) == 0);
  359. assert(m.str(0) == s);
  360. }
  361. {
  362. std::cmatch m;
  363. const char s[] = "adefghic";
  364. assert(!std::regex_match(s, m, std::regex("a.{3,5}c")));
  365. assert(m.size() == 0);
  366. }
  367. {
  368. std::cmatch m;
  369. // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
  370. const char s[] = "tournament";
  371. assert(std::regex_match(s, m, std::regex("tour|to|tournament")));
  372. assert(m.size() == 1);
  373. assert(!m.prefix().matched);
  374. assert(m.prefix().first == s);
  375. assert(m.prefix().second == m[0].first);
  376. assert(!m.suffix().matched);
  377. assert(m.suffix().first == m[0].second);
  378. assert(m.suffix().second == m[0].second);
  379. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  380. assert(m.position(0) == 0);
  381. assert(m.str(0) == s);
  382. }
  383. {
  384. std::cmatch m;
  385. // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
  386. const char s[] = "tournamenttotour";
  387. assert(
  388. std::regex_match(s, m, std::regex("(tour|to|tournament)+",
  389. std::regex_constants::nosubs)));
  390. assert(m.size() == 1);
  391. assert(!m.prefix().matched);
  392. assert(m.prefix().first == s);
  393. assert(m.prefix().second == m[0].first);
  394. assert(!m.suffix().matched);
  395. assert(m.suffix().first == m[0].second);
  396. assert(m.suffix().second == m[0].second);
  397. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  398. assert(m.position(0) == 0);
  399. assert(m.str(0) == s);
  400. }
  401. {
  402. std::cmatch m;
  403. const char s[] = "ttotour";
  404. assert(std::regex_match(s, m, std::regex("(tour|to|t)+")));
  405. assert(m.size() == 2);
  406. assert(!m.prefix().matched);
  407. assert(m.prefix().first == s);
  408. assert(m.prefix().second == m[0].first);
  409. assert(!m.suffix().matched);
  410. assert(m.suffix().first == m[0].second);
  411. assert(m.suffix().second == m[0].second);
  412. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  413. assert(m.position(0) == 0);
  414. assert(m.str(0) == s);
  415. assert(m.length(1) == 4);
  416. assert(m.position(1) == 3);
  417. assert(m.str(1) == "tour");
  418. }
  419. {
  420. std::cmatch m;
  421. const char s[] = "-ab,ab-";
  422. assert(!std::regex_match(s, m, std::regex("-(.*),\1-")));
  423. assert(m.size() == 0);
  424. }
  425. {
  426. std::cmatch m;
  427. const char s[] = "-ab,ab-";
  428. assert(std::regex_match(s, m, std::regex("-.*,.*-")));
  429. assert(m.size() == 1);
  430. assert(!m.prefix().matched);
  431. assert(m.prefix().first == s);
  432. assert(m.prefix().second == m[0].first);
  433. assert(!m.suffix().matched);
  434. assert(m.suffix().first == m[0].second);
  435. assert(m.suffix().second == m[0].second);
  436. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  437. assert(m.position(0) == 0);
  438. assert(m.str(0) == s);
  439. }
  440. {
  441. std::cmatch m;
  442. const char s[] = "a";
  443. assert(std::regex_match(s, m, std::regex("^[a]$")));
  444. assert(m.size() == 1);
  445. assert(!m.prefix().matched);
  446. assert(m.prefix().first == s);
  447. assert(m.prefix().second == m[0].first);
  448. assert(!m.suffix().matched);
  449. assert(m.suffix().first == m[0].second);
  450. assert(m.suffix().second == m[0].second);
  451. assert(m.length(0) == 1);
  452. assert(m.position(0) == 0);
  453. assert(m.str(0) == "a");
  454. }
  455. {
  456. std::cmatch m;
  457. const char s[] = "a";
  458. assert(std::regex_match(s, m, std::regex("^[ab]$")));
  459. assert(m.size() == 1);
  460. assert(!m.prefix().matched);
  461. assert(m.prefix().first == s);
  462. assert(m.prefix().second == m[0].first);
  463. assert(!m.suffix().matched);
  464. assert(m.suffix().first == m[0].second);
  465. assert(m.suffix().second == m[0].second);
  466. assert(m.length(0) == 1);
  467. assert(m.position(0) == 0);
  468. assert(m.str(0) == "a");
  469. }
  470. {
  471. std::cmatch m;
  472. const char s[] = "c";
  473. assert(std::regex_match(s, m, std::regex("^[a-f]$")));
  474. assert(m.size() == 1);
  475. assert(!m.prefix().matched);
  476. assert(m.prefix().first == s);
  477. assert(m.prefix().second == m[0].first);
  478. assert(!m.suffix().matched);
  479. assert(m.suffix().first == m[0].second);
  480. assert(m.suffix().second == m[0].second);
  481. assert(m.length(0) == 1);
  482. assert(m.position(0) == 0);
  483. assert(m.str(0) == s);
  484. }
  485. {
  486. std::cmatch m;
  487. const char s[] = "g";
  488. assert(!std::regex_match(s, m, std::regex("^[a-f]$")));
  489. assert(m.size() == 0);
  490. }
  491. {
  492. std::cmatch m;
  493. const char s[] = "Iraqi";
  494. assert(!std::regex_match(s, m, std::regex("q[^u]")));
  495. assert(m.size() == 0);
  496. }
  497. {
  498. std::cmatch m;
  499. const char s[] = "Iraq";
  500. assert(!std::regex_match(s, m, std::regex("q[^u]")));
  501. assert(m.size() == 0);
  502. }
  503. {
  504. std::cmatch m;
  505. const char s[] = "AmB";
  506. assert(std::regex_match(s, m, std::regex("A[[:lower:]]B")));
  507. assert(m.size() == 1);
  508. assert(!m.prefix().matched);
  509. assert(m.prefix().first == s);
  510. assert(m.prefix().second == m[0].first);
  511. assert(!m.suffix().matched);
  512. assert(m.suffix().first == m[0].second);
  513. assert(m.suffix().second == m[0].second);
  514. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  515. assert(m.position(0) == 0);
  516. assert(m.str(0) == s);
  517. }
  518. {
  519. std::cmatch m;
  520. const char s[] = "AMB";
  521. assert(!std::regex_match(s, m, std::regex("A[[:lower:]]B")));
  522. assert(m.size() == 0);
  523. }
  524. {
  525. std::cmatch m;
  526. const char s[] = "AMB";
  527. assert(std::regex_match(s, m, std::regex("A[^[:lower:]]B")));
  528. assert(m.size() == 1);
  529. assert(!m.prefix().matched);
  530. assert(m.prefix().first == s);
  531. assert(m.prefix().second == m[0].first);
  532. assert(!m.suffix().matched);
  533. assert(m.suffix().first == m[0].second);
  534. assert(m.suffix().second == m[0].second);
  535. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  536. assert(m.position(0) == 0);
  537. assert(m.str(0) == s);
  538. }
  539. {
  540. std::cmatch m;
  541. const char s[] = "AmB";
  542. assert(!std::regex_match(s, m, std::regex("A[^[:lower:]]B")));
  543. assert(m.size() == 0);
  544. }
  545. {
  546. std::cmatch m;
  547. const char s[] = "A5B";
  548. assert(!std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B")));
  549. assert(m.size() == 0);
  550. }
  551. {
  552. std::cmatch m;
  553. const char s[] = "A?B";
  554. assert(std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B")));
  555. assert(m.size() == 1);
  556. assert(!m.prefix().matched);
  557. assert(m.prefix().first == s);
  558. assert(m.prefix().second == m[0].first);
  559. assert(!m.suffix().matched);
  560. assert(m.suffix().first == m[0].second);
  561. assert(m.suffix().second == m[0].second);
  562. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  563. assert(m.position(0) == 0);
  564. assert(m.str(0) == s);
  565. }
  566. {
  567. std::cmatch m;
  568. const char s[] = "-";
  569. assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
  570. assert(m.size() == 1);
  571. assert(!m.prefix().matched);
  572. assert(m.prefix().first == s);
  573. assert(m.prefix().second == m[0].first);
  574. assert(!m.suffix().matched);
  575. assert(m.suffix().first == m[0].second);
  576. assert(m.suffix().second == m[0].second);
  577. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  578. assert(m.position(0) == 0);
  579. assert(m.str(0) == s);
  580. }
  581. {
  582. std::cmatch m;
  583. const char s[] = "z";
  584. assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
  585. assert(m.size() == 1);
  586. assert(!m.prefix().matched);
  587. assert(m.prefix().first == s);
  588. assert(m.prefix().second == m[0].first);
  589. assert(!m.suffix().matched);
  590. assert(m.suffix().first == m[0].second);
  591. assert(m.suffix().second == m[0].second);
  592. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  593. assert(m.position(0) == 0);
  594. assert(m.str(0) == s);
  595. }
  596. {
  597. std::cmatch m;
  598. const char s[] = "m";
  599. assert(!std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
  600. assert(m.size() == 0);
  601. }
  602. std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
  603. {
  604. std::cmatch m;
  605. const char s[] = "m";
  606. assert(std::regex_match(s, m, std::regex("[a[=M=]z]")));
  607. assert(m.size() == 1);
  608. assert(!m.prefix().matched);
  609. assert(m.prefix().first == s);
  610. assert(m.prefix().second == m[0].first);
  611. assert(!m.suffix().matched);
  612. assert(m.suffix().first == m[0].second);
  613. assert(m.suffix().second == m[0].second);
  614. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  615. assert(m.position(0) == 0);
  616. assert(m.str(0) == s);
  617. }
  618. {
  619. std::cmatch m;
  620. const char s[] = "Ch";
  621. assert(std::regex_match(s, m, std::regex("[a[.ch.]z]",
  622. std::regex_constants::icase)));
  623. assert(m.size() == 1);
  624. assert(!m.prefix().matched);
  625. assert(m.prefix().first == s);
  626. assert(m.prefix().second == m[0].first);
  627. assert(!m.suffix().matched);
  628. assert(m.suffix().first == m[0].second);
  629. assert(m.suffix().second == m[0].second);
  630. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  631. assert(m.position(0) == 0);
  632. assert(m.str(0) == s);
  633. }
  634. {
  635. std::cmatch m;
  636. const char s[] = "foobar";
  637. assert(std::regex_match(s, m, std::regex("[^\\0]*")));
  638. assert(m.size() == 1);
  639. }
  640. {
  641. std::cmatch m;
  642. const char s[] = "foo\0bar";
  643. assert(std::regex_match(s, s+7, m, std::regex("[abfor\\0]*")));
  644. assert(m.size() == 1);
  645. }
  646. std::locale::global(std::locale("C"));
  647. {
  648. std::cmatch m;
  649. const char s[] = "m";
  650. assert(!std::regex_match(s, m, std::regex("[a[=M=]z]")));
  651. assert(m.size() == 0);
  652. }
  653. {
  654. std::cmatch m;
  655. const char s[] = "01a45cef9";
  656. assert(!std::regex_match(s, m, std::regex("[ace1-9]*")));
  657. assert(m.size() == 0);
  658. }
  659. {
  660. std::cmatch m;
  661. const char s[] = "01a45cef9";
  662. assert(!std::regex_match(s, m, std::regex("[ace1-9]+")));
  663. assert(m.size() == 0);
  664. }
  665. {
  666. const char r[] = "^[-+]?[0-9]+[CF]$";
  667. std::ptrdiff_t sr = std::char_traits<char>::length(r);
  668. typedef forward_iterator<const char*> FI;
  669. typedef bidirectional_iterator<const char*> BI;
  670. std::regex regex(FI(r), FI(r+sr));
  671. std::match_results<BI> m;
  672. const char s[] = "-40C";
  673. std::ptrdiff_t ss = std::char_traits<char>::length(s);
  674. assert(std::regex_match(BI(s), BI(s+ss), m, regex));
  675. assert(m.size() == 1);
  676. assert(!m.prefix().matched);
  677. assert(m.prefix().first == BI(s));
  678. assert(m.prefix().second == m[0].first);
  679. assert(!m.suffix().matched);
  680. assert(m.suffix().first == m[0].second);
  681. assert(m.suffix().second == m[0].second);
  682. assert(m.length(0) == 4);
  683. assert(m.position(0) == 0);
  684. assert(m.str(0) == s);
  685. }
  686. {
  687. std::cmatch m;
  688. const char s[] = "Jeff Jeffs ";
  689. assert(!std::regex_match(s, m, std::regex("Jeff(?=s\\b)")));
  690. assert(m.size() == 0);
  691. }
  692. {
  693. std::cmatch m;
  694. const char s[] = "Jeffs Jeff";
  695. assert(!std::regex_match(s, m, std::regex("Jeff(?!s\\b)")));
  696. assert(m.size() == 0);
  697. }
  698. {
  699. std::cmatch m;
  700. const char s[] = "5%k";
  701. assert(std::regex_match(s, m, std::regex("\\d[\\W]k")));
  702. assert(m.size() == 1);
  703. assert(!m.prefix().matched);
  704. assert(m.prefix().first == s);
  705. assert(m.prefix().second == m[0].first);
  706. assert(!m.suffix().matched);
  707. assert(m.suffix().first == m[0].second);
  708. assert(m.suffix().second == s + std::char_traits<char>::length(s));
  709. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
  710. assert(m.position(0) == 0);
  711. assert(m.str(0) == s);
  712. }
  713. {
  714. std::wcmatch m;
  715. const wchar_t s[] = L"a";
  716. assert(std::regex_match(s, m, std::wregex(L"a")));
  717. assert(m.size() == 1);
  718. assert(!m.empty());
  719. assert(!m.prefix().matched);
  720. assert(m.prefix().first == s);
  721. assert(m.prefix().second == m[0].first);
  722. assert(!m.suffix().matched);
  723. assert(m.suffix().first == m[0].second);
  724. assert(m.suffix().second == s+1);
  725. assert(m.length(0) == 1);
  726. assert(m.position(0) == 0);
  727. assert(m.str(0) == L"a");
  728. }
  729. {
  730. std::wcmatch m;
  731. const wchar_t s[] = L"ab";
  732. assert(std::regex_match(s, m, std::wregex(L"ab")));
  733. assert(m.size() == 1);
  734. assert(!m.prefix().matched);
  735. assert(m.prefix().first == s);
  736. assert(m.prefix().second == m[0].first);
  737. assert(!m.suffix().matched);
  738. assert(m.suffix().first == m[0].second);
  739. assert(m.suffix().second == s+2);
  740. assert(m.length(0) == 2);
  741. assert(m.position(0) == 0);
  742. assert(m.str(0) == L"ab");
  743. }
  744. {
  745. std::wcmatch m;
  746. const wchar_t s[] = L"ab";
  747. assert(!std::regex_match(s, m, std::wregex(L"ba")));
  748. assert(m.size() == 0);
  749. assert(m.empty());
  750. }
  751. {
  752. std::wcmatch m;
  753. const wchar_t s[] = L"aab";
  754. assert(!std::regex_match(s, m, std::wregex(L"ab")));
  755. assert(m.size() == 0);
  756. }
  757. {
  758. std::wcmatch m;
  759. const wchar_t s[] = L"aab";
  760. assert(!std::regex_match(s, m, std::wregex(L"ab"),
  761. std::regex_constants::match_continuous));
  762. assert(m.size() == 0);
  763. }
  764. {
  765. std::wcmatch m;
  766. const wchar_t s[] = L"abcd";
  767. assert(!std::regex_match(s, m, std::wregex(L"bc")));
  768. assert(m.size() == 0);
  769. }
  770. {
  771. std::wcmatch m;
  772. const wchar_t s[] = L"abbc";
  773. assert(std::regex_match(s, m, std::wregex(L"ab*c")));
  774. assert(m.size() == 1);
  775. assert(!m.prefix().matched);
  776. assert(m.prefix().first == s);
  777. assert(m.prefix().second == m[0].first);
  778. assert(!m.suffix().matched);
  779. assert(m.suffix().first == m[0].second);
  780. assert(m.suffix().second == s+4);
  781. assert(m.length(0) == 4);
  782. assert(m.position(0) == 0);
  783. assert(m.str(0) == s);
  784. }
  785. {
  786. std::wcmatch m;
  787. const wchar_t s[] = L"ababc";
  788. assert(std::regex_match(s, m, std::wregex(L"(ab)*c")));
  789. assert(m.size() == 2);
  790. assert(!m.prefix().matched);
  791. assert(m.prefix().first == s);
  792. assert(m.prefix().second == m[0].first);
  793. assert(!m.suffix().matched);
  794. assert(m.suffix().first == m[0].second);
  795. assert(m.suffix().second == s+5);
  796. assert(m.length(0) == 5);
  797. assert(m.position(0) == 0);
  798. assert(m.str(0) == s);
  799. assert(m.length(1) == 2);
  800. assert(m.position(1) == 2);
  801. assert(m.str(1) == L"ab");
  802. }
  803. {
  804. std::wcmatch m;
  805. const wchar_t s[] = L"abcdefghijk";
  806. assert(!std::regex_match(s, m, std::wregex(L"cd((e)fg)hi")));
  807. assert(m.size() == 0);
  808. }
  809. {
  810. std::wcmatch m;
  811. const wchar_t s[] = L"abc";
  812. assert(std::regex_match(s, m, std::wregex(L"^abc")));
  813. assert(m.size() == 1);
  814. assert(!m.prefix().matched);
  815. assert(m.prefix().first == s);
  816. assert(m.prefix().second == m[0].first);
  817. assert(!m.suffix().matched);
  818. assert(m.suffix().first == m[0].second);
  819. assert(m.suffix().second == s+3);
  820. assert(m.length(0) == 3);
  821. assert(m.position(0) == 0);
  822. assert(m.str(0) == s);
  823. }
  824. {
  825. std::wcmatch m;
  826. const wchar_t s[] = L"abcd";
  827. assert(!std::regex_match(s, m, std::wregex(L"^abc")));
  828. assert(m.size() == 0);
  829. }
  830. {
  831. std::wcmatch m;
  832. const wchar_t s[] = L"aabc";
  833. assert(!std::regex_match(s, m, std::wregex(L"^abc")));
  834. assert(m.size() == 0);
  835. }
  836. {
  837. std::wcmatch m;
  838. const wchar_t s[] = L"abc";
  839. assert(std::regex_match(s, m, std::wregex(L"abc$")));
  840. assert(m.size() == 1);
  841. assert(!m.prefix().matched);
  842. assert(m.prefix().first == s);
  843. assert(m.prefix().second == m[0].first);
  844. assert(!m.suffix().matched);
  845. assert(m.suffix().first == m[0].second);
  846. assert(m.suffix().second == s+3);
  847. assert(m.length(0) == 3);
  848. assert(m.position(0) == 0);
  849. assert(m.str(0) == s);
  850. }
  851. {
  852. std::wcmatch m;
  853. const wchar_t s[] = L"efabc";
  854. assert(!std::regex_match(s, m, std::wregex(L"abc$")));
  855. assert(m.size() == 0);
  856. }
  857. {
  858. std::wcmatch m;
  859. const wchar_t s[] = L"efabcg";
  860. assert(!std::regex_match(s, m, std::wregex(L"abc$")));
  861. assert(m.size() == 0);
  862. }
  863. {
  864. std::wcmatch m;
  865. const wchar_t s[] = L"abc";
  866. assert(std::regex_match(s, m, std::wregex(L"a.c")));
  867. assert(m.size() == 1);
  868. assert(!m.prefix().matched);
  869. assert(m.prefix().first == s);
  870. assert(m.prefix().second == m[0].first);
  871. assert(!m.suffix().matched);
  872. assert(m.suffix().first == m[0].second);
  873. assert(m.suffix().second == s+3);
  874. assert(m.length(0) == 3);
  875. assert(m.position(0) == 0);
  876. assert(m.str(0) == s);
  877. }
  878. {
  879. std::wcmatch m;
  880. const wchar_t s[] = L"acc";
  881. assert(std::regex_match(s, m, std::wregex(L"a.c")));
  882. assert(m.size() == 1);
  883. assert(!m.prefix().matched);
  884. assert(m.prefix().first == s);
  885. assert(m.prefix().second == m[0].first);
  886. assert(!m.suffix().matched);
  887. assert(m.suffix().first == m[0].second);
  888. assert(m.suffix().second == s+3);
  889. assert(m.length(0) == 3);
  890. assert(m.position(0) == 0);
  891. assert(m.str(0) == s);
  892. }
  893. {
  894. std::wcmatch m;
  895. const wchar_t s[] = L"acc";
  896. assert(std::regex_match(s, m, std::wregex(L"a.c")));
  897. assert(m.size() == 1);
  898. assert(!m.prefix().matched);
  899. assert(m.prefix().first == s);
  900. assert(m.prefix().second == m[0].first);
  901. assert(!m.suffix().matched);
  902. assert(m.suffix().first == m[0].second);
  903. assert(m.suffix().second == s+3);
  904. assert(m.length(0) == 3);
  905. assert(m.position(0) == 0);
  906. assert(m.str(0) == s);
  907. }
  908. {
  909. std::wcmatch m;
  910. const wchar_t s[] = L"abcdef";
  911. assert(std::regex_match(s, m, std::wregex(L"(.*).*")));
  912. assert(m.size() == 2);
  913. assert(!m.prefix().matched);
  914. assert(m.prefix().first == s);
  915. assert(m.prefix().second == m[0].first);
  916. assert(!m.suffix().matched);
  917. assert(m.suffix().first == m[0].second);
  918. assert(m.suffix().second == s+6);
  919. assert(m.length(0) == 6);
  920. assert(m.position(0) == 0);
  921. assert(m.str(0) == s);
  922. assert(m.length(1) == 6);
  923. assert(m.position(1) == 0);
  924. assert(m.str(1) == s);
  925. }
  926. {
  927. std::wcmatch m;
  928. const wchar_t s[] = L"bc";
  929. assert(!std::regex_match(s, m, std::wregex(L"(a*)*")));
  930. assert(m.size() == 0);
  931. }
  932. {
  933. std::wcmatch m;
  934. const wchar_t s[] = L"abbc";
  935. assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
  936. assert(m.size() == 0);
  937. }
  938. {
  939. std::wcmatch m;
  940. const wchar_t s[] = L"abbbc";
  941. assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
  942. assert(m.size() == 1);
  943. assert(!m.prefix().matched);
  944. assert(m.prefix().first == s);
  945. assert(m.prefix().second == m[0].first);
  946. assert(!m.suffix().matched);
  947. assert(m.suffix().first == m[0].second);
  948. assert(m.suffix().second == m[0].second);
  949. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  950. assert(m.position(0) == 0);
  951. assert(m.str(0) == s);
  952. }
  953. {
  954. std::wcmatch m;
  955. const wchar_t s[] = L"abbbbc";
  956. assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
  957. assert(m.size() == 1);
  958. assert(!m.prefix().matched);
  959. assert(m.prefix().first == s);
  960. assert(m.prefix().second == m[0].first);
  961. assert(!m.suffix().matched);
  962. assert(m.suffix().first == m[0].second);
  963. assert(m.suffix().second == m[0].second);
  964. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  965. assert(m.position(0) == 0);
  966. assert(m.str(0) == s);
  967. }
  968. {
  969. std::wcmatch m;
  970. const wchar_t s[] = L"abbbbbc";
  971. assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
  972. assert(m.size() == 1);
  973. assert(!m.prefix().matched);
  974. assert(m.prefix().first == s);
  975. assert(m.prefix().second == m[0].first);
  976. assert(!m.suffix().matched);
  977. assert(m.suffix().first == m[0].second);
  978. assert(m.suffix().second == m[0].second);
  979. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  980. assert(m.position(0) == 0);
  981. assert(m.str(0) == s);
  982. }
  983. {
  984. std::wcmatch m;
  985. const wchar_t s[] = L"adefc";
  986. assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
  987. assert(m.size() == 0);
  988. }
  989. {
  990. std::wcmatch m;
  991. const wchar_t s[] = L"abbbbbbc";
  992. assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
  993. assert(m.size() == 0);
  994. }
  995. {
  996. std::wcmatch m;
  997. const wchar_t s[] = L"adec";
  998. assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
  999. assert(m.size() == 0);
  1000. }
  1001. {
  1002. std::wcmatch m;
  1003. const wchar_t s[] = L"adefc";
  1004. assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
  1005. assert(m.size() == 1);
  1006. assert(!m.prefix().matched);
  1007. assert(m.prefix().first == s);
  1008. assert(m.prefix().second == m[0].first);
  1009. assert(!m.suffix().matched);
  1010. assert(m.suffix().first == m[0].second);
  1011. assert(m.suffix().second == m[0].second);
  1012. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1013. assert(m.position(0) == 0);
  1014. assert(m.str(0) == s);
  1015. }
  1016. {
  1017. std::wcmatch m;
  1018. const wchar_t s[] = L"adefgc";
  1019. assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
  1020. assert(m.size() == 1);
  1021. assert(!m.prefix().matched);
  1022. assert(m.prefix().first == s);
  1023. assert(m.prefix().second == m[0].first);
  1024. assert(!m.suffix().matched);
  1025. assert(m.suffix().first == m[0].second);
  1026. assert(m.suffix().second == m[0].second);
  1027. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1028. assert(m.position(0) == 0);
  1029. assert(m.str(0) == s);
  1030. }
  1031. {
  1032. std::wcmatch m;
  1033. const wchar_t s[] = L"adefghc";
  1034. assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
  1035. assert(m.size() == 1);
  1036. assert(!m.prefix().matched);
  1037. assert(m.prefix().first == s);
  1038. assert(m.prefix().second == m[0].first);
  1039. assert(!m.suffix().matched);
  1040. assert(m.suffix().first == m[0].second);
  1041. assert(m.suffix().second == m[0].second);
  1042. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1043. assert(m.position(0) == 0);
  1044. assert(m.str(0) == s);
  1045. }
  1046. {
  1047. std::wcmatch m;
  1048. const wchar_t s[] = L"adefghic";
  1049. assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
  1050. assert(m.size() == 0);
  1051. }
  1052. {
  1053. std::wcmatch m;
  1054. // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
  1055. const wchar_t s[] = L"tournament";
  1056. assert(std::regex_match(s, m, std::wregex(L"tour|to|tournament")));
  1057. assert(m.size() == 1);
  1058. assert(!m.prefix().matched);
  1059. assert(m.prefix().first == s);
  1060. assert(m.prefix().second == m[0].first);
  1061. assert(!m.suffix().matched);
  1062. assert(m.suffix().first == m[0].second);
  1063. assert(m.suffix().second == m[0].second);
  1064. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1065. assert(m.position(0) == 0);
  1066. assert(m.str(0) == s);
  1067. }
  1068. {
  1069. std::wcmatch m;
  1070. // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
  1071. const wchar_t s[] = L"tournamenttotour";
  1072. assert(
  1073. std::regex_match(s, m, std::wregex(L"(tour|to|tournament)+",
  1074. std::regex_constants::nosubs)));
  1075. assert(m.size() == 1);
  1076. assert(!m.prefix().matched);
  1077. assert(m.prefix().first == s);
  1078. assert(m.prefix().second == m[0].first);
  1079. assert(!m.suffix().matched);
  1080. assert(m.suffix().first == m[0].second);
  1081. assert(m.suffix().second == m[0].second);
  1082. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1083. assert(m.position(0) == 0);
  1084. assert(m.str(0) == s);
  1085. }
  1086. {
  1087. std::wcmatch m;
  1088. const wchar_t s[] = L"ttotour";
  1089. assert(std::regex_match(s, m, std::wregex(L"(tour|to|t)+")));
  1090. assert(m.size() == 2);
  1091. assert(!m.prefix().matched);
  1092. assert(m.prefix().first == s);
  1093. assert(m.prefix().second == m[0].first);
  1094. assert(!m.suffix().matched);
  1095. assert(m.suffix().first == m[0].second);
  1096. assert(m.suffix().second == m[0].second);
  1097. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1098. assert(m.position(0) == 0);
  1099. assert(m.str(0) == s);
  1100. assert(m.length(1) == 4);
  1101. assert(m.position(1) == 3);
  1102. assert(m.str(1) == L"tour");
  1103. }
  1104. {
  1105. std::wcmatch m;
  1106. const wchar_t s[] = L"-ab,ab-";
  1107. assert(!std::regex_match(s, m, std::wregex(L"-(.*),\1-")));
  1108. assert(m.size() == 0);
  1109. }
  1110. {
  1111. std::wcmatch m;
  1112. const wchar_t s[] = L"-ab,ab-";
  1113. assert(std::regex_match(s, m, std::wregex(L"-.*,.*-")));
  1114. assert(m.size() == 1);
  1115. assert(!m.prefix().matched);
  1116. assert(m.prefix().first == s);
  1117. assert(m.prefix().second == m[0].first);
  1118. assert(!m.suffix().matched);
  1119. assert(m.suffix().first == m[0].second);
  1120. assert(m.suffix().second == m[0].second);
  1121. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1122. assert(m.position(0) == 0);
  1123. assert(m.str(0) == s);
  1124. }
  1125. {
  1126. std::wcmatch m;
  1127. const wchar_t s[] = L"a";
  1128. assert(std::regex_match(s, m, std::wregex(L"^[a]$")));
  1129. assert(m.size() == 1);
  1130. assert(!m.prefix().matched);
  1131. assert(m.prefix().first == s);
  1132. assert(m.prefix().second == m[0].first);
  1133. assert(!m.suffix().matched);
  1134. assert(m.suffix().first == m[0].second);
  1135. assert(m.suffix().second == m[0].second);
  1136. assert(m.length(0) == 1);
  1137. assert(m.position(0) == 0);
  1138. assert(m.str(0) == L"a");
  1139. }
  1140. {
  1141. std::wcmatch m;
  1142. const wchar_t s[] = L"a";
  1143. assert(std::regex_match(s, m, std::wregex(L"^[ab]$")));
  1144. assert(m.size() == 1);
  1145. assert(!m.prefix().matched);
  1146. assert(m.prefix().first == s);
  1147. assert(m.prefix().second == m[0].first);
  1148. assert(!m.suffix().matched);
  1149. assert(m.suffix().first == m[0].second);
  1150. assert(m.suffix().second == m[0].second);
  1151. assert(m.length(0) == 1);
  1152. assert(m.position(0) == 0);
  1153. assert(m.str(0) == L"a");
  1154. }
  1155. {
  1156. std::wcmatch m;
  1157. const wchar_t s[] = L"c";
  1158. assert(std::regex_match(s, m, std::wregex(L"^[a-f]$")));
  1159. assert(m.size() == 1);
  1160. assert(!m.prefix().matched);
  1161. assert(m.prefix().first == s);
  1162. assert(m.prefix().second == m[0].first);
  1163. assert(!m.suffix().matched);
  1164. assert(m.suffix().first == m[0].second);
  1165. assert(m.suffix().second == m[0].second);
  1166. assert(m.length(0) == 1);
  1167. assert(m.position(0) == 0);
  1168. assert(m.str(0) == s);
  1169. }
  1170. {
  1171. std::wcmatch m;
  1172. const wchar_t s[] = L"g";
  1173. assert(!std::regex_match(s, m, std::wregex(L"^[a-f]$")));
  1174. assert(m.size() == 0);
  1175. }
  1176. {
  1177. std::wcmatch m;
  1178. const wchar_t s[] = L"Iraqi";
  1179. assert(!std::regex_match(s, m, std::wregex(L"q[^u]")));
  1180. assert(m.size() == 0);
  1181. }
  1182. {
  1183. std::wcmatch m;
  1184. const wchar_t s[] = L"Iraq";
  1185. assert(!std::regex_match(s, m, std::wregex(L"q[^u]")));
  1186. assert(m.size() == 0);
  1187. }
  1188. {
  1189. std::wcmatch m;
  1190. const wchar_t s[] = L"AmB";
  1191. assert(std::regex_match(s, m, std::wregex(L"A[[:lower:]]B")));
  1192. assert(m.size() == 1);
  1193. assert(!m.prefix().matched);
  1194. assert(m.prefix().first == s);
  1195. assert(m.prefix().second == m[0].first);
  1196. assert(!m.suffix().matched);
  1197. assert(m.suffix().first == m[0].second);
  1198. assert(m.suffix().second == m[0].second);
  1199. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1200. assert(m.position(0) == 0);
  1201. assert(m.str(0) == s);
  1202. }
  1203. {
  1204. std::wcmatch m;
  1205. const wchar_t s[] = L"AMB";
  1206. assert(!std::regex_match(s, m, std::wregex(L"A[[:lower:]]B")));
  1207. assert(m.size() == 0);
  1208. }
  1209. {
  1210. std::wcmatch m;
  1211. const wchar_t s[] = L"AMB";
  1212. assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B")));
  1213. assert(m.size() == 1);
  1214. assert(!m.prefix().matched);
  1215. assert(m.prefix().first == s);
  1216. assert(m.prefix().second == m[0].first);
  1217. assert(!m.suffix().matched);
  1218. assert(m.suffix().first == m[0].second);
  1219. assert(m.suffix().second == m[0].second);
  1220. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1221. assert(m.position(0) == 0);
  1222. assert(m.str(0) == s);
  1223. }
  1224. {
  1225. std::wcmatch m;
  1226. const wchar_t s[] = L"AmB";
  1227. assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B")));
  1228. assert(m.size() == 0);
  1229. }
  1230. {
  1231. std::wcmatch m;
  1232. const wchar_t s[] = L"A5B";
  1233. assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
  1234. assert(m.size() == 0);
  1235. }
  1236. {
  1237. std::wcmatch m;
  1238. const wchar_t s[] = L"A?B";
  1239. assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
  1240. assert(m.size() == 1);
  1241. assert(!m.prefix().matched);
  1242. assert(m.prefix().first == s);
  1243. assert(m.prefix().second == m[0].first);
  1244. assert(!m.suffix().matched);
  1245. assert(m.suffix().first == m[0].second);
  1246. assert(m.suffix().second == m[0].second);
  1247. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1248. assert(m.position(0) == 0);
  1249. assert(m.str(0) == s);
  1250. }
  1251. {
  1252. std::wcmatch m;
  1253. const wchar_t s[] = L"-";
  1254. assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
  1255. assert(m.size() == 1);
  1256. assert(!m.prefix().matched);
  1257. assert(m.prefix().first == s);
  1258. assert(m.prefix().second == m[0].first);
  1259. assert(!m.suffix().matched);
  1260. assert(m.suffix().first == m[0].second);
  1261. assert(m.suffix().second == m[0].second);
  1262. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1263. assert(m.position(0) == 0);
  1264. assert(m.str(0) == s);
  1265. }
  1266. {
  1267. std::wcmatch m;
  1268. const wchar_t s[] = L"z";
  1269. assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
  1270. assert(m.size() == 1);
  1271. assert(!m.prefix().matched);
  1272. assert(m.prefix().first == s);
  1273. assert(m.prefix().second == m[0].first);
  1274. assert(!m.suffix().matched);
  1275. assert(m.suffix().first == m[0].second);
  1276. assert(m.suffix().second == m[0].second);
  1277. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1278. assert(m.position(0) == 0);
  1279. assert(m.str(0) == s);
  1280. }
  1281. {
  1282. std::wcmatch m;
  1283. const wchar_t s[] = L"m";
  1284. assert(!std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
  1285. assert(m.size() == 0);
  1286. }
  1287. std::locale::global(std::locale(LOCALE_cs_CZ_ISO8859_2));
  1288. {
  1289. std::wcmatch m;
  1290. const wchar_t s[] = L"m";
  1291. assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]")));
  1292. assert(m.size() == 1);
  1293. assert(!m.prefix().matched);
  1294. assert(m.prefix().first == s);
  1295. assert(m.prefix().second == m[0].first);
  1296. assert(!m.suffix().matched);
  1297. assert(m.suffix().first == m[0].second);
  1298. assert(m.suffix().second == m[0].second);
  1299. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1300. assert(m.position(0) == 0);
  1301. assert(m.str(0) == s);
  1302. }
  1303. {
  1304. std::wcmatch m;
  1305. const wchar_t s[] = L"Ch";
  1306. assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]",
  1307. std::regex_constants::icase)));
  1308. assert(m.size() == 1);
  1309. assert(!m.prefix().matched);
  1310. assert(m.prefix().first == s);
  1311. assert(m.prefix().second == m[0].first);
  1312. assert(!m.suffix().matched);
  1313. assert(m.suffix().first == m[0].second);
  1314. assert(m.suffix().second == m[0].second);
  1315. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1316. assert(m.position(0) == 0);
  1317. assert(m.str(0) == s);
  1318. }
  1319. std::locale::global(std::locale("C"));
  1320. {
  1321. std::wcmatch m;
  1322. const wchar_t s[] = L"m";
  1323. assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]")));
  1324. assert(m.size() == 0);
  1325. }
  1326. {
  1327. std::wcmatch m;
  1328. const wchar_t s[] = L"01a45cef9";
  1329. assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]*")));
  1330. assert(m.size() == 0);
  1331. }
  1332. {
  1333. std::wcmatch m;
  1334. const wchar_t s[] = L"01a45cef9";
  1335. assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]+")));
  1336. assert(m.size() == 0);
  1337. }
  1338. {
  1339. const wchar_t r[] = L"^[-+]?[0-9]+[CF]$";
  1340. std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r);
  1341. typedef forward_iterator<const wchar_t*> FI;
  1342. typedef bidirectional_iterator<const wchar_t*> BI;
  1343. std::wregex regex(FI(r), FI(r+sr));
  1344. std::match_results<BI> m;
  1345. const wchar_t s[] = L"-40C";
  1346. std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s);
  1347. assert(std::regex_match(BI(s), BI(s+ss), m, regex));
  1348. assert(m.size() == 1);
  1349. assert(!m.prefix().matched);
  1350. assert(m.prefix().first == BI(s));
  1351. assert(m.prefix().second == m[0].first);
  1352. assert(!m.suffix().matched);
  1353. assert(m.suffix().first == m[0].second);
  1354. assert(m.suffix().second == m[0].second);
  1355. assert(m.length(0) == 4);
  1356. assert(m.position(0) == 0);
  1357. assert(m.str(0) == s);
  1358. }
  1359. {
  1360. std::wcmatch m;
  1361. const wchar_t s[] = L"Jeff Jeffs ";
  1362. assert(!std::regex_match(s, m, std::wregex(L"Jeff(?=s\\b)")));
  1363. assert(m.size() == 0);
  1364. }
  1365. {
  1366. std::wcmatch m;
  1367. const wchar_t s[] = L"Jeffs Jeff";
  1368. assert(!std::regex_match(s, m, std::wregex(L"Jeff(?!s\\b)")));
  1369. assert(m.size() == 0);
  1370. }
  1371. {
  1372. std::wcmatch m;
  1373. const wchar_t s[] = L"5%k";
  1374. assert(std::regex_match(s, m, std::wregex(L"\\d[\\W]k")));
  1375. assert(m.size() == 1);
  1376. assert(!m.prefix().matched);
  1377. assert(m.prefix().first == s);
  1378. assert(m.prefix().second == m[0].first);
  1379. assert(!m.suffix().matched);
  1380. assert(m.suffix().first == m[0].second);
  1381. assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
  1382. assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
  1383. assert(m.position(0) == 0);
  1384. assert(m.str(0) == s);
  1385. }
  1386. return 0;
  1387. }