From 93db088bd341b5e4792c9f432908faf4cf9a0dfc Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Tue, 23 Mar 2004 05:20:48 +0000 Subject: [PATCH] ICU-2421 more regexp C API tests X-SVN-Rev: 14731 --- icu4c/source/test/cintltst/reapits.c | 232 ++++++++++++++++++++++++++- 1 file changed, 231 insertions(+), 1 deletion(-) diff --git a/icu4c/source/test/cintltst/reapits.c b/icu4c/source/test/cintltst/reapits.c index c788af3fa2..c4fe7c4b76 100644 --- a/icu4c/source/test/cintltst/reapits.c +++ b/icu4c/source/test/cintltst/reapits.c @@ -85,6 +85,8 @@ void TestRegexCAPI(void) { TEST_ASSERT(len==(int32_t)strlen("abc*")); uregex_close(re); + + /* TODO: Open with ParseError parameter */ } /* @@ -166,10 +168,238 @@ void TestRegexCAPI(void) { TEST_ASSERT(u_strncmp(resultPat, pat, 3) == 0); TEST_ASSERT(u_strlen(resultPat) == 3); uregex_close(re); + } + /* + * flags() + */ + { + int32_t t; + + status = U_ZERO_ERROR; + re = uregex_open(pat, -1, 0, NULL, &status); + t = uregex_flags(re, &status); + TEST_ASSERT_SUCCESS(status); + TEST_ASSERT(t == 0); + uregex_close(re); + + status = U_ZERO_ERROR; + re = uregex_open(pat, -1, 0, NULL, &status); + t = uregex_flags(re, &status); + TEST_ASSERT_SUCCESS(status); + TEST_ASSERT(t == 0); + uregex_close(re); + + status = U_ZERO_ERROR; + re = uregex_open(pat, -1, UREGEX_CASE_INSENSITIVE | UREGEX_DOTALL, NULL, &status); + t = uregex_flags(re, &status); + TEST_ASSERT_SUCCESS(status); + TEST_ASSERT(t == (UREGEX_CASE_INSENSITIVE | UREGEX_DOTALL)); + uregex_close(re); + } + + /* + * setText() and lookingAt() + */ + { + UChar text1[50]; + UChar text2[50]; + UBool result; + u_uastrncpy(text1, "abcccd", sizeof(text1)/2); + u_uastrncpy(text2, "abcccxd", sizeof(text2)/2); + status = U_ZERO_ERROR; + u_uastrncpy(pat, "abc*d", sizeof(pat)/2); + re = uregex_open(pat, -1, 0, NULL, &status); + + uregex_setText(re, text1, -1, &status); + result = uregex_lookingAt(re, 0, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_setText(re, text2, -1, &status); + result = uregex_lookingAt(re, 0, &status); + TEST_ASSERT(result == FALSE); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_setText(re, text1, -1, &status); + result = uregex_lookingAt(re, 0, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_setText(re, text1, 5, &status); + result = uregex_lookingAt(re, 0, &status); + TEST_ASSERT(result == FALSE); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_setText(re, text1, 6, &status); + result = uregex_lookingAt(re, 0, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT_SUCCESS(status); + + uregex_close(re); + } + + + /* + * getText() + */ + { + UChar text1[50]; + UChar text2[50]; + const UChar *result; + int32_t textLength; + + u_uastrncpy(text1, "abcccd", sizeof(text1)/2); + u_uastrncpy(text2, "abcccxd", sizeof(text2)/2); + status = U_ZERO_ERROR; + u_uastrncpy(pat, "abc*d", sizeof(pat)/2); + re = uregex_open(pat, -1, 0, NULL, &status); + + uregex_setText(re, text1, -1, &status); + result = uregex_getText(re, &textLength, &status); + TEST_ASSERT(result == text1); + TEST_ASSERT(textLength == -1); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_setText(re, text2, 7, &status); + result = uregex_getText(re, &textLength, &status); + TEST_ASSERT(result == text2); + TEST_ASSERT(textLength == 7); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_setText(re, text2, 4, &status); + result = uregex_getText(re, &textLength, &status); + TEST_ASSERT(result == text2); + TEST_ASSERT(textLength == 4); + TEST_ASSERT_SUCCESS(status); + uregex_close(re); + } + + /* + * matches() + */ + { + UChar text1[50]; + UBool result; + u_uastrncpy(text1, "abcccde", sizeof(text1)/2); + status = U_ZERO_ERROR; + u_uastrncpy(pat, "abc*d", sizeof(pat)/2); + re = uregex_open(pat, -1, 0, NULL, &status); + + uregex_setText(re, text1, -1, &status); + result = uregex_matches(re, 0, &status); + TEST_ASSERT(result == FALSE); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_setText(re, text1, 6, &status); + result = uregex_matches(re, 0, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_setText(re, text1, 6, &status); + result = uregex_matches(re, 1, &status); + TEST_ASSERT(result == FALSE); + TEST_ASSERT_SUCCESS(status); + uregex_close(re); } - + + + /* + * lookingAt() Used in setText test. + */ + + + /* + * find(), findNext, start, end, reset + */ + { + UChar text1[50]; + UBool result; + u_uastrncpy(text1, "012rx5rx890rxrx...", sizeof(text1)/2); + status = U_ZERO_ERROR; + re = uregex_openC("rx", 0, NULL, &status); + + uregex_setText(re, text1, -1, &status); + result = uregex_find(re, 0, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT(uregex_start(re, 0, &status) == 3); + TEST_ASSERT(uregex_end(re, 0, &status) == 5); + TEST_ASSERT_SUCCESS(status); + + result = uregex_find(re, 9, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT(uregex_start(re, 0, &status) == 11); + TEST_ASSERT(uregex_end(re, 0, &status) == 13); + TEST_ASSERT_SUCCESS(status); + + result = uregex_find(re, 14, &status); + TEST_ASSERT(result == FALSE); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_reset(re, 0, &status); + + result = uregex_findNext(re, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT(uregex_start(re, 0, &status) == 3); + TEST_ASSERT(uregex_end(re, 0, &status) == 5); + TEST_ASSERT_SUCCESS(status); + + result = uregex_findNext(re, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT(uregex_start(re, 0, &status) == 6); + TEST_ASSERT(uregex_end(re, 0, &status) == 8); + TEST_ASSERT_SUCCESS(status); + + status = U_ZERO_ERROR; + uregex_reset(re, 12, &status); + + result = uregex_findNext(re, &status); + TEST_ASSERT(result == TRUE); + TEST_ASSERT(uregex_start(re, 0, &status) == 13); + TEST_ASSERT(uregex_end(re, 0, &status) == 15); + TEST_ASSERT_SUCCESS(status); + + result = uregex_findNext(re, &status); + TEST_ASSERT(result == FALSE); + TEST_ASSERT_SUCCESS(status); + + uregex_close(re); + } + + /* + * groupCount + */ + { + int32_t result; + + status = U_ZERO_ERROR; + re = uregex_openC("abc", 0, NULL, &status); + result = uregex_groupCount(re, &status); + TEST_ASSERT_SUCCESS(status); + TEST_ASSERT(result == 0); + uregex_close(re); + + status = U_ZERO_ERROR; + re = uregex_openC("abc(def)(ghi(j))", 0, NULL, &status); + result = uregex_groupCount(re, &status); + TEST_ASSERT_SUCCESS(status); + TEST_ASSERT(result == 3); + uregex_close(re); + + } + + + }