mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-11480 added tests for regex with capture groups that do not participate in match.
X-SVN-Rev: 37816
This commit is contained in:
parent
633e6d1d7b
commit
57ac300668
2 changed files with 32 additions and 6 deletions
|
@ -487,7 +487,7 @@ uregex_matches64(URegularExpression *regexp,
|
|||
*
|
||||
* <p>If the match succeeds then more information can be obtained via the
|
||||
* <code>uregexp_start()</code>, <code>uregexp_end()</code>,
|
||||
* and <code>uregexp_group()</code> functions.</p>
|
||||
* and <code>uregex_group()</code> functions.</p>
|
||||
*
|
||||
* @param regexp The compiled regular expression.
|
||||
* @param startIndex The input string (native) index at which to begin matching, or
|
||||
|
@ -516,7 +516,7 @@ uregex_lookingAt(URegularExpression *regexp,
|
|||
*
|
||||
* <p>If the match succeeds then more information can be obtained via the
|
||||
* <code>uregexp_start()</code>, <code>uregexp_end()</code>,
|
||||
* and <code>uregexp_group()</code> functions.</p>
|
||||
* and <code>uregex_group()</code> functions.</p>
|
||||
*
|
||||
* @param regexp The compiled regular expression.
|
||||
* @param startIndex The input string (native) index at which to begin matching, or
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
#include "intltest.h"
|
||||
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "unicode/localpointer.h"
|
||||
#include "unicode/regex.h"
|
||||
#include "unicode/uchar.h"
|
||||
|
@ -31,13 +35,12 @@
|
|||
#include "unicode/uregex.h"
|
||||
#include "unicode/usetiter.h"
|
||||
#include "unicode/ustring.h"
|
||||
#include "unicode/utext.h"
|
||||
|
||||
#include "regextst.h"
|
||||
#include "regexcmp.h"
|
||||
#include "uvector.h"
|
||||
#include "util.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "cmemory.h"
|
||||
#include "cstring.h"
|
||||
#include "uinvchar.h"
|
||||
|
@ -5780,7 +5783,7 @@ void RegexTest::TestBug11371() {
|
|||
void RegexTest::TestBug11480() {
|
||||
// C API, get capture group of a group that does not participate in the match.
|
||||
// (Returns a zero length string, with nul termination,
|
||||
// indistinguishable from a group with a zero lenght match.)
|
||||
// indistinguishable from a group with a zero length match.)
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
URegularExpression *re = uregex_openC("(A)|(B)", 0, NULL, &status);
|
||||
|
@ -5796,6 +5799,29 @@ void RegexTest::TestBug11480() {
|
|||
REGEX_ASSERT(buf[1] == 0);
|
||||
REGEX_ASSERT(buf[2] == 13);
|
||||
uregex_close(re);
|
||||
|
||||
// UText C++ API, length of match is 0 for non-participating matches.
|
||||
UText ut = UTEXT_INITIALIZER;
|
||||
utext_openUnicodeString(&ut, &text, &status);
|
||||
RegexMatcher matcher(UnicodeString("(A)|(B)"), 0, status);
|
||||
REGEX_CHECK_STATUS;
|
||||
matcher.reset(&ut);
|
||||
REGEX_ASSERT(matcher.lookingAt(0, status));
|
||||
|
||||
// UText C++ API, Capture group 1 matches "A", position 0, length 1.
|
||||
int64_t groupLen = -666;
|
||||
UText group = UTEXT_INITIALIZER;
|
||||
matcher.group(1, &group, groupLen, status);
|
||||
REGEX_CHECK_STATUS;
|
||||
REGEX_ASSERT(groupLen == 1);
|
||||
REGEX_ASSERT(utext_getNativeIndex(&group) == 0);
|
||||
|
||||
// Capture group 2, the (B), does not participate in the match.
|
||||
matcher.group(2, &group, groupLen, status);
|
||||
REGEX_CHECK_STATUS;
|
||||
REGEX_ASSERT(groupLen == 0);
|
||||
REGEX_ASSERT(matcher.start(2, status) == -1);
|
||||
REGEX_CHECK_STATUS;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue