summaryrefslogtreecommitdiff
path: root/pcrecpp_unittest.cc
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2008-01-04 19:44:00 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2008-01-04 19:44:00 +0000
commitef49ade6a6462bb4a9f673b20b28d79da9cea129 (patch)
tree02b2166c1d523bbaab291dfbb9da0d77977f7332 /pcrecpp_unittest.cc
parent5ee150b95d7dc6e69aaaec8aae623c32b2b069d2 (diff)
downloadpcre-ef49ade6a6462bb4a9f673b20b28d79da9cea129.tar.gz
Craig's patch for the double-counting bug in global replace.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@297 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcrecpp_unittest.cc')
-rw-r--r--pcrecpp_unittest.cc55
1 files changed, 36 insertions, 19 deletions
diff --git a/pcrecpp_unittest.cc b/pcrecpp_unittest.cc
index 90351bf..4f49cb2 100644
--- a/pcrecpp_unittest.cc
+++ b/pcrecpp_unittest.cc
@@ -213,87 +213,103 @@ static void TestReplace() {
const char *original;
const char *single;
const char *global;
+ int global_count; // the expected return value from ReplaceAll
};
static const ReplaceTest tests[] = {
{ "(qu|[b-df-hj-np-tv-z]*)([a-z]+)",
"\\2\\1ay",
"the quick brown fox jumps over the lazy dogs.",
"ethay quick brown fox jumps over the lazy dogs.",
- "ethay ickquay ownbray oxfay umpsjay overay ethay azylay ogsday." },
+ "ethay ickquay ownbray oxfay umpsjay overay ethay azylay ogsday.",
+ 9 },
{ "\\w+",
"\\0-NOSPAM",
"paul.haahr@google.com",
"paul-NOSPAM.haahr@google.com",
- "paul-NOSPAM.haahr-NOSPAM@google-NOSPAM.com-NOSPAM" },
+ "paul-NOSPAM.haahr-NOSPAM@google-NOSPAM.com-NOSPAM",
+ 4 },
{ "^",
"(START)",
"foo",
"(START)foo",
- "(START)foo" },
+ "(START)foo",
+ 1 },
{ "^",
"(START)",
"",
"(START)",
- "(START)" },
+ "(START)",
+ 1 },
{ "$",
"(END)",
"",
"(END)",
- "(END)" },
+ "(END)",
+ 1 },
{ "b",
"bb",
"ababababab",
"abbabababab",
- "abbabbabbabbabb" },
+ "abbabbabbabbabb",
+ 5 },
{ "b",
"bb",
"bbbbbb",
"bbbbbbb",
- "bbbbbbbbbbbb" },
+ "bbbbbbbbbbbb",
+ 6 },
{ "b+",
"bb",
"bbbbbb",
"bb",
- "bb" },
+ "bb",
+ 1 },
{ "b*",
"bb",
"bbbbbb",
"bb",
- "bb" },
+ "bb",
+ 1 },
{ "b*",
"bb",
"aaaaa",
"bbaaaaa",
- "bbabbabbabbabbabb" },
+ "bbabbabbabbabbabb",
+ 6 },
{ "b*",
"bb",
"aa\naa\n",
"bbaa\naa\n",
- "bbabbabb\nbbabbabb\nbb" },
+ "bbabbabb\nbbabbabb\nbb",
+ 7 },
{ "b*",
"bb",
"aa\raa\r",
"bbaa\raa\r",
- "bbabbabb\rbbabbabb\rbb" },
+ "bbabbabb\rbbabbabb\rbb",
+ 7 },
{ "b*",
"bb",
"aa\r\naa\r\n",
"bbaa\r\naa\r\n",
- "bbabbabb\r\nbbabbabb\r\nbb" },
+ "bbabbabb\r\nbbabbabb\r\nbb",
+ 7 },
#ifdef SUPPORT_UTF8
{ "b*",
"bb",
"\xE3\x83\x9B\xE3\x83\xBC\xE3\x83\xA0\xE3\x81\xB8", // utf8
"bb\xE3\x83\x9B\xE3\x83\xBC\xE3\x83\xA0\xE3\x81\xB8",
- "bb\xE3\x83\x9B""bb""\xE3\x83\xBC""bb""\xE3\x83\xA0""bb""\xE3\x81\xB8""bb" },
+ "bb\xE3\x83\x9B""bb""\xE3\x83\xBC""bb""\xE3\x83\xA0""bb""\xE3\x81\xB8""bb",
+ 5 },
{ "b*",
"bb",
"\xE3\x83\x9B\r\n\xE3\x83\xBC\r\xE3\x83\xA0\n\xE3\x81\xB8\r\n", // utf8
"bb\xE3\x83\x9B\r\n\xE3\x83\xBC\r\xE3\x83\xA0\n\xE3\x81\xB8\r\n",
("bb\xE3\x83\x9B""bb\r\nbb""\xE3\x83\xBC""bb\rbb""\xE3\x83\xA0"
- "bb\nbb""\xE3\x81\xB8""bb\r\nbb") },
+ "bb\nbb""\xE3\x81\xB8""bb\r\nbb"),
+ 9 },
#endif
- { "", NULL, NULL, NULL, NULL }
+ { "", NULL, NULL, NULL, NULL, 0 }
};
#ifdef SUPPORT_UTF8
@@ -309,8 +325,9 @@ static void TestReplace() {
CHECK(re.Replace(t->rewrite, &one));
CHECK_EQ(one, t->single);
string all(t->original);
- CHECK(re.GlobalReplace(t->rewrite, &all) > 0);
+ const int replace_count = re.GlobalReplace(t->rewrite, &all);
CHECK_EQ(all, t->global);
+ CHECK_EQ(replace_count, t->global_count);
}
// One final test: test \r\n replacement when we're not in CRLF mode
@@ -318,14 +335,14 @@ static void TestReplace() {
RE re("b*", RE_Options(PCRE_NEWLINE_CR).set_utf8(support_utf8));
assert(re.error().empty());
string all("aa\r\naa\r\n");
- CHECK(re.GlobalReplace("bb", &all) > 0);
+ CHECK_EQ(re.GlobalReplace("bb", &all), 9);
CHECK_EQ(all, string("bbabbabb\rbb\nbbabbabb\rbb\nbb"));
}
{
RE re("b*", RE_Options(PCRE_NEWLINE_LF).set_utf8(support_utf8));
assert(re.error().empty());
string all("aa\r\naa\r\n");
- CHECK(re.GlobalReplace("bb", &all) > 0);
+ CHECK_EQ(re.GlobalReplace("bb", &all), 9);
CHECK_EQ(all, string("bbabbabb\rbb\nbbabbabb\rbb\nbb"));
}
// TODO: test what happens when no PCRE_NEWLINE_* flag is set.