/********************************************************************
* COPYRIGHT:
- * Copyright (c) 2002-2010, International Business Machines Corporation and
+ * Copyright (c) 2002-2012, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
// ICU Regular Expressions test, part of intltest.
//
+/*
+ NOTE!!
+
+ PLEASE be careful about ASCII assumptions in this test.
+ This test is one of the worst repeat offenders.
+ If you have questions, contact someone on the ICU PMC
+ who has access to an EBCDIC system.
+
+ */
+
#include "intltest.h"
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
#include "unicode/regex.h"
#include "unicode/uchar.h"
#include "unicode/ucnv.h"
+#include "unicode/uniset.h"
#include "unicode/ustring.h"
#include "regextst.h"
#include "uvector.h"
case 17: name = "Bug 7740";
if (exec) Bug7740();
break;
+ case 18: name = "Bug 8479";
+ if (exec) Bug8479();
+ break;
+ case 19: name = "Bug 7029";
+ if (exec) Bug7029();
+ break;
+ case 20: name = "CheckInvBufSize";
+ if (exec) CheckInvBufSize();
+ break;
+ case 21: name = "Bug 9283";
+ if (exec) Bug9283();
+ break;
default: name = "";
break; //needed to end loop
}
+
/**
* Calls utext_openUTF8 after, potentially, converting invariant text from the compilation codepage
* into ASCII.
*/
static UText* regextst_openUTF8FromInvariant(UText* ut, const char *inv, int64_t length, UErrorCode *status);
-static UText* regextst_openUTF8FromInvariant(UText *ut, const char *inv, int64_t length, UErrorCode *status) {
-#if U_CHARSET_FAMILY==U_ASCII_FAMILY
- return utext_openUTF8(ut, inv, length, status);
-#else
- char buf[1024];
-
- uprv_aestrncpy((uint8_t*)buf, (const uint8_t*)inv, length);
-
- return utext_openUTF8(ut, buf, length, status);
-#endif
-}
-
//---------------------------------------------------------------------------
//
// Error Checking / Reporting macros used in all of the tests.
utext_setNativeIndex(text, oldIndex);
}
+
+static char ASSERT_BUF[1024];
+
+const char* RegexTest::extractToAssertBuf(const UnicodeString& message) {
+ if(message.length()==0) {
+ strcpy(ASSERT_BUF, "[[empty UnicodeString]]");
+ } else {
+ UnicodeString buf;
+ IntlTest::prettify(message,buf);
+ if(buf.length()==0) {
+ strcpy(ASSERT_BUF, "[[escape() returned 0 chars]]");
+ } else {
+ buf.extract(0, 0x7FFFFFFF, ASSERT_BUF, sizeof(ASSERT_BUF)-1);
+ if(ASSERT_BUF[0]==0) {
+ ASSERT_BUF[0]=0;
+ for(int32_t i=0;i<buf.length();i++) {
+ UChar ch = buf[i];
+ sprintf(ASSERT_BUF+strlen(ASSERT_BUF),"\\u%02x",ch);
+ }
+ }
+ }
+ }
+ ASSERT_BUF[sizeof(ASSERT_BUF)-1] = 0;
+ return ASSERT_BUF;
+}
+
+
#define REGEX_VERBOSE_TEXT(text) {char buf[200];utextToPrintable(buf,sizeof(buf)/sizeof(buf[0]),text);logln("%s:%d: UText %s=\"%s\"", __FILE__, __LINE__, #text, buf);}
#define REGEX_CHECK_STATUS {if (U_FAILURE(status)) {dataerrln("%s:%d: RegexTest failure. status=%s", \
#define REGEX_ASSERT_L(expr, line) {if ((expr)==FALSE) { \
errln("RegexTest failure at line %d, from %d.", __LINE__, (line)); return;}}
+#define REGEX_ASSERT_UNISTR(ustr,inv) {if (!(ustr==inv)) {errln("%s:%d: RegexTest failure: REGEX_ASSERT_UNISTR(%s,%s) failed \n", __FILE__, __LINE__, extractToAssertBuf(ustr),inv);};}
+
+
+static UBool testUTextEqual(UText *uta, UText *utb) {
+ UChar32 ca = 0;
+ UChar32 cb = 0;
+ utext_setNativeIndex(uta, 0);
+ utext_setNativeIndex(utb, 0);
+ do {
+ ca = utext_next32(uta);
+ cb = utext_next32(utb);
+ if (ca != cb) {
+ break;
+ }
+ } while (ca != U_SENTINEL);
+ return ca == cb;
+}
+
+
/**
* @param expected expected text in UTF-8 (not platform) codepage
*/
return;
}
utext_setNativeIndex(actual, 0);
- if (utext_compare(&expectedText, -1, actual, -1) != 0) {
+ if (!testUTextEqual(&expectedText, actual)) {
char buf[201 /*21*/];
char expectedBuf[201];
utextToPrintable(buf, sizeof(buf)/sizeof(buf[0]), actual);
return;
}
utext_setNativeIndex(actual, 0);
- if (utext_compare(&expectedText, -1, actual, -1) != 0) {
+ if (!testUTextEqual(&expectedText, actual)) {
char buf[201 /*21*/];
char expectedBuf[201];
utextToPrintable(buf, sizeof(buf)/sizeof(buf[0]), actual);
*/
#define REGEX_ASSERT_UTEXT_INVARIANT(expected, actual) assertUTextInvariant((expected), (actual), __FILE__, __LINE__)
+/**
+ * This buffer ( inv_buf ) is used to hold the UTF-8 strings
+ * passed into utext_openUTF8. An error will be given if
+ * INV_BUFSIZ is too small. It's only used on EBCDIC systems.
+ */
+
+#define INV_BUFSIZ 2048 /* increase this if too small */
+
+static int32_t inv_next=0;
+
+#if U_CHARSET_FAMILY!=U_ASCII_FAMILY
+static char inv_buf[INV_BUFSIZ];
+#endif
+
+static UText* regextst_openUTF8FromInvariant(UText *ut, const char *inv, int64_t length, UErrorCode *status) {
+ if(length==-1) length=strlen(inv);
+#if U_CHARSET_FAMILY==U_ASCII_FAMILY
+ inv_next+=length;
+ return utext_openUTF8(ut, inv, length, status);
+#else
+ if(inv_next+length+1>INV_BUFSIZ) {
+ fprintf(stderr, "%s:%d Error: INV_BUFSIZ #defined to be %d but needs to be at least %d.\n",
+ __FILE__, __LINE__, INV_BUFSIZ, (inv_next+length+1));
+ *status = U_MEMORY_ALLOCATION_ERROR;
+ return NULL;
+ }
+
+ unsigned char *buf = (unsigned char*)inv_buf+inv_next;
+ uprv_aestrncpy(buf, (const uint8_t*)inv, length);
+ inv_next+=length;
+
+#if 0
+ fprintf(stderr, " Note: INV_BUFSIZ at %d, used=%d\n", INV_BUFSIZ, inv_next);
+#endif
+
+ return utext_openUTF8(ut, (const char*)buf, length, status);
+#endif
+}
+
//---------------------------------------------------------------------------
//
unEscapedInput.extract(textChars, inputUTF8Length+1, UTF8Converter.getAlias(), status);
utext_openUTF8(&inputText, textChars, inputUTF8Length, &status);
- REMatcher = REPattern->matcher(&inputText, RegexPattern::PATTERN_IS_UTEXT, status);
+ REMatcher = &REPattern->matcher(status)->reset(&inputText);
if (U_FAILURE(status)) {
errln("RegexTest failure in REPattern::matcher() at line %d (UTF8). Status = %s\n",
line, u_errorName(status));
// REGEX_TESTLM("a\N{LATIN SMALL LETTER B}c", "abc", FALSE, FALSE);
UParseError pe;
UErrorCode status = U_ZERO_ERROR;
- RegexPattern::compile("^(?:a?b?)*$", 0, pe, status);
- // REGEX_FIND("(?>(abc{2,4}?))(c*)", "<0>ab<1>cc</1><2>ccc</2></0>ddd");
+ RegexPattern *pattern;
+ pattern = RegexPattern::compile(UNICODE_STRING_SIMPLE("a\\u00dfx").unescape(), UREGEX_CASE_INSENSITIVE, pe, status);
+ RegexPatternDump(pattern);
+ RegexMatcher *m = pattern->matcher(UNICODE_STRING_SIMPLE("a\\u00dfxzzz").unescape(), status);
+ UBool result = m->find();
+ printf("result = %d\n", result);
+ // REGEX_FIND("", "<0>ab<1>cc</1><2>ccc</2></0>ddd");
// REGEX_FIND("(X([abc=X]+)+X)|(y[abc=]+)", "=XX====================");
}
exit(1);
n = pat1->split(" Now is the time ", fields, 10, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(n==5);
+ REGEX_ASSERT(n==6);
REGEX_ASSERT(fields[0]=="");
REGEX_ASSERT(fields[1]=="Now");
REGEX_ASSERT(fields[2]=="is");
n = pat1->split(" ", fields, 10, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(n==1);
+ REGEX_ASSERT(n==2);
REGEX_ASSERT(fields[0]=="");
+ REGEX_ASSERT(fields[1]=="");
fields[0] = "foo";
n = pat1->split("", fields, 10, status);
status = U_ZERO_ERROR;
n = pat1->split("<a>Now is <b>the time<c>", fields, 10, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(n==6);
+ REGEX_ASSERT(n==7);
REGEX_ASSERT(fields[0]=="");
REGEX_ASSERT(fields[1]=="a");
REGEX_ASSERT(fields[2]=="Now is ");
n = pat1->split(" <a>Now is <b>the time<c>", fields, 10, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(n==6);
+ REGEX_ASSERT(n==7);
REGEX_ASSERT(fields[0]==" ");
REGEX_ASSERT(fields[1]=="a");
REGEX_ASSERT(fields[2]=="Now is ");
REGEX_ASSERT(fields[2]=="Now is ");
REGEX_ASSERT(fields[3]=="b");
REGEX_ASSERT(fields[4]=="the time");
- REGEX_ASSERT(fields[5]=="c");
+ REGEX_ASSERT(fields[5]==""); // All text following "<c>" field delimiter.
REGEX_ASSERT(fields[6]=="foo");
status = U_ZERO_ERROR;
REGEX_ASSERT(fields[4]=="20");
delete pat1;
+ // Test split of string with empty trailing fields
+ pat1 = RegexPattern::compile(",", pe, status);
+ REGEX_CHECK_STATUS;
+ n = pat1->split("a,b,c,", fields, 10, status);
+ REGEX_CHECK_STATUS;
+ REGEX_ASSERT(n==4);
+ REGEX_ASSERT(fields[0]=="a");
+ REGEX_ASSERT(fields[1]=="b");
+ REGEX_ASSERT(fields[2]=="c");
+ REGEX_ASSERT(fields[3]=="");
+
+ n = pat1->split("a,,,", fields, 10, status);
+ REGEX_CHECK_STATUS;
+ REGEX_ASSERT(n==4);
+ REGEX_ASSERT(fields[0]=="a");
+ REGEX_ASSERT(fields[1]=="");
+ REGEX_ASSERT(fields[2]=="");
+ REGEX_ASSERT(fields[3]=="");
+ delete pat1;
+
+ // Split Separator with zero length match.
+ pat1 = RegexPattern::compile(":?", pe, status);
+ REGEX_CHECK_STATUS;
+ n = pat1->split("abc", fields, 10, status);
+ REGEX_CHECK_STATUS;
+ REGEX_ASSERT(n==5);
+ REGEX_ASSERT(fields[0]=="");
+ REGEX_ASSERT(fields[1]=="a");
+ REGEX_ASSERT(fields[2]=="b");
+ REGEX_ASSERT(fields[3]=="c");
+ REGEX_ASSERT(fields[4]=="");
+
+ delete pat1;
//
// RegexPattern::pattern()
{
UText re = UTEXT_INITIALIZER;
regextst_openUTF8FromInvariant(&re, "abc", -1, &status);
+ REGEX_VERBOSE_TEXT(&re);
RegexPattern *pat2;
pat2 = RegexPattern::compile(&re, flags, pe, status);
REGEX_CHECK_STATUS;
//
// Matcher creation and reset.
//
- RegexMatcher *m1 = pat2->matcher(&input1, RegexPattern::PATTERN_IS_UTEXT, status);
+ RegexMatcher *m1 = &pat2->matcher(status)->reset(&input1);
REGEX_CHECK_STATUS;
REGEX_ASSERT(m1->lookingAt(status) == TRUE);
const char str_abcdefthisisatest[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x00 }; /* abcdef this is a test */
const char str_0123456789[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x00 }; /* 0123456789 */
utext_openUTF8(&input, str_0123456789, -1, &status);
- RegexMatcher *matcher = pat->matcher(&input, RegexPattern::PATTERN_IS_UTEXT, status);
+ RegexMatcher *matcher = &pat->matcher(status)->reset(&input);
REGEX_CHECK_STATUS;
REGEX_ASSERT(matcher->lookingAt(status) == TRUE);
static const int32_t matchStarts[] = {0, 2, 4, 8};
utext_openUTF8(&input, str_abcabcabc, -1, &status);
// 012345678901234567
- RegexMatcher *matcher = pat->matcher(&input, RegexPattern::PATTERN_IS_UTEXT, status);
+ RegexMatcher *matcher = &pat->matcher(status)->reset(&input);
REGEX_CHECK_STATUS;
REGEX_ASSERT(matcher->find());
REGEX_ASSERT(matcher->start(status) == 1);
utext_openUTF8(&input, str_abcabcabc, -1, &status);
// 012345678901234567
- RegexMatcher *matcher = pat->matcher(&input, RegexPattern::PATTERN_IS_UTEXT, status);
+ RegexMatcher *matcher = &pat->matcher(status)->reset(&input);
REGEX_CHECK_STATUS;
REGEX_ASSERT(matcher->find());
REGEX_ASSERT(matcher->start(status) == 0);
utext_openUTF8(&dataText, data, -1, &status);
REGEX_CHECK_STATUS;
REGEX_VERBOSE_TEXT(&dataText);
- RegexMatcher *matcher = pat->matcher(&dataText, RegexPattern::PATTERN_IS_UTEXT, status);
+ RegexMatcher *matcher = &pat->matcher(status)->reset(&dataText);
//
// Plain vanilla matches.
const char str_abcdefg[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x00 }; /* abcdefg */
utext_openUTF8(&dataText, str_abcdefg, -1, &status);
- RegexMatcher *matcher2 = pat2->matcher(&dataText, RegexPattern::PATTERN_IS_UTEXT, status);
+ RegexMatcher *matcher2 = &pat2->matcher(status)->reset(&dataText);
REGEX_CHECK_STATUS;
const char str_11[] = { 0x24, 0x31, 0x24, 0x31, 0x00 }; /* $1$1 */
REGEX_CHECK_STATUS;
REGEX_ASSERT(result == &destText);
REGEX_ASSERT_UTEXT_UTF8(str_bcbcdefg, result);
-
- regextst_openUTF8FromInvariant(&replText, "The value of \\$1 is $1.", -1, &status);
+
+ const char str_v[24] = { 0x54, 0x68, 0x65, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x5c, 0x24, 0x31, 0x20, 0x69, 0x73, 0x20, 0x24, 0x31, 0x2e, 0x00 }; /* The value of \$1 is $1. */
+ utext_openUTF8(&replText, str_v, -1, &status);
+ REGEX_VERBOSE_TEXT(&replText);
result = matcher2->replaceFirst(&replText, NULL, status);
REGEX_CHECK_STATUS;
const char str_Thevalueof1isbcdefg[] = { 0x54, 0x68, 0x65, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x24, 0x31, 0x20, 0x69, 0x73, 0x20, 0x62, 0x63, 0x2e, 0x64, 0x65, 0x66, 0x67, 0x00 }; /* The value of $1 is bc.defg */
n = pat1->split(" Now is the time ", fields, 10, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(n==5);
+ REGEX_ASSERT(n==6);
REGEX_ASSERT(fields[0]=="");
REGEX_ASSERT(fields[1]=="Now");
REGEX_ASSERT(fields[2]=="is");
REGEX_ASSERT(fields[3]=="the");
REGEX_ASSERT(fields[4]=="time");
REGEX_ASSERT(fields[5]=="");
+ REGEX_ASSERT(fields[6]=="");
+ fields[2] = "*";
n = pat1->split(" ", fields, 10, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(n==1);
+ REGEX_ASSERT(n==2);
REGEX_ASSERT(fields[0]=="");
+ REGEX_ASSERT(fields[1]=="");
+ REGEX_ASSERT(fields[2]=="*");
fields[0] = "foo";
n = pat1->split("", fields, 10, status);
REGEX_CHECK_STATUS;
status = U_ZERO_ERROR;
+ fields[6] = fields[7] = "*";
n = pat1->split("<a>Now is <b>the time<c>", fields, 10, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(n==6);
+ REGEX_ASSERT(n==7);
REGEX_ASSERT(fields[0]=="");
REGEX_ASSERT(fields[1]=="a");
REGEX_ASSERT(fields[2]=="Now is ");
REGEX_ASSERT(fields[4]=="the time");
REGEX_ASSERT(fields[5]=="c");
REGEX_ASSERT(fields[6]=="");
+ REGEX_ASSERT(fields[7]=="*");
REGEX_ASSERT(status==U_ZERO_ERROR);
+ fields[6] = fields[7] = "*";
n = pat1->split(" <a>Now is <b>the time<c>", fields, 10, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(n==6);
+ REGEX_ASSERT(n==7);
REGEX_ASSERT(fields[0]==" ");
REGEX_ASSERT(fields[1]=="a");
REGEX_ASSERT(fields[2]=="Now is ");
REGEX_ASSERT(fields[4]=="the time");
REGEX_ASSERT(fields[5]=="c");
REGEX_ASSERT(fields[6]=="");
+ REGEX_ASSERT(fields[7]=="*");
status = U_ZERO_ERROR;
fields[6] = "foo";
- n = pat1->split(" <a>Now is <b>the time<c>", fields, 6, status);
+ n = pat1->split(" <a>Now is <b>the time<c> ", fields, 6, status);
REGEX_CHECK_STATUS;
REGEX_ASSERT(n==6);
REGEX_ASSERT(fields[0]==" ");
REGEX_ASSERT(fields[2]=="Now is ");
REGEX_ASSERT(fields[3]=="b");
REGEX_ASSERT(fields[4]=="the time");
- REGEX_ASSERT(fields[5]=="c");
+ REGEX_ASSERT(fields[5]==" ");
REGEX_ASSERT(fields[6]=="foo");
status = U_ZERO_ERROR;
REGEX_ASSERT(pat1->pattern() == "");
REGEX_ASSERT_UTEXT_UTF8("", pat1->patternText(status));
delete pat1;
-
- regextst_openUTF8FromInvariant(&re1, "(Hello, world)*", -1, &status);
+ const char *helloWorldInvariant = "(Hello, world)*";
+ regextst_openUTF8FromInvariant(&re1, helloWorldInvariant, -1, &status);
pat1 = RegexPattern::compile(&re1, pe, status);
REGEX_CHECK_STATUS;
- REGEX_ASSERT(pat1->pattern() == "(Hello, world)*");
+ REGEX_ASSERT_UNISTR(pat1->pattern(),"(Hello, world)*");
REGEX_ASSERT_UTEXT_INVARIANT("(Hello, world)*", pat1->patternText(status));
delete pat1;
RegexMatcher quotedStuffMat(UNICODE_STRING_SIMPLE("\\s*([\\'\\\"/])(.*?)\\1"), 0, status);
RegexMatcher commentMat (UNICODE_STRING_SIMPLE("\\s*(#.*)?$"), 0, status);
- RegexMatcher flagsMat (UNICODE_STRING_SIMPLE("\\s*([ixsmdteDEGLMvabtyYzZ2-9]*)([:letter:]*)"), 0, status);
+ RegexMatcher flagsMat (UNICODE_STRING_SIMPLE("\\s*([ixsmdteDEGLMQvabtyYzZ2-9]*)([:letter:]*)"), 0, status);
RegexMatcher lineMat(UNICODE_STRING_SIMPLE("(.*?)\\r?\\n"), testString, 0, status);
UnicodeString testPattern; // The pattern for test from the test file.
break;
}
}
- nativeIndex = UTEXT_GETNATIVEINDEX(utext);
+ nativeIndex = (int32_t)UTEXT_GETNATIVEINDEX(utext);
return couldFind;
}
if (flags.indexOf((UChar)0x44) >= 0) { // 'D' flag
bflags |= UREGEX_UNIX_LINES;
}
+ if (flags.indexOf((UChar)0x51) >= 0) { // 'Q' flag
+ bflags |= UREGEX_LITERAL;
+ }
callerPattern = RegexPattern::compile(pattern, bflags, pe, status);
goto cleanupAndReturn;
} else {
// Unexpected pattern compilation error.
- errln("Line %d: error %s compiling pattern.", line, u_errorName(status));
+ dataerrln("Line %d: error %s compiling pattern.", line, u_errorName(status));
goto cleanupAndReturn;
}
}
utext_openUTF8(&inputText, inputChars, inputUTF8Length, &status);
if (status == U_ZERO_ERROR) {
- UTF8Matcher = UTF8Pattern->matcher(&inputText, RegexPattern::PATTERN_IS_UTEXT, status);
+ UTF8Matcher = &UTF8Pattern->matcher(status)->reset(&inputText);
REGEX_CHECK_STATUS_L(line);
}
// G option in test means that capture group data is not available in the
// expected results, so the check needs to be suppressed.
if (isMatch == FALSE && groupStarts.size() != 0) {
- errln("Error at line %d: Match expected, but none found.", line);
+ dataerrln("Error at line %d: Match expected, but none found.", line);
failed = TRUE;
goto cleanupAndReturn;
} else if (UTF8Matcher != NULL && isUTF8Match == FALSE && groupStarts.size() != 0) {
ucnv_close(conv);
if (U_FAILURE(status)) {
errln("ucnv_toUChars: ICU Error \"%s\"\n", u_errorName(status));
- delete retPtr;
+ delete []retPtr;
retPtr = 0;
ulen = 0;
};
//
// Run the test, check for expected match/don't match result.
//
- RegexMatcher *testMat = testPat->matcher(&inputText, RegexPattern::PATTERN_IS_UTEXT, status);
+ RegexMatcher *testMat = &testPat->matcher(status)->reset(&inputText);
UBool found = testMat->find();
UBool expected = FALSE;
if (fields[2].indexOf(UChar_y) >=0) {
REGEX_ASSERT(resultText == &bufferText);
utext_setNativeIndex(resultText, 0);
utext_setNativeIndex(&text1, 0);
- REGEX_ASSERT(utext_compare(resultText, -1, &text1, -1) == 0);
+ REGEX_ASSERT(testUTextEqual(resultText, &text1));
resultText = uregex_getUText(re, &bufferText, &status);
REGEX_CHECK_STATUS;
REGEX_ASSERT(resultText == &bufferText);
utext_setNativeIndex(resultText, 0);
utext_setNativeIndex(&text1, 0);
- REGEX_ASSERT(utext_compare(resultText, -1, &text1, -1) == 0);
+ REGEX_ASSERT(testUTextEqual(resultText, &text1));
/* Then set a UChar * */
uregex_setText(re, text2Chars, 7, &status);
REGEX_ASSERT(resultText == &bufferText);
utext_setNativeIndex(resultText, 0);
utext_setNativeIndex(&text2, 0);
- REGEX_ASSERT(utext_compare(resultText, -1, &text2, -1) == 0);
+ REGEX_ASSERT(testUTextEqual(resultText, &text2));
uregex_close(re);
utext_close(&text1);
delete m;
}
+// Bug 8479: was crashing whith a Bogus UnicodeString as input.
+
+void RegexTest::Bug8479() {
+ UErrorCode status = U_ZERO_ERROR;
+ RegexMatcher* const pMatcher = new RegexMatcher("\\Aboo\\z", UREGEX_DOTALL|UREGEX_CASE_INSENSITIVE, status);
+ REGEX_CHECK_STATUS;
+ if (U_SUCCESS(status))
+ {
+ UnicodeString str;
+ str.setToBogus();
+ pMatcher->reset(str);
+ status = U_ZERO_ERROR;
+ pMatcher->matches(status);
+ REGEX_ASSERT(status == U_ILLEGAL_ARGUMENT_ERROR);
+ delete pMatcher;
+ }
+}
+// Bug 7029
+void RegexTest::Bug7029() {
+ UErrorCode status = U_ZERO_ERROR;
+
+ RegexMatcher* const pMatcher = new RegexMatcher(".", 0, status);
+ UnicodeString text = "abc.def";
+ UnicodeString splits[10];
+ REGEX_CHECK_STATUS;
+ int32_t numFields = pMatcher->split(text, splits, 10, status);
+ REGEX_CHECK_STATUS;
+ REGEX_ASSERT(numFields == 8);
+ delete pMatcher;
+}
+
+// Bug 9283
+// This test is checking for the existance of any supplemental characters that case-fold
+// to a bmp character.
+//
+// At the time of this writing there are none. If any should appear in a subsequent release
+// of Unicode, the code in regular expressions compilation that determines the longest
+// posssible match for a literal string will need to be enhanced.
+//
+// See file regexcmp.cpp, case URX_STRING_I in RegexCompile::maxMatchLength()
+// for details on what to do in case of a failure of this test.
+//
+void RegexTest::Bug9283() {
+ UErrorCode status = U_ZERO_ERROR;
+ UnicodeSet supplementalsWithCaseFolding("[[:CWCF:]&[\\U00010000-\\U0010FFFF]]", status);
+ REGEX_CHECK_STATUS;
+ int32_t index;
+ UChar32 c;
+ for (index=0; ; index++) {
+ c = supplementalsWithCaseFolding.charAt(index);
+ if (c == -1) {
+ break;
+ }
+ UnicodeString cf = UnicodeString(c).foldCase();
+ REGEX_ASSERT(cf.length() >= 2);
+ }
+}
+
+
+void RegexTest::CheckInvBufSize() {
+ if(inv_next>=INV_BUFSIZ) {
+ errln("%s: increase #define of INV_BUFSIZ ( is %d but needs to be at least %d )\n",
+ __FILE__, INV_BUFSIZ, inv_next);
+ } else {
+ logln("%s: INV_BUFSIZ is %d, usage %d\n", __FILE__, INV_BUFSIZ, inv_next);
+ }
+}
+
#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */