| OLD | NEW |
| 1 /******************************************************************** | 1 /******************************************************************** |
| 2 * COPYRIGHT: | 2 * COPYRIGHT: |
| 3 * Copyright (c) 2004-2014, International Business Machines Corporation and | 3 * Copyright (c) 2004-2015, International Business Machines Corporation and |
| 4 * others. All Rights Reserved. | 4 * others. All Rights Reserved. |
| 5 ********************************************************************/ | 5 ********************************************************************/ |
| 6 /*******************************************************************************
* | 6 /*******************************************************************************
* |
| 7 * | 7 * |
| 8 * File reapits.c | 8 * File reapits.c |
| 9 * | 9 * |
| 10 ********************************************************************************
*/ | 10 ********************************************************************************
*/ |
| 11 /*C API TEST FOR Regular Expressions */ | 11 /*C API TEST FOR Regular Expressions */ |
| 12 /** | 12 /** |
| 13 * This is an API test for ICU regular expressions in C. It doesn't test very
many cases, and doesn't | 13 * This is an API test for ICU regular expressions in C. It doesn't test very
many cases, and doesn't |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 bufCap = UPRV_LENGTHOF(buf); | 1015 bufCap = UPRV_LENGTHOF(buf); |
| 1016 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); | 1016 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); |
| 1017 TEST_ASSERT_SUCCESS(status); | 1017 TEST_ASSERT_SUCCESS(status); |
| 1018 TEST_ASSERT_STRING("some other", buf, TRUE); | 1018 TEST_ASSERT_STRING("some other", buf, TRUE); |
| 1019 | 1019 |
| 1020 /* Match has \u \U escapes */ | 1020 /* Match has \u \U escapes */ |
| 1021 uregex_find(re, 0, &status); | 1021 uregex_find(re, 0, &status); |
| 1022 TEST_ASSERT_SUCCESS(status); | 1022 TEST_ASSERT_SUCCESS(status); |
| 1023 bufPtr = buf; | 1023 bufPtr = buf; |
| 1024 bufCap = UPRV_LENGTHOF(buf); | 1024 bufCap = UPRV_LENGTHOF(buf); |
| 1025 u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", UPRV_LENGTHOF(re
pl)); | 1025 u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ \\$ \\abc", UPRV_LENGTHOF(
repl)); |
| 1026 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); | 1026 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); |
| 1027 TEST_ASSERT_SUCCESS(status); | 1027 TEST_ASSERT_SUCCESS(status); |
| 1028 TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); | 1028 TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); |
| 1029 | 1029 |
| 1030 /* Bug 6813, parameter check of NULL destCapacity; crashed before fix. *
/ | 1030 /* Bug 6813, parameter check of NULL destCapacity; crashed before fix. *
/ |
| 1031 status = U_ZERO_ERROR; | 1031 status = U_ZERO_ERROR; |
| 1032 uregex_find(re, 0, &status); | 1032 uregex_find(re, 0, &status); |
| 1033 TEST_ASSERT_SUCCESS(status); | 1033 TEST_ASSERT_SUCCESS(status); |
| 1034 bufPtr = buf; | 1034 bufPtr = buf; |
| 1035 status = U_BUFFER_OVERFLOW_ERROR; | 1035 status = U_BUFFER_OVERFLOW_ERROR; |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1747 TEST_ASSERT_SUCCESS(status); | 1747 TEST_ASSERT_SUCCESS(status); |
| 1748 | 1748 |
| 1749 result = uregex_findNext(re, &status); | 1749 result = uregex_findNext(re, &status); |
| 1750 TEST_ASSERT(result == FALSE); | 1750 TEST_ASSERT(result == FALSE); |
| 1751 TEST_ASSERT_SUCCESS(status); | 1751 TEST_ASSERT_SUCCESS(status); |
| 1752 | 1752 |
| 1753 uregex_close(re); | 1753 uregex_close(re); |
| 1754 } | 1754 } |
| 1755 | 1755 |
| 1756 /* | 1756 /* |
| 1757 * group() | 1757 * groupUText() |
| 1758 */ | 1758 */ |
| 1759 { | 1759 { |
| 1760 UChar text1[80]; | 1760 UChar text1[80]; |
| 1761 UText *actual; | 1761 UText *actual; |
| 1762 UBool result; | 1762 UBool result; |
| 1763 | 1763 int64_t groupLen = 0; |
| 1764 const char str_abcinteriordef[] = { 0x61, 0x62, 0x63, 0x20, 0x69, 0x6e,
0x74, 0x65, 0x72, 0x69, 0x6f, 0x72, 0x20, 0x64, 0x65, 0x66, 0x00 }; /* abc inter
ior def */ | 1764 UChar groupBuf[20]; |
| 1765 const char str_interior[] = { 0x20, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x69,
0x6f, 0x72, 0x20, 0x00 }; /* ' interior ' */ | |
| 1766 | |
| 1767 | 1765 |
| 1768 u_uastrncpy(text1, "noise abc interior def, and this is off the end", U
PRV_LENGTHOF(text1)); | 1766 u_uastrncpy(text1, "noise abc interior def, and this is off the end", U
PRV_LENGTHOF(text1)); |
| 1769 | 1767 |
| 1770 status = U_ZERO_ERROR; | 1768 status = U_ZERO_ERROR; |
| 1771 re = uregex_openC("abc(.*?)def", 0, NULL, &status); | 1769 re = uregex_openC("abc(.*?)def", 0, NULL, &status); |
| 1772 TEST_ASSERT_SUCCESS(status); | 1770 TEST_ASSERT_SUCCESS(status); |
| 1773 | 1771 |
| 1774 uregex_setText(re, text1, -1, &status); | 1772 uregex_setText(re, text1, -1, &status); |
| 1775 result = uregex_find(re, 0, &status); | 1773 result = uregex_find(re, 0, &status); |
| 1776 TEST_ASSERT(result==TRUE); | 1774 TEST_ASSERT(result==TRUE); |
| 1777 | 1775 |
| 1778 /* Capture Group 0, the full match. Should succeed. */ | |
| 1779 status = U_ZERO_ERROR; | |
| 1780 actual = uregex_groupUTextDeep(re, 0, NULL, &status); | |
| 1781 TEST_ASSERT_SUCCESS(status); | |
| 1782 TEST_ASSERT_UTEXT(str_abcinteriordef, actual); | |
| 1783 utext_close(actual); | |
| 1784 | |
| 1785 /* Capture Group 0 with shallow clone API. Should succeed. */ | 1776 /* Capture Group 0 with shallow clone API. Should succeed. */ |
| 1786 status = U_ZERO_ERROR; | 1777 status = U_ZERO_ERROR; |
| 1787 { | 1778 actual = uregex_groupUText(re, 0, NULL, &groupLen, &status); |
| 1788 int64_t group_len; | 1779 TEST_ASSERT_SUCCESS(status); |
| 1789 int32_t len16; | |
| 1790 UErrorCode shallowStatus = U_ZERO_ERROR; | |
| 1791 int64_t nativeIndex; | |
| 1792 UChar *groupChars; | |
| 1793 UText groupText = UTEXT_INITIALIZER; | |
| 1794 | 1780 |
| 1795 actual = uregex_groupUText(re, 0, NULL, &group_len, &status); | 1781 TEST_ASSERT(utext_getNativeIndex(actual) == 6); /* index of "abc " with
in "noise abc ..." */ |
| 1796 TEST_ASSERT_SUCCESS(status); | 1782 TEST_ASSERT(groupLen == 16); /* length of "abc interior def" */ |
| 1783 utext_extract(actual, 6 /*start index */, 6+16 /*limit index*/, groupBuf
, sizeof(groupBuf), &status); |
| 1797 | 1784 |
| 1798 nativeIndex = utext_getNativeIndex(actual); | 1785 TEST_ASSERT_STRING("abc interior def", groupBuf, TRUE); |
| 1799 /* Following returns U_INDEX_OUTOFBOUNDS_ERROR... looks like a bug
in ucstrFuncs UTextFuncs [utext.cpp] */ | |
| 1800 /* len16 = utext_extract(actual, nativeIndex, nativeIndex + group_l
en, NULL, 0, &shallowStatus); */ | |
| 1801 len16 = (int32_t)group_len; | |
| 1802 | |
| 1803 groupChars = (UChar *)malloc(sizeof(UChar)*(len16+1)); | |
| 1804 utext_extract(actual, nativeIndex, nativeIndex + group_len, groupCha
rs, len16+1, &shallowStatus); | |
| 1805 | |
| 1806 utext_openUChars(&groupText, groupChars, len16, &shallowStatus); | |
| 1807 | |
| 1808 TEST_ASSERT_UTEXT(str_abcinteriordef, &groupText); | |
| 1809 utext_close(&groupText); | |
| 1810 free(groupChars); | |
| 1811 } | |
| 1812 utext_close(actual); | 1786 utext_close(actual); |
| 1813 | 1787 |
| 1814 /* Capture group #1. Should succeed. */ | 1788 /* Capture group #1. Should succeed. */ |
| 1815 status = U_ZERO_ERROR; | 1789 status = U_ZERO_ERROR; |
| 1816 actual = uregex_groupUTextDeep(re, 1, NULL, &status); | 1790 |
| 1791 actual = uregex_groupUText(re, 1, NULL, &groupLen, &status); |
| 1817 TEST_ASSERT_SUCCESS(status); | 1792 TEST_ASSERT_SUCCESS(status); |
| 1818 TEST_ASSERT_UTEXT(str_interior, actual); | 1793 TEST_ASSERT(9 == utext_getNativeIndex(actual)); /* index of " interio
r " within "noise abc interior def ... " */ |
| 1794 /* (within the str
ing text1) */ |
| 1795 TEST_ASSERT(10 == groupLen); /* length of " interi
or " */ |
| 1796 utext_extract(actual, 9 /*start index*/, 9+10 /*limit index*/, groupBuf,
sizeof(groupBuf), &status); |
| 1797 TEST_ASSERT_STRING(" interior ", groupBuf, TRUE); |
| 1798 |
| 1819 utext_close(actual); | 1799 utext_close(actual); |
| 1820 | 1800 |
| 1821 /* Capture group out of range. Error. */ | 1801 /* Capture group out of range. Error. */ |
| 1822 status = U_ZERO_ERROR; | 1802 status = U_ZERO_ERROR; |
| 1823 actual = uregex_groupUTextDeep(re, 2, NULL, &status); | 1803 actual = uregex_groupUText(re, 2, NULL, &groupLen, &status); |
| 1824 TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR); | 1804 TEST_ASSERT(status == U_INDEX_OUTOFBOUNDS_ERROR); |
| 1825 TEST_ASSERT(utext_nativeLength(actual) == 0); | |
| 1826 utext_close(actual); | 1805 utext_close(actual); |
| 1827 | 1806 |
| 1828 uregex_close(re); | 1807 uregex_close(re); |
| 1829 | |
| 1830 } | 1808 } |
| 1831 | 1809 |
| 1832 /* | 1810 /* |
| 1833 * replaceFirst() | 1811 * replaceFirst() |
| 1834 */ | 1812 */ |
| 1835 { | 1813 { |
| 1836 UChar text1[80]; | 1814 UChar text1[80]; |
| 1837 UChar text2[80]; | 1815 UChar text2[80]; |
| 1838 UText replText = UTEXT_INITIALIZER; | 1816 UText replText = UTEXT_INITIALIZER; |
| 1839 UText *result; | 1817 UText *result; |
| 1840 const char str_Replxxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0
x20, 0x3c, 0x61, 0x61, 0x3e, 0x20, 0x78, 0x31, 0x78, 0x20, 0x78, 0x2e, 0x2e, 0x2
e, 0x78, 0x2e, 0x00 }; /* Replace <aa> x1x x...x. */ | 1818 const char str_Replxxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x63, 0x65, 0
x20, 0x3c, 0x61, 0x61, 0x3e, 0x20, 0x78, 0x31, 0x78, 0x20, 0x78, 0x2e, 0x2e, 0x2
e, 0x78, 0x2e, 0x00 }; /* Replace <aa> x1x x...x. */ |
| 1841 const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x6
3, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ | 1819 const char str_Nomatchhere[] = { 0x4e, 0x6f, 0x20, 0x6d, 0x61, 0x74, 0x6
3, 0x68, 0x20, 0x68, 0x65, 0x72, 0x65, 0x2e, 0x00 }; /* No match here. */ |
| 1842 const char str_u00411U00000042a[] = { 0x5c, 0x5c, 0x5c, 0x75, 0x30, 0x3
0, 0x34, 0x31, 0x24, 0x31, 0x5c, 0x55, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34,
0x32, 0x24, 0x5c, 0x61, 0x00 }; /* \\\u0041$1\U00000042$\a */ | 1820 const char str_u00411U00000042a[] = { 0x5c, 0x5c, 0x5c, 0x75, 0x30, 0x3
0, 0x34, 0x31, 0x24, 0x31, |
| 1821 0x5c, 0x55, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x32, 0x5c,
0x24, 0x5c, 0x61, 0x00 }; /* \\\u0041$1\U00000042\$\a */ |
| 1843 const char str_1x[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ | 1822 const char str_1x[] = { 0x3c, 0x24, 0x31, 0x3e, 0x00 }; /* <$1> */ |
| 1844 const char str_ReplaceAaaBax1xxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x6
3, 0x65, 0x20, 0x5c, 0x41, 0x61, 0x61, 0x42, 0x24, 0x61, 0x20, 0x78, 0x31, 0x78,
0x20, 0x78, 0x2e, 0x2e, 0x2e, 0x78, 0x2e, 0x00 }; /* Replace \AaaB$a x1x x...x.
*/ | 1823 const char str_ReplaceAaaBax1xxx[] = { 0x52, 0x65, 0x70, 0x6c, 0x61, 0x6
3, 0x65, 0x20, 0x5c, 0x41, 0x61, 0x61, 0x42, 0x24, 0x61, 0x20, 0x78, 0x31, 0x78,
0x20, 0x78, 0x2e, 0x2e, 0x2e, 0x78, 0x2e, 0x00 }; /* Replace \AaaB$a x1x x...x.
*/ |
| 1845 status = U_ZERO_ERROR; | 1824 status = U_ZERO_ERROR; |
| 1846 u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); | 1825 u_uastrncpy(text1, "Replace xaax x1x x...x.", UPRV_LENGTHOF(text1)); |
| 1847 u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); | 1826 u_uastrncpy(text2, "No match here.", UPRV_LENGTHOF(text2)); |
| 1848 utext_openUTF8(&replText, str_1x, -1, &status); | 1827 utext_openUTF8(&replText, str_1x, -1, &status); |
| 1849 | 1828 |
| 1850 re = uregex_openC("x(.*?)x", 0, NULL, &status); | 1829 re = uregex_openC("x(.*?)x", 0, NULL, &status); |
| 1851 TEST_ASSERT_SUCCESS(status); | 1830 TEST_ASSERT_SUCCESS(status); |
| 1852 | 1831 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1940 bufCap = UPRV_LENGTHOF(buf); | 1919 bufCap = UPRV_LENGTHOF(buf); |
| 1941 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); | 1920 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); |
| 1942 TEST_ASSERT_SUCCESS(status); | 1921 TEST_ASSERT_SUCCESS(status); |
| 1943 TEST_ASSERT_STRING("some other", buf, TRUE); | 1922 TEST_ASSERT_STRING("some other", buf, TRUE); |
| 1944 | 1923 |
| 1945 /* Match has \u \U escapes */ | 1924 /* Match has \u \U escapes */ |
| 1946 uregex_find(re, 0, &status); | 1925 uregex_find(re, 0, &status); |
| 1947 TEST_ASSERT_SUCCESS(status); | 1926 TEST_ASSERT_SUCCESS(status); |
| 1948 bufPtr = buf; | 1927 bufPtr = buf; |
| 1949 bufCap = UPRV_LENGTHOF(buf); | 1928 bufCap = UPRV_LENGTHOF(buf); |
| 1950 u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ $ \\abc", UPRV_LENGTHOF(re
pl)); | 1929 u_uastrncpy(repl, "abc\\u0041\\U00000042 \\\\ \\$ \\abc", UPRV_LENGTHOF(
repl)); |
| 1951 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); | 1930 uregex_appendReplacement(re, repl, -1, &bufPtr, &bufCap, &status); |
| 1952 TEST_ASSERT_SUCCESS(status); | 1931 TEST_ASSERT_SUCCESS(status); |
| 1953 TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); | 1932 TEST_ASSERT_STRING("abcAB \\ $ abc", buf, TRUE); |
| 1954 | 1933 |
| 1955 uregex_close(re); | 1934 uregex_close(re); |
| 1956 } | 1935 } |
| 1957 | 1936 |
| 1958 | 1937 |
| 1959 /* | 1938 /* |
| 1960 * appendReplacement(), appendTail() checked in replaceFirst(), replaceAll(
). | 1939 * appendReplacement(), appendTail() checked in replaceFirst(), replaceAll(
). |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 TEST_ASSERT_SUCCESS(status); | 2298 TEST_ASSERT_SUCCESS(status); |
| 2320 | 2299 |
| 2321 uregex_findNext(re, &status); | 2300 uregex_findNext(re, &status); |
| 2322 TEST_ASSERT(status == U_REGEX_STOPPED_BY_CALLER); | 2301 TEST_ASSERT(status == U_REGEX_STOPPED_BY_CALLER); |
| 2323 | 2302 |
| 2324 uregex_close(re); | 2303 uregex_close(re); |
| 2325 } | 2304 } |
| 2326 | 2305 |
| 2327 | 2306 |
| 2328 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */ | 2307 #endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */ |
| OLD | NEW |