32 |
// TODO: Test extractions for PartialMatch/Consume |
// TODO: Test extractions for PartialMatch/Consume |
33 |
|
|
34 |
#include <stdio.h> |
#include <stdio.h> |
35 |
|
#include <cassert> |
36 |
#include <vector> |
#include <vector> |
37 |
#include "config.h" |
#include "config.h" |
38 |
#include "pcrecpp.h" |
#include "pcrecpp.h" |
260 |
"aaaaa", |
"aaaaa", |
261 |
"bbaaaaa", |
"bbaaaaa", |
262 |
"bbabbabbabbabbabb" }, |
"bbabbabbabbabbabb" }, |
263 |
|
{ "b*", |
264 |
|
"bb", |
265 |
|
"aa\naa\n", |
266 |
|
"bbaa\naa\n", |
267 |
|
"bbabbabb\nbbabbabb\nbb" }, |
268 |
|
{ "b*", |
269 |
|
"bb", |
270 |
|
"aa\raa\r", |
271 |
|
"bbaa\raa\r", |
272 |
|
"bbabbabb\rbbabbabb\rbb" }, |
273 |
|
{ "b*", |
274 |
|
"bb", |
275 |
|
"aa\r\naa\r\n", |
276 |
|
"bbaa\r\naa\r\n", |
277 |
|
"bbabbabb\r\nbbabbabb\r\nbb" }, |
278 |
|
#ifdef SUPPORT_UTF8 |
279 |
|
{ "b*", |
280 |
|
"bb", |
281 |
|
"\xE3\x83\x9B\xE3\x83\xBC\xE3\x83\xA0\xE3\x81\xB8", // utf8 |
282 |
|
"bb\xE3\x83\x9B\xE3\x83\xBC\xE3\x83\xA0\xE3\x81\xB8", |
283 |
|
"bb\xE3\x83\x9B""bb""\xE3\x83\xBC""bb""\xE3\x83\xA0""bb""\xE3\x81\xB8""bb" }, |
284 |
|
{ "b*", |
285 |
|
"bb", |
286 |
|
"\xE3\x83\x9B\r\n\xE3\x83\xBC\r\xE3\x83\xA0\n\xE3\x81\xB8\r\n", // utf8 |
287 |
|
"bb\xE3\x83\x9B\r\n\xE3\x83\xBC\r\xE3\x83\xA0\n\xE3\x81\xB8\r\n", |
288 |
|
("bb\xE3\x83\x9B""bb\r\nbb""\xE3\x83\xBC""bb\rbb""\xE3\x83\xA0" |
289 |
|
"bb\nbb""\xE3\x81\xB8""bb\r\nbb") }, |
290 |
|
#endif |
291 |
{ "", NULL, NULL, NULL, NULL } |
{ "", NULL, NULL, NULL, NULL } |
292 |
}; |
}; |
293 |
|
|
294 |
|
#ifdef SUPPORT_UTF8 |
295 |
|
const bool support_utf8 = true; |
296 |
|
#else |
297 |
|
const bool support_utf8 = false; |
298 |
|
#endif |
299 |
|
|
300 |
for (const ReplaceTest *t = tests; t->original != NULL; ++t) { |
for (const ReplaceTest *t = tests; t->original != NULL; ++t) { |
301 |
|
RE re(t->regexp, RE_Options(PCRE_NEWLINE_CRLF).set_utf8(support_utf8)); |
302 |
|
assert(re.error().empty()); |
303 |
string one(t->original); |
string one(t->original); |
304 |
CHECK(RE(t->regexp).Replace(t->rewrite, &one)); |
CHECK(re.Replace(t->rewrite, &one)); |
305 |
CHECK_EQ(one, t->single); |
CHECK_EQ(one, t->single); |
306 |
string all(t->original); |
string all(t->original); |
307 |
CHECK(RE(t->regexp).GlobalReplace(t->rewrite, &all) > 0); |
CHECK(re.GlobalReplace(t->rewrite, &all) > 0); |
308 |
CHECK_EQ(all, t->global); |
CHECK_EQ(all, t->global); |
309 |
} |
} |
310 |
|
|
311 |
|
// One final test: test \r\n replacement when we're not in CRLF mode |
312 |
|
{ |
313 |
|
RE re("b*", RE_Options(PCRE_NEWLINE_CR).set_utf8(support_utf8)); |
314 |
|
assert(re.error().empty()); |
315 |
|
string all("aa\r\naa\r\n"); |
316 |
|
CHECK(re.GlobalReplace("bb", &all) > 0); |
317 |
|
CHECK_EQ(all, string("bbabbabb\rbb\nbbabbabb\rbb\nbb")); |
318 |
|
} |
319 |
|
{ |
320 |
|
RE re("b*", RE_Options(PCRE_NEWLINE_LF).set_utf8(support_utf8)); |
321 |
|
assert(re.error().empty()); |
322 |
|
string all("aa\r\naa\r\n"); |
323 |
|
CHECK(re.GlobalReplace("bb", &all) > 0); |
324 |
|
CHECK_EQ(all, string("bbabbabb\rbb\nbbabbabb\rbb\nbb")); |
325 |
|
} |
326 |
|
// TODO: test what happens when no PCRE_NEWLINE_* flag is set. |
327 |
|
// Alas, the answer depends on how pcre was compiled. |
328 |
} |
} |
329 |
|
|
330 |
static void TestExtract() { |
static void TestExtract() { |