16f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/*
26f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org********************************************************************************
36f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*   Copyright (C) 1999-2013 International Business Machines Corporation and
46f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*   others. All Rights Reserved.
56f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org********************************************************************************
66f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*   Date        Name        Description
76f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*   10/20/99    alan        Creation.
86f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*   03/22/2000  Madhu       Added additional tests
96f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org********************************************************************************
106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org*/
116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <stdio.h>
136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include <string.h>
156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/utypes.h"
166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "usettest.h"
176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ucnv.h"
186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/uniset.h"
196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/uchar.h"
206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/usetiter.h"
216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/ustring.h"
226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/parsepos.h"
236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/symtable.h"
246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "unicode/uversion.h"
256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#include "hash.h"
266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define TEST_ASSERT_SUCCESS(status) {if (U_FAILURE(status)) { \
306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    dataerrln("fail in file \"%s\", line %d: \"%s\"", __FILE__, __LINE__, \
316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u_errorName(status));}}
326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define TEST_ASSERT(expr) {if (!(expr)) { \
346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    dataerrln("fail in file \"%s\", line %d", __FILE__, __LINE__); }}
356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeString operator+(const UnicodeString& left, const UnicodeSet& set) {
376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat;
386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.toPattern(pat);
396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return left + UnicodeSetTest::escape(pat);
406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#define CASE(id,test) case id:                          \
436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          name = #test;                 \
446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          if (exec) {                   \
456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                              logln(#test "---");       \
466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                              logln();                  \
476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                              test();                   \
486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          }                             \
496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          break
506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::UnicodeSetTest() : utf8Cnv(NULL) {
526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUConverter *UnicodeSetTest::openUTF8Converter() {
556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(utf8Cnv==NULL) {
566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode errorCode=U_ZERO_ERROR;
576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        utf8Cnv=ucnv_open("UTF-8", &errorCode);
586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return utf8Cnv;
606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::~UnicodeSetTest() {
636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ucnv_close(utf8Cnv);
646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::runIndexedTest(int32_t index, UBool exec,
686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               const char* &name, char* /*par*/) {
696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // if (exec) logln((UnicodeString)"TestSuite UnicodeSetTest");
706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    switch (index) {
716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(0,TestPatterns);
726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(1,TestAddRemove);
736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(2,TestCategories);
746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(3,TestCloneEqualHash);
756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(4,TestMinimalRep);
766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(5,TestAPI);
776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(6,TestScriptSet);
786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(7,TestPropertySet);
796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(8,TestClone);
806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(9,TestExhaustive);
816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(10,TestToPattern);
826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(11,TestIndexOf);
836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(12,TestStrings);
846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(13,Testj2268);
856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(14,TestCloseOver);
866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(15,TestEscapePattern);
876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(16,TestInvalidCodePoint);
886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(17,TestSymbolTable);
896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(18,TestSurrogate);
906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(19,TestPosixClasses);
916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(20,TestIteration);
926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(21,TestFreezable);
936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(22,TestSpan);
946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE(23,TestStringSpan);
956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        default: name = ""; break;
966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic const char NOT[] = "%%%%";
1006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
1026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * UVector was improperly copying contents
1036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * This code will crash this is still true
1046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
1056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::Testj2268() {
1066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  UnicodeSet t;
1076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  t.add(UnicodeString("abc"));
1086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  UnicodeSet test(t);
1096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  UnicodeString ustrPat;
1106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  test.toPattern(ustrPat, TRUE);
1116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
1126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
1146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test toPattern().
1156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
1166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestToPattern() {
1176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
1186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test that toPattern() round trips with syntax characters and
1206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // whitespace.
1216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
1226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        static const char* OTHER_TOPATTERN_TESTS[] = {
1236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "[[:latin:]&[:greek:]]",
1246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "[[:latin:]-[:greek:]]",
1256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            "[:nonspacing mark:]",
1266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            NULL
1276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        };
1286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t j=0; OTHER_TOPATTERN_TESTS[j]!=NULL; ++j) {
1306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ec = U_ZERO_ERROR;
1316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeSet s(OTHER_TOPATTERN_TESTS[j], ec);
1326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
1336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                dataerrln((UnicodeString)"FAIL: bad pattern " + OTHER_TOPATTERN_TESTS[j] + " - " + UnicodeString(u_errorName(ec)));
1346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
1356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
1366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            checkPat(OTHER_TOPATTERN_TESTS[j], s);
1376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
1386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (UChar32 i = 0; i <= 0x10FFFF; ++i) {
1406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if ((i <= 0xFF && !u_isalpha(i)) || u_isspace(i)) {
1416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                // check various combinations to make sure they all work.
1436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (i != 0 && !toPatternAux(i, i)){
1446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    continue;
1456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
1466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (!toPatternAux(0, i)){
1476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    continue;
1486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
1496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if (!toPatternAux(i, 0xFFFF)){
1506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    continue;
1516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                }
1526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
1536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
1546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
1556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test pattern behavior of multicharacter strings.
1576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
1586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ec = U_ZERO_ERROR;
1596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet* s = new UnicodeSet("[a-z {aa} {ab}]", ec);
1606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // This loop isn't a loop.  It's here to make the compiler happy.
1626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // If you're curious, try removing it and changing the 'break'
1636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // statements (except for the last) to goto's.
1646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (;;) {
1656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) break;
1666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* exp1[] = {"aa", "ab", NOT, "ac", NULL};
1676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectToPattern(*s, "[a-z{aa}{ab}]", exp1);
1686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s->add("ac");
1706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* exp2[] = {"aa", "ab", "ac", NOT, "xy", NULL};
1716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectToPattern(*s, "[a-z{aa}{ab}{ac}]", exp2);
1726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s->applyPattern(UNICODE_STRING_SIMPLE("[a-z {\\{l} {r\\}}]"), ec);
1746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) break;
1756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* exp3[] = {"{l", "r}", NOT, "xy", NULL};
1766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectToPattern(*s, UNICODE_STRING_SIMPLE("[a-z{r\\}}{\\{l}]"), exp3);
1776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s->add("[]");
1796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* exp4[] = {"{l", "r}", "[]", NOT, "xy", NULL};
1806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectToPattern(*s, UNICODE_STRING_SIMPLE("[a-z{\\[\\]}{r\\}}{\\{l}]"), exp4);
1816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s->applyPattern(UNICODE_STRING_SIMPLE("[a-z {\\u4E01\\u4E02}{\\n\\r}]"), ec);
1836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) break;
1846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* exp5[] = {"\\u4E01\\u4E02", "\n\r", NULL};
1856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectToPattern(*s, UNICODE_STRING_SIMPLE("[a-z{\\u000A\\u000D}{\\u4E01\\u4E02}]"), exp5);
1866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // j2189
1886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s->clear();
1896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s->add(UnicodeString("abc", ""));
1906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s->add(UnicodeString("abc", ""));
1916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const char* exp6[] = {"abc", NOT, "ab", NULL};
1926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            expectToPattern(*s, "[{abc}]", exp6);
1936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            break;
1956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
1966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
1976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) errln("FAIL: pattern parse error");
1986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete s;
1996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // JB#3400: For 2 character ranges prefer [ab] to [a-b]
2026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet s;
2036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.add((UChar)97, (UChar)98); // 'a', 'b'
2046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectToPattern(s, "[ab]", NULL);
2056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUBool UnicodeSetTest::toPatternAux(UChar32 start, UChar32 end) {
2086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // use Integer.toString because Utility.hex doesn't handle ints
2106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat = "";
2116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // TODO do these in hex
2126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //String source = "0x" + Integer.toString(start,16).toUpperCase();
2136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //if (start != end) source += "..0x" + Integer.toString(end,16).toUpperCase();
2146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString source;
2156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    source = source + (uint32_t)start;
2166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (start != end)
2176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        source = source + ".." + (uint32_t)end;
2186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet testSet;
2196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testSet.add(start, end);
2206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return checkPat(source, testSet);
2216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUBool UnicodeSetTest::checkPat(const UnicodeString& source,
2246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               const UnicodeSet& testSet) {
2256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // What we want to make sure of is that a pattern generated
2266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // by toPattern(), with or without escaped unprintables, can
2276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // be passed back into the UnicodeSet constructor.
2286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat0;
2296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testSet.toPattern(pat0, TRUE);
2316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!checkPat(source + " (escaped)", testSet, pat0)) return FALSE;
2336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //String pat1 = unescapeLeniently(pat0);
2356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //if (!checkPat(source + " (in code)", testSet, pat1)) return false;
2366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat2;
2386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    testSet.toPattern(pat2, FALSE);
2396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!checkPat(source, testSet, pat2)) return FALSE;
2406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //String pat3 = unescapeLeniently(pat2);
2426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // if (!checkPat(source + " (in code)", testSet, pat3)) return false;
2436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //logln(source + " => " + pat0 + ", " + pat1 + ", " + pat2 + ", " + pat3);
2456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)source + " => " + pat0 + ", " + pat2);
2466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return TRUE;
2476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUBool UnicodeSetTest::checkPat(const UnicodeString& source,
2506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               const UnicodeSet& testSet,
2516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                               const UnicodeString& pat) {
2526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
2536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet testSet2(pat, ec);
2546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (testSet2 != testSet) {
2556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"Fail toPattern: " + source + " => " + pat);
2566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return FALSE;
2576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return TRUE;
2596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
2626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::TestPatterns(void) {
2636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set;
2646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, UnicodeString("[[a-m]&[d-z]&[k-y]]", ""),  "km");
2656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, UnicodeString("[[a-z]-[m-y]-[d-r]]", ""),  "aczz");
2666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, UnicodeString("[a\\-z]", ""),  "--aazz");
2676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, UnicodeString("[-az]", ""),  "--aazz");
2686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, UnicodeString("[az-]", ""),  "--aazz");
2696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, UnicodeString("[[[a-z]-[aeiou]i]]", ""), "bdfnptvz");
2706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Throw in a test of complement
2726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.complement();
2736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString exp;
2746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.append((UChar)0x0000).append("aeeoouu").append((UChar)(0x007a+1)).append((UChar)0xFFFF);
2756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, exp);
2766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
2776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
2796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::TestCategories(void) {
2806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
2816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* pat = " [:Lu:] "; // Whitespace ok outside [:..:]
2826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set(pat, status);
2836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) {
2846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln((UnicodeString)"Fail: Can't construct set with " + pat + " - " + UnicodeString(u_errorName(status)));
2856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
2866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
2876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectContainment(set, pat, "ABC", "abc");
2886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
2896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
2906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar32 i;
2916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t failures = 0;
2926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Make sure generation of L doesn't pollute cached Lu set
2936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // First generate L, then Lu
2946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.applyPattern("[:L:]", status);
2956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
2966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i<0x200; ++i) {
2976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UBool l = u_isalpha((UChar)i);
2986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (l != set.contains(i)) {
2996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: L contains " + (unsigned short)i + " = " +
3006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  set.contains(i));
3016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (++failures == 10) break;
3026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.applyPattern("[:Lu:]", status);
3066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
3076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i<0x200; ++i) {
3086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UBool lu = (u_charType((UChar)i) == U_UPPERCASE_LETTER);
3096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (lu != set.contains(i)) {
3106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: Lu contains " + (unsigned short)i + " = " +
3116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  set.contains(i));
3126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (++failures == 20) break;
3136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
3146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
3166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
3176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::TestCloneEqualHash(void) {
3186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
3196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // set1 and set2 used to be built with the obsolete constructor taking
3206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // UCharCategory values; replaced with pattern constructors
3216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // markus 20030502
3226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *set1=new UnicodeSet(UNICODE_STRING_SIMPLE("\\p{Lowercase Letter}"), status); //  :Ll: Letter, lowercase
3236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *set1a=new UnicodeSet(UNICODE_STRING_SIMPLE("[:Ll:]"), status); //  Letter, lowercase
3246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)){
3256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln((UnicodeString)"FAIL: Can't construst set with category->Ll" + " - " + UnicodeString(u_errorName(status)));
3266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
3276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *set2=new UnicodeSet(UNICODE_STRING_SIMPLE("\\p{Decimal Number}"), status);   //Number, Decimal digit
3296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *set2a=new UnicodeSet(UNICODE_STRING_SIMPLE("[:Nd:]"), status);   //Number, Decimal digit
3306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)){
3316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: Can't construct set with category->Nd");
3326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
3336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (*set1 != *set1a) {
3366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: category constructor for Ll broken");
3376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (*set2 != *set2a) {
3396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: category constructor for Nd broken");
3406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete set1a;
3426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete set2a;
3436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("Testing copy construction");
3456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *set1copy=new UnicodeSet(*set1);
3466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(*set1 != *set1copy || *set1 == *set2 ||
3476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        getPairs(*set1) != getPairs(*set1copy) ||
3486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set1->hashCode() != set1copy->hashCode()){
3496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL : Error in copy construction");
3506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
3516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("Testing =operator");
3546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set1equal=*set1;
3556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set2equal=*set2;
3566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(set1equal != *set1 || set1equal != *set1copy || set2equal != *set2 ||
3576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set2equal == *set1 || set2equal == *set1copy || set2equal == set1equal){
3586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: Error in =operator");
3596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("Testing clone()");
3626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *set1clone=(UnicodeSet*)set1->clone();
3636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *set2clone=(UnicodeSet*)set2->clone();
3646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(*set1clone != *set1 || *set1clone != *set1copy || *set1clone != set1equal ||
3656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        *set2clone != *set2 || *set2clone == *set1copy || *set2clone != set2equal ||
3666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        *set2clone == *set1 || *set2clone == set1equal || *set2clone == *set1clone){
3676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: Error in clone");
3686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln("Testing hashcode");
3716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(set1->hashCode() != set1equal.hashCode() || set1->hashCode() != set1clone->hashCode() ||
3726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set2->hashCode() != set2equal.hashCode() || set2->hashCode() != set2clone->hashCode() ||
3736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set1copy->hashCode() != set1equal.hashCode() || set1copy->hashCode() != set1clone->hashCode() ||
3746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set1->hashCode() == set2->hashCode()  || set1copy->hashCode() == set2->hashCode() ||
3756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set2->hashCode() == set1clone->hashCode() || set2->hashCode() == set1equal.hashCode() ){
3766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: Error in hashCode()");
3776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
3786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete set1;
3806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete set1copy;
3816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete set2;
3826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete set1clone;
3836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete set2clone;
3846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
3866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
3876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
3886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::TestAddRemove(void) {
3896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set; // Construct empty set
3906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.isEmpty() == TRUE, "set should be empty");
3916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 0, "size should be 0");
3926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.complement();
3936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 0x110000, "size should be 0x110000");
3946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.clear();
3956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0061, 0x007a);
3966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "az");
3976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.isEmpty() == FALSE, "set should not be empty");
3986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() != 0, "size should not be equal to 0");
3996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 26, "size should be equal to 26");
4006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.remove(0x006d, 0x0070);
4016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "alqz");
4026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 22, "size should be equal to 22");
4036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.remove(0x0065, 0x0067);
4046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "adhlqz");
4056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 19, "size should be equal to 19");
4066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.remove(0x0064, 0x0069);
4076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "acjlqz");
4086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 16, "size should be equal to 16");
4096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.remove(0x0063, 0x0072);
4106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "absz");
4116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 10, "size should be equal to 10");
4126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0066, 0x0071);
4136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "abfqsz");
4146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 22, "size should be equal to 22");
4156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.remove(0x0061, 0x0067);
4166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "hqsz");
4176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.remove(0x0061, 0x007a);
4186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "");
4196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.isEmpty() == TRUE, "set should be empty");
4206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 0, "size should be 0");
4216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0061);
4226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.isEmpty() == FALSE, "set should not be empty");
4236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 1, "size should not be equal to 1");
4246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0062);
4256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0063);
4266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "ac");
4276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 3, "size should not be equal to 3");
4286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0070);
4296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0071);
4306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "acpq");
4316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 5, "size should not be equal to 5");
4326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.clear();
4336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "");
4346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.isEmpty() == TRUE, "set should be empty");
4356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == 0, "size should be 0");
4366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Try removing an entire set from another set
4386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, "[c-x]", "cx");
4396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set2;
4406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set2, "[f-ky-za-bc[vw]]", "acfkvwyz");
4416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.removeAll(set2);
4426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "deluxx");
4436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Try adding an entire set to another set
4456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, "[jackiemclean]", "aacceein");
4466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set2, "[hitoshinamekatajamesanderson]", "aadehkmort");
4476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.addAll(set2);
4486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "aacehort");
4496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.containsAll(set2) == TRUE, "set should contain all the elements in set2");
4506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Try retaining an set of elements contained in another set (intersection)
4526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set3;
4536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set3, "[a-c]", "ac");
4546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.containsAll(set3) == FALSE, "set doesn't contain all the elements in set3");
4556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set3.remove(0x0062);
4566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set3, "aacc");
4576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.containsAll(set3) == TRUE, "set should contain all the elements in set3");
4586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.retainAll(set3);
4596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "aacc");
4606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() == set3.size(), "set.size() should be set3.size()");
4616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.containsAll(set3) == TRUE, "set should contain all the elements in set3");
4626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.clear();
4636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.size() != set3.size(), "set.size() != set3.size()");
4646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test commutativity
4666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set, "[hitoshinamekatajamesanderson]", "aadehkmort");
4676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPattern(set2, "[jackiemclean]", "aacceein");
4686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.addAll(set2);
4696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "aacehort");
4706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    doAssert(set.containsAll(set2) == TRUE, "set should contain all the elements in set2");
4716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
4766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
4786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Make sure minimal representation is maintained.
4796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
4806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestMinimalRep() {
4816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
4826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // This is pretty thoroughly tested by checkCanonicalRep()
4836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // run against the exhaustive operation results.  Use the code
4846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // here for debugging specific spot problems.
4856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
4866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // 1 overlap against 2
4876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set("[h-km-q]", status);
4886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
4896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set2("[i-o]", status);
4906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
4916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.addAll(set2);
4926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "hq");
4936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // right
4946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.applyPattern("[a-m]", status);
4956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
4966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set2.applyPattern("[e-o]", status);
4976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
4986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.addAll(set2);
4996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "ao");
5006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // left
5016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.applyPattern("[e-o]", status);
5026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
5036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set2.applyPattern("[a-m]", status);
5046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
5056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.addAll(set2);
5066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "ao");
5076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // 1 overlap against 3
5086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.applyPattern("[a-eg-mo-w]", status);
5096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
5106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set2.applyPattern("[d-q]", status);
5116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
5126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.addAll(set2);
5136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectPairs(set, "aw");
5146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
5156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestAPI() {
5176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
5186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // default ct
5196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set;
5206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!set.isEmpty() || set.getRangeCount() != 0) {
5216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL, set should be empty but isn't: " +
5226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              set);
5236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // clear(), isEmpty()
5266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0061);
5276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set.isEmpty()) {
5286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL, set shouldn't be empty but is: " +
5296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              set);
5306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.clear();
5326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!set.isEmpty()) {
5336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL, set should be empty but isn't: " +
5346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              set);
5356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // size()
5386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.clear();
5396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set.size() != 0) {
5406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL, size should be 0, but is " + set.size() +
5416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              ": " + set);
5426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0061);
5446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set.size() != 1) {
5456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL, size should be 1, but is " + set.size() +
5466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              ": " + set);
5476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add(0x0031, 0x0039);
5496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set.size() != 10) {
5506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL, size should be 10, but is " + set.size() +
5516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              ": " + set);
5526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // contains(first, last)
5556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.clear();
5566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.applyPattern("[A-Y 1-8 b-d l-y]", status);
5576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
5586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i = 0; i<set.getRangeCount(); ++i) {
5596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 a = set.getRangeStart(i);
5606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 b = set.getRangeEnd(i);
5616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (!set.contains(a, b)) {
5626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL, should contain " + (unsigned short)a + '-' + (unsigned short)b +
5636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  " but doesn't: " + set);
5646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (set.contains((UChar32)(a-1), b)) {
5666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL, shouldn't contain " +
5676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  (unsigned short)(a-1) + '-' + (unsigned short)b +
5686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  " but does: " + set);
5696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (set.contains(a, (UChar32)(b+1))) {
5716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL, shouldn't contain " +
5726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  (unsigned short)a + '-' + (unsigned short)(b+1) +
5736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  " but does: " + set);
5746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
5756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Ported InversionList test.
5786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet a((UChar32)3,(UChar32)10);
5796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet b((UChar32)7,(UChar32)15);
5806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet c;
5816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
5826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"a [3-10]: " + a);
5836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    logln((UnicodeString)"b [7-15]: " + b);
5846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    c = a;
5856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    c.addAll(b);
5866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet exp((UChar32)3,(UChar32)15);
5876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c == exp) {
5886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"c.set(a).add(b): " + c);
5896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
5906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: c.set(a).add(b) = " + c + ", expect " + exp);
5916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
5926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    c.complement();
5936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.set((UChar32)0, (UChar32)2);
5946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.add((UChar32)16, UnicodeSet::MAX_VALUE);
5956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c == exp) {
5966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"c.complement(): " + c);
5976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
5986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: c.complement() = " + c + ", expect " + exp);
5996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    c.complement();
6016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.set((UChar32)3, (UChar32)15);
6026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c == exp) {
6036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"c.complement(): " + c);
6046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
6056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: c.complement() = " + c + ", expect " + exp);
6066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    c = a;
6086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    c.complementAll(b);
6096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.set((UChar32)3,(UChar32)6);
6106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.add((UChar32)11,(UChar32) 15);
6116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c == exp) {
6126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"c.set(a).exclusiveOr(b): " + c);
6136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
6146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: c.set(a).exclusiveOr(b) = " + c + ", expect " + exp);
6156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp = c;
6186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(setToBits(c), c);
6196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c == exp) {
6206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"bitsToSet(setToBits(c)): " + c);
6216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
6226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: bitsToSet(setToBits(c)) = " + c + ", expect " + exp);
6236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Additional tests for coverage JB#2118
6266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::complement(class UnicodeString const &)
6276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::complementAll(class UnicodeString const &)
6286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::containsNone(class UnicodeSet const &)
6296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::containsNone(long,long)
6306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::containsSome(class UnicodeSet const &)
6316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::containsSome(long,long)
6326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::removeAll(class UnicodeString const &)
6336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::retain(long)
6346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::retainAll(class UnicodeString const &)
6356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSet::serialize(unsigned short *,long,enum UErrorCode &)
6366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //UnicodeSetIterator::getString(void)
6376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.clear();
6386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.complement("ab");
6396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.applyPattern("[{ab}]", status);
6406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
6416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set != exp) { errln("FAIL: complement(\"ab\")"); return; }
6426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSetIterator iset(set);
6446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!iset.next() || !iset.isString()) {
6456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSetIterator::next/isString");
6466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else if (iset.getString() != "ab") {
6476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSetIterator::getString");
6486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.add((UChar32)0x61, (UChar32)0x7A);
6516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.complementAll("alan");
6526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.applyPattern("[{ab}b-kmo-z]", status);
6536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
6546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set != exp) { errln("FAIL: complementAll(\"alan\")"); return; }
6556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.applyPattern("[a-z]", status);
6576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
6586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set.containsNone(exp)) { errln("FAIL: containsNone(UnicodeSet)"); }
6596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!set.containsSome(exp)) { errln("FAIL: containsSome(UnicodeSet)"); }
6606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.applyPattern("[aln]", status);
6616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
6626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!set.containsNone(exp)) { errln("FAIL: containsNone(UnicodeSet)"); }
6636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set.containsSome(exp)) { errln("FAIL: containsSome(UnicodeSet)"); }
6646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set.containsNone((UChar32)0x61, (UChar32)0x7A)) {
6666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: containsNone(UChar32, UChar32)");
6676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!set.containsSome((UChar32)0x61, (UChar32)0x7A)) {
6696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: containsSome(UChar32, UChar32)");
6706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!set.containsNone((UChar32)0x41, (UChar32)0x5A)) {
6726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: containsNone(UChar32, UChar32)");
6736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set.containsSome((UChar32)0x41, (UChar32)0x5A)) {
6756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: containsSome(UChar32, UChar32)");
6766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
6776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.removeAll("liu");
6796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.applyPattern("[{ab}b-hj-kmo-tv-z]", status);
6806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
6816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set != exp) { errln("FAIL: removeAll(\"liu\")"); return; }
6826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.retainAll("star");
6846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.applyPattern("[rst]", status);
6856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
6866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set != exp) { errln("FAIL: retainAll(\"star\")"); return; }
6876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.retain((UChar32)0x73);
6896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    exp.applyPattern("[s]", status);
6906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL"); return; }
6916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set != exp) { errln("FAIL: retain('s')"); return; }
6926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
6936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    uint16_t buf[32];
6946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t slen = set.serialize(buf, sizeof(buf)/sizeof(buf[0]), status);
6956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) { errln("FAIL: serialize"); return; }
6966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (slen != 3 || buf[0] != 2 || buf[1] != 0x73 || buf[2] != 0x74) {
6976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: serialize");
6986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
6996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Conversions to and from USet
7026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *uniset = &set;
7036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    USet *uset = uniset->toUSet();
7046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TEST_ASSERT((void *)uset == (void *)uniset);
7056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *setx = UnicodeSet::fromUSet(uset);
7066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TEST_ASSERT((void *)setx == (void *)uset);
7076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UnicodeSet *constSet = uniset;
7086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const USet *constUSet = constSet->toUSet();
7096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TEST_ASSERT((void *)constUSet == (void *)constSet);
7106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UnicodeSet *constSetx = UnicodeSet::fromUSet(constUSet);
7116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TEST_ASSERT((void *)constSetx == (void *)constUSet);
7126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // span(UnicodeString) and spanBack(UnicodeString) convenience methods
7146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString longString=UNICODE_STRING_SIMPLE("aaaaaaaaaabbbbbbbbbbcccccccccc");
7156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet ac(0x61, 0x63);
7166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ac.remove(0x62).freeze();
7176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if( ac.span(longString, -5, USET_SPAN_CONTAINED)!=10 ||
7186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, 0, USET_SPAN_CONTAINED)!=10 ||
7196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, 5, USET_SPAN_CONTAINED)!=10 ||
7206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, 10, USET_SPAN_CONTAINED)!=10 ||
7216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, 15, USET_SPAN_CONTAINED)!=15 ||
7226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, 20, USET_SPAN_CONTAINED)!=30 ||
7236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, 25, USET_SPAN_CONTAINED)!=30 ||
7246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, 30, USET_SPAN_CONTAINED)!=30 ||
7256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, 35, USET_SPAN_CONTAINED)!=30 ||
7266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.span(longString, INT32_MAX, USET_SPAN_CONTAINED)!=30
7276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ) {
7286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("UnicodeSet.span(UnicodeString, ...) returns incorrect end indexes");
7296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if( ac.spanBack(longString, -5, USET_SPAN_CONTAINED)!=0 ||
7316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, 0, USET_SPAN_CONTAINED)!=0 ||
7326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, 5, USET_SPAN_CONTAINED)!=0 ||
7336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, 10, USET_SPAN_CONTAINED)!=0 ||
7346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, 15, USET_SPAN_CONTAINED)!=15 ||
7356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, 20, USET_SPAN_CONTAINED)!=20 ||
7366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, 25, USET_SPAN_CONTAINED)!=20 ||
7376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, 30, USET_SPAN_CONTAINED)!=20 ||
7386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, 35, USET_SPAN_CONTAINED)!=20 ||
7396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ac.spanBack(longString, INT32_MAX, USET_SPAN_CONTAINED)!=20
7406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ) {
7416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("UnicodeSet.spanBack(UnicodeString, ...) returns incorrect start indexes");
7426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
7436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
7446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestIteration() {
7466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
7476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int i = 0;
7486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int outerLoop;
7496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // 6 code points, 3 ranges, 2 strings, 8 total elements
7516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    //   Iteration will access them in sorted order -  a, b, c, y, z, U0001abcd, "str1", "str2"
7526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set(UNICODE_STRING_SIMPLE("[zabyc\\U0001abcd{str1}{str2}]"), ec);
7536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TEST_ASSERT_SUCCESS(ec);
7546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSetIterator it(set);
7556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
7566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (outerLoop=0; outerLoop<3; outerLoop++) {
7576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Run the test multiple times, to check that iterator.reset() is working.
7586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (i=0; i<10; i++) {
7596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UBool         nextv        = it.next();
7606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UBool         isString     = it.isString();
7616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            int32_t       codePoint    = it.getCodepoint();
7626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            //int32_t       codePointEnd = it.getCodepointEnd();
7636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString s   = it.getString();
7646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            switch (i) {
7656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 0:
7666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == TRUE);
7676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(isString == FALSE);
7686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(codePoint==0x61);
7696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(s == "a");
7706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
7716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 1:
7726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == TRUE);
7736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(isString == FALSE);
7746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(codePoint==0x62);
7756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(s == "b");
7766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
7776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 2:
7786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == TRUE);
7796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(isString == FALSE);
7806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(codePoint==0x63);
7816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(s == "c");
7826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
7836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 3:
7846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == TRUE);
7856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(isString == FALSE);
7866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(codePoint==0x79);
7876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(s == "y");
7886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
7896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 4:
7906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == TRUE);
7916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(isString == FALSE);
7926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(codePoint==0x7a);
7936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(s == "z");
7946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
7956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 5:
7966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == TRUE);
7976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(isString == FALSE);
7986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(codePoint==0x1abcd);
7996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(s == UnicodeString((UChar32)0x1abcd));
8006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
8016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 6:
8026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == TRUE);
8036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(isString == TRUE);
8046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(s == "str1");
8056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
8066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 7:
8076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == TRUE);
8086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(isString == TRUE);
8096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(s == "str2");
8106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
8116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 8:
8126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == FALSE);
8136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
8146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            case 9:
8156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                TEST_ASSERT(nextv == FALSE);
8166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
8176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
8186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
8196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        it.reset();  // prepare to run the iteration again.
8206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestStrings() {
8276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
8286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet* testList[] = {
8306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet::createFromAll("abc"),
8316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        new UnicodeSet("[a-c]", ec),
8326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        &(UnicodeSet::createFrom("ch")->add('a','z').add("ll")),
8346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        new UnicodeSet("[{ll}{ch}a-z]", ec),
8356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet::createFrom("ab}c"),
8376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        new UnicodeSet("[{ab\\}c}]", ec),
8386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        &((new UnicodeSet('a','z'))->add('A', 'Z').retain('M','m').complement('X')),
8406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        new UnicodeSet("[[a-zA-Z]&[M-m]-[X]]", ec),
8416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        NULL
8436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
8446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
8466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: couldn't construct test sets");
8476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i = 0; testList[i] != NULL; i+=2) {
8506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_SUCCESS(ec)) {
8516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString pat0, pat1;
8526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testList[i]->toPattern(pat0, TRUE);
8536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            testList[i+1]->toPattern(pat1, TRUE);
8546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (*testList[i] == *testList[i+1]) {
8556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                logln((UnicodeString)"Ok: " + pat0 + " == " + pat1);
8566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
8576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                logln((UnicodeString)"FAIL: " + pat0 + " != " + pat1);
8586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
8596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
8606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete testList[i];
8616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        delete testList[i+1];
8626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
8636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
8666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test the [:Latin:] syntax.
8676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
8686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestScriptSet() {
8696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectContainment(UNICODE_STRING_SIMPLE("[:Latin:]"), "aA", CharsToUnicodeString("\\u0391\\u03B1"));
8706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectContainment(UNICODE_STRING_SIMPLE("[:Greek:]"), CharsToUnicodeString("\\u0391\\u03B1"), "aA");
8726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /* Jitterbug 1423 */
8746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectContainment(UNICODE_STRING_SIMPLE("[[:Common:][:Inherited:]]"), CharsToUnicodeString("\\U00003099\\U0001D169\\u0000"), "aA");
8756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
8776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
8796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test the [:Latin:] syntax.
8806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
8816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestPropertySet() {
8826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const char* const DATA[] = {
8836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Pattern, Chars IN, Chars NOT in
8846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:Latin:]",
8866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "aA",
8876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0391\\u03B1",
8886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\p{Greek}]",
8906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0391\\u03B1",
8916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "aA",
8926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\P{ GENERAL Category = upper case letter }",
8946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abc",
8956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ABC",
8966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
8976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_NORMALIZATION
8986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Combining class: @since ICU 2.2
8996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Check both symbolic and numeric
9006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\p{ccc=Nukta}",
9016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0ABC",
9026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abc",
9036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\p{Canonical Combining Class = 11}",
9056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u05B1",
9066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u05B2",
9076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:c c c = iota subscript :]",
9096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0345",
9106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "xyz",
9116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
9126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Bidi class: @since ICU 2.2
9146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\p{bidiclass=lefttoright}",
9156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abc",
9166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0671\\u0672",
9176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Binary properties: @since ICU 2.2
9196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\p{ideographic}",
9206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u4E0A",
9216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "x",
9226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:math=false:]",
9246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "q)*(",
9256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // weiv: )(and * were removed from math in Unicode 4.0.1
9266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        //"(*+)",
9276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "+<>^",
9286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // JB#1767 \N{}, \p{ASCII}
9306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:Ascii:]",
9316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abc\\u0000\\u007F",
9326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0080\\u4E00",
9336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\N{ latin small letter  a  }[:name= latin small letter z:]]",
9356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "az",
9366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "qrs",
9376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // JB#2015
9396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:any:]",
9406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "a\\U0010FFFF",
9416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "",
9426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:nv=0.5:]",
9446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u00BD\\u0F2A",
9456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u00BC",
9466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // JB#2653: Age
9486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:Age=1.1:]",
9496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u03D6", // 1.1
9506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u03D8\\u03D9", // 3.2
9516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:Age=3.1:]",
9536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u1800\\u3400\\U0002f800",
9546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0220\\u034f\\u30ff\\u33ff\\ufe73\\U00010000\\U00050000",
9556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // JB#2350: Case_Sensitive
9576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:Case Sensitive:]",
9586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "A\\u1FFC\\U00010410",
9596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ";\\u00B4\\U00010500",
9606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // JB#2832: C99-compatibility props
9626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:blank:]",
9636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        " \\u0009",
9646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "1-9A-Z",
9656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:graph:]",
9676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "19AZ",
9686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        " \\u0003\\u0007\\u0009\\u000A\\u000D",
9696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:punct:]",
9716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "!@#%&*()[]{}-_\\/;:,.?'\"",
9726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "09azAZ",
9736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:xdigit:]",
9756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "09afAF",
9766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "gG!",
9776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Regex compatibility test
9796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[-b]", // leading '-' is literal
9806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-b",
9816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ac",
9826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[^-b]", // leading '-' is literal
9846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ac",
9856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-b",
9866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[b-]", // trailing '-' is literal
9886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-b",
9896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ac",
9906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[^b-]", // trailing '-' is literal
9926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ac",
9936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "-b",
9946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[a-b-]", // trailing '-' is literal
9966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ab-",
9976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "c=",
9986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
9996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[[a-q]&[p-z]-]", // trailing '-' is literal
10006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "pq-",
10016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "or=",
10026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\s|\\)|:|$|\\>]", // from regex tests
10046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "s|):$>",
10056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abc",
10066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\uDC00cd]", // JB#2906: isolated trail at start
10086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "cd\\uDC00",
10096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ab\\uD800\\U00010000",
10106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[ab\\uD800]", // JB#2906: isolated trail at start
10126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ab\\uD800",
10136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "cd\\uDC00\\U00010000",
10146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[ab\\uD800cd]", // JB#2906: isolated lead in middle
10166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abcd\\uD800",
10176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ef\\uDC00\\U00010000",
10186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[ab\\uDC00cd]", // JB#2906: isolated trail in middle
10206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abcd\\uDC00",
10216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "ef\\uD800\\U00010000",
10226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_NORMALIZATION
10246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:^lccc=0:]", // Lead canonical class
10256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0300\\u0301",
10266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abcd\\u00c0\\u00c5",
10276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:^tccc=0:]", // Trail canonical class
10296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0300\\u0301\\u00c0\\u00c5",
10306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abcd",
10316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[[:^lccc=0:][:^tccc=0:]]", // Lead and trail canonical class
10336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0300\\u0301\\u00c0\\u00c5",
10346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abcd",
10356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[[:^lccc=0:]-[:^tccc=0:]]", // Stuff that starts with an accent but ends with a base (none right now)
10376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "",
10386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abcd\\u0300\\u0301\\u00c0\\u00c5",
10396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[[:ccc=0:]-[:lccc=0:]-[:tccc=0:]]", // Weirdos. Complete canonical class is zero, but both lead and trail are not
10416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0F73\\u0F75\\u0F81",
10426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "abcd\\u0300\\u0301\\u00c0\\u00c5",
10436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif /* !UCONFIG_NO_NORMALIZATION */
10446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:Assigned:]",
10466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "A\\uE000\\uF8FF\\uFDC7\\U00010000\\U0010FFFD",
10476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0888\\uFDD3\\uFFFE\\U00050005",
10486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Script_Extensions, new in Unicode 6.0
10506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[:scx=Arab:]",
10516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u061E\\u061F\\u0620\\u0621\\u063F\\u0640\\u0650\\u065E\\uFDF1\\uFDF2\\uFDF3",
10526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u061D\\uFDEF\\uFDFE",
10536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // U+FDF2 has Script=Arabic and also Arab in its Script_Extensions,
10556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // so scx-sc is missing U+FDF2.
10566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[[:Script_Extensions=Arabic:]-[:Arab:]]",
10576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\u0640\\u064B\\u0650\\u0655\\uFDFD",
10586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "\\uFDF2"
10596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
10606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    static const int32_t DATA_LEN = sizeof(DATA)/sizeof(DATA[0]);
10626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i<DATA_LEN; i+=3) {
10646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectContainment(UnicodeString(DATA[i], -1, US_INV), CharsToUnicodeString(DATA[i+1]),
10656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          CharsToUnicodeString(DATA[i+2]));
10666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
10686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
10696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
10706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  * Test that Posix style character classes [:digit:], etc.
10716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  *   have the Unicode definitions from TR 18.
10726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org  */
10736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestPosixClasses() {
10746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
10756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
10766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:alpha:]", status);
10776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("\\p{Alphabetic}"), status);
10786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
10796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
10806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
10826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
10836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:lower:]", status);
10846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("\\p{lowercase}"), status);
10856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
10866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
10876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
10896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
10906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:upper:]", status);
10916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("\\p{Uppercase}"), status);
10926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
10936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
10946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
10956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
10966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
10976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:punct:]", status);
10986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("\\p{gc=Punctuation}"), status);
10996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
11046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:digit:]", status);
11056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("\\p{gc=DecimalNumber}"), status);
11066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
11116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:xdigit:]", status);
11126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("[\\p{DecimalNumber}\\p{HexDigit}]"), status);
11136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
11186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:alnum:]", status);
11196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("[\\p{Alphabetic}\\p{DecimalNumber}]"), status);
11206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
11256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:space:]", status);
11266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("\\p{Whitespace}"), status);
11276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
11326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:blank:]", status);
11336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("[\\p{Whitespace}-[\\u000a\\u000B\\u000c\\u000d\\u0085\\p{LineSeparator}\\p{ParagraphSeparator}]]"),
11356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            status);
11366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
11416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:cntrl:]", status);
11426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("\\p{Control}"), status);
11446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
11496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:graph:]", status);
11506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("[^\\p{Whitespace}\\p{Control}\\p{Surrogate}\\p{Unassigned}]"), status);
11526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
11566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode status = U_ZERO_ERROR;
11576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s1("[:print:]", status);
11586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet s2(UNICODE_STRING_SIMPLE("[[:graph:][:blank:]-[\\p{Control}]]") ,status);
11606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT_SUCCESS(status);
11616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TEST_ASSERT(s1==s2);
11626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
11646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
11656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test cloning of UnicodeSet.  For C++, we test the copy constructor.
11666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
11676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestClone() {
11686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
11696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet s("[abcxyz]", ec);
11706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet t(s);
11716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectContainment(t, "abc", "def");
11726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
11736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
11746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
11756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test the indexOf() and charAt() methods.
11766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
11776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestIndexOf() {
11786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
11796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set("[a-cx-y3578]", ec);
11806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
11816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet constructor");
11826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
11836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i<set.size(); ++i) {
11856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 c = set.charAt(i);
11866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (set.indexOf(c) != i) {
11876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: charAt(%d) = %X => indexOf() => %d",
11886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                i, c, set.indexOf(c));
11896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
11906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar32 c = set.charAt(set.size());
11926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c != -1) {
11936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: charAt(<out of range>) = %X", c);
11946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t j = set.indexOf((UChar32)0x71/*'q'*/);
11966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (j != -1) {
11976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: indexOf('q') = " + j);
11986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
11996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
12006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
12026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Test closure API.
12036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
12046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestCloseOver() {
12056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
12066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char CASE[] = {(char)USET_CASE_INSENSITIVE};
12086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    char CASE_MAPPINGS[] = {(char)USET_ADD_CASE_MAPPINGS};
12096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* DATA[] = {
12106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // selector, input, output
12116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE,
12126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[aq\\u00DF{Bc}{bC}{Fi}]",
12136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[aAqQ\\u00DF\\u1E9E\\uFB01{ss}{bc}{fi}]",  // U+1E9E LATIN CAPITAL LETTER SHARP S is new in Unicode 5.1
12146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE,
12166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\u01F1]", // 'DZ'
12176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\u01F1\\u01F2\\u01F3]",
12186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE,
12206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\u1FB4]",
12216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\u1FB4{\\u03AC\\u03B9}]",
12226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE,
12246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[{F\\uFB01}]",
12256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\uFB03{ffi}]",
12266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, // make sure binary search finds limits
12286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[a\\uFF3A]",
12296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[aA\\uFF3A\\uFF5A]",
12306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE,
12326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[a-z]","[A-Za-z\\u017F\\u212A]",
12336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE,
12346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[abc]","[A-Ca-c]",
12356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE,
12366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[ABC]","[A-Ca-c]",
12376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[i]", "[iI]",
12396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\u0130]",          "[\\u0130{i\\u0307}]", // dotted I
12416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[{i\\u0307}]",       "[\\u0130{i\\u0307}]", // i with dot
12426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\u0131]",          "[\\u0131]", // dotless i
12446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\u0390]",          "[\\u0390\\u1FD3{\\u03B9\\u0308\\u0301}]",
12466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\u03c2]",          "[\\u03a3\\u03c2\\u03c3]", // sigmas
12486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\u03f2]",          "[\\u03f2\\u03f9]", // lunate sigmas
12506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\u03f7]",          "[\\u03f7\\u03f8]",
12526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\u1fe3]",          "[\\u03b0\\u1fe3{\\u03c5\\u0308\\u0301}]",
12546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\ufb05]",          "[\\ufb05\\ufb06{st}]",
12566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[{st}]",             "[\\ufb05\\ufb06{st}]",
12576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[\\U0001044F]",      "[\\U00010427\\U0001044F]",
12596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[{a\\u02BE}]",       "[\\u1E9A{a\\u02BE}]", // first in sorted table
12616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE, "[{\\u1f7c\\u03b9}]", "[\\u1ff2{\\u1f7c\\u03b9}]", // last in sorted table
12636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if !UCONFIG_NO_FILE_IO
12656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE_MAPPINGS,
12666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[aq\\u00DF{Bc}{bC}{Fi}]",
12676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[aAqQ\\u00DF{ss}{Ss}{SS}{Bc}{BC}{bC}{bc}{FI}{Fi}{fi}]",
12686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
12696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE_MAPPINGS,
12716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\u01F1]", // 'DZ'
12726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\u01F1\\u01F2\\u01F3]",
12736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        CASE_MAPPINGS,
12756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[a-z]",
12766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[A-Za-z]",
12776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        NULL
12796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
12806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
12816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet s;
12826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet t;
12836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString buf;
12846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; DATA[i]!=NULL; i+=3) {
12856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t selector = DATA[i][0];
12866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString pat(DATA[i+1], -1, US_INV);
12876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString exp(DATA[i+2], -1, US_INV);
12886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        s.applyPattern(pat, ec);
12896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        s.closeOver(selector);
12906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        t.applyPattern(exp, ec);
12916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
12926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: applyPattern failed");
12936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
12946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
12956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (s == t) {
12966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"Ok: " + pat + ".closeOver(" + selector + ") => " + exp);
12976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
12986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            dataerrln((UnicodeString)"FAIL: " + pat + ".closeOver(" + selector + ") => " +
12996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  s.toPattern(buf, TRUE) + ", expected " + exp);
13006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#if 0
13046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /*
13056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * Unused test code.
13066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * This was used to compare the old implementation (using USET_CASE)
13076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * with the new one (using 0x100 temporarily)
13086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * while transitioning from hardcoded case closure tables in uniset.cpp
13096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * (moved to uniset_props.cpp) to building the data by gencase into ucase.icu.
13106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * and using ucase.c functions for closure.
13116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * See Jitterbug 3432 RFE: Move uniset.cpp data to a data file
13126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     *
13136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * Note: The old and new implementation never fully matched because
13146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * the old implementation turned out to not map U+0130 and U+0131 correctly
13156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * (dotted I and dotless i) and because the old implementation's data tables
13166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * were outdated compared to Unicode 4.0.1 at the time of the change to the
13176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * new implementation. (So sigmas and some other characters were not handled
13186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * according to the newer Unicode version.)
13196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
13206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet sens("[:case_sensitive:]", ec), sens2, s2;
13216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSetIterator si(sens);
13226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString str, buf2;
13236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UnicodeString *pStr;
13246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar32 c;
13256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    while(si.next()) {
13266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(!si.isString()) {
13276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            c=si.getCodepoint();
13286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s.clear();
13296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s.add(c);
13306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            str.setTo(c);
13326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            str.foldCase();
13336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            sens2.add(str);
13346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            t=s;
13366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s.closeOver(USET_CASE);
13376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            t.closeOver(0x100);
13386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(s!=t) {
13396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: closeOver(U+%04x) differs: ", c);
13406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"old "+s.toPattern(buf, TRUE)+" new: "+t.toPattern(buf2, TRUE));
13416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
13426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // remove all code points
13456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // should contain all full case folding mapping strings
13466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    sens2.remove(0, 0x10ffff);
13476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    si.reset(sens2);
13486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    while(si.next()) {
13496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(si.isString()) {
13506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            pStr=&si.getString();
13516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s.clear();
13526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s.add(*pStr);
13536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            t=s2=s;
13546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            s.closeOver(USET_CASE);
13556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            t.closeOver(0x100);
13566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if(s!=t) {
13576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"FAIL: closeOver("+s2.toPattern(buf, TRUE)+") differs: ");
13586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"old "+s.toPattern(buf, TRUE)+" new: "+t.toPattern(buf2, TRUE));
13596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
13606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org#endif
13636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Test the pattern API
13656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.applyPattern("[abc]", USET_CASE_INSENSITIVE, NULL, ec);
13666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
13676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: applyPattern failed");
13686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
13696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectContainment(s, "abcABC", "defDEF");
13706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet v("[^abc]", USET_CASE_INSENSITIVE, NULL, ec);
13726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
13736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: constructor failed");
13746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
13756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectContainment(v, "defDEF", "abcABC");
13766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet cm("[abck]", USET_ADD_CASE_MAPPINGS, NULL, ec);
13786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
13796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: construct w/case mappings failed");
13806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
13816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectContainment(cm, "abckABCK", CharsToUnicodeString("defDEF\\u212A"));
13826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
13836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
13846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
13856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestEscapePattern() {
13866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char pattern[] =
13876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\uFEFF \\u200A-\\u200E \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD ]";
13886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char exp[] =
13896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[\\u200A-\\u200E\\uFEFF\\U0001D173-\\U0001D17A\\U000F0000-\\U000FFFFD]";
13906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // We test this with two passes; in the second pass we
13916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // pre-unescape the pattern.  Since U+200E is Pattern_White_Space,
13926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // this fails -- which is what we expect.
13936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t pass=1; pass<=2; ++pass) {
13946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode ec = U_ZERO_ERROR;
13956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString pat(pattern, -1, US_INV);
13966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (pass==2) {
13976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            pat = pat.unescape();
13986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
13996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Pattern is only good for pass 1
14006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UBool isPatternValid = (pass==1);
14016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet set(pat, ec);
14036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_SUCCESS(ec) != isPatternValid){
14046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: applyPattern(" +
14056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  escape(pat) + ") => " +
14066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  u_errorName(ec));
14076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
14086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
14096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
14106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
14116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
14126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (set.contains((UChar)0x0644)){
14136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: " + escape(pat) + " contains(U+0664)");
14146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
14156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString newpat;
14176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.toPattern(newpat, TRUE);
14186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (newpat == UnicodeString(exp, -1, US_INV)) {
14196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln(escape(pat) + " => " + newpat);
14206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
14216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: " + escape(pat) + " => " + newpat);
14226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
14236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t i=0; i<set.getRangeCount(); ++i) {
14256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeString str("Range ");
14266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            str.append((UChar)(0x30 + i))
14276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                .append(": ")
14286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                .append((UChar32)set.getRangeStart(i))
14296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                .append(" - ")
14306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                .append((UChar32)set.getRangeEnd(i));
14316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            str = str + " (" + set.getRangeStart(i) + " - " +
14326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                set.getRangeEnd(i) + ")";
14336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (set.getRangeStart(i) < 0) {
14346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln((UnicodeString)"FAIL: " + escape(str));
14356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
14366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                logln(escape(str));
14376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
14386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
14396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
14416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::expectRange(const UnicodeString& label,
14436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                 const UnicodeSet& set,
14446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                 UChar32 start, UChar32 end) {
14456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet exp(start, end);
14466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat;
14476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (set == exp) {
14486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(label + " => " + set.toPattern(pat, TRUE));
14496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
14506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString xpat;
14516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: " + label + " => " +
14526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              set.toPattern(pat, TRUE) +
14536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              ", expected " + exp.toPattern(xpat, TRUE));
14546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
14556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
14566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestInvalidCodePoint() {
14586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UChar32 DATA[] = {
14606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Test range             Expected range
14616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0, 0x10FFFF,              0, 0x10FFFF,
14626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (UChar32)-1, 8,           0, 8,
14636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        8, 0x110000,              8, 0x10FFFF
14646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
14656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const int32_t DATA_LENGTH = sizeof(DATA)/sizeof(DATA[0]);
14666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat;
14686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
14696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i<DATA_LENGTH; i+=4) {
14716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 start  = DATA[i];
14726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 end    = DATA[i+1];
14736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 xstart = DATA[i+2];
14746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 xend   = DATA[i+3];
14756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Try various API using the test code points
14776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet set(start, end);
14796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectRange((UnicodeString)"ct(" + start + "," + end + ")",
14806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    set, xstart, xend);
14816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.clear();
14836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.set(start, end);
14846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectRange((UnicodeString)"set(" + start + "," + end + ")",
14856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    set, xstart, xend);
14866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UBool b = set.contains(start);
14886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        b = set.contains(start, end);
14896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        b = set.containsNone(start, end);
14906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        b = set.containsSome(start, end);
14916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (void)b;   // Suppress set but not used warning.
14926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        /*int32_t index = set.indexOf(start);*/
14946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
14956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.clear();
14966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.add(start);
14976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.add(start, end);
14986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectRange((UnicodeString)"add(" + start + "," + end + ")",
14996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    set, xstart, xend);
15006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.set(0, 0x10FFFF);
15026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.retain(start, end);
15036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectRange((UnicodeString)"retain(" + start + "," + end + ")",
15046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    set, xstart, xend);
15056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.retain(start);
15066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.set(0, 0x10FFFF);
15086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.remove(start);
15096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.remove(start, end);
15106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.complement();
15116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectRange((UnicodeString)"!remove(" + start + "," + end + ")",
15126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    set, xstart, xend);
15136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.set(0, 0x10FFFF);
15156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.complement(start, end);
15166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.complement();
15176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectRange((UnicodeString)"!complement(" + start + "," + end + ")",
15186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    set, xstart, xend);
15196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        set.complement(start);
15206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const UChar32 DATA2[] = {
15236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0,
15246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x10FFFF,
15256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        (UChar32)-1,
15266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0x110000
15276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
15286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const int32_t DATA2_LENGTH = sizeof(DATA2)/sizeof(DATA2[0]);
15296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i<DATA2_LENGTH; ++i) {
15316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 c = DATA2[i], end = 0x10FFFF;
15326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UBool valid = (c >= 0 && c <= 0x10FFFF);
15336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet set(0, 0x10FFFF);
15356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // For single-codepoint contains, invalid codepoints are NOT contained
15376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UBool b = set.contains(c);
15386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (b == valid) {
15396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"[\\u0000-\\U0010FFFF].contains(" + c +
15406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  ") = " + b);
15416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
15426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: [\\u0000-\\U0010FFFF].contains(" + c +
15436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  ") = " + b);
15446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // For codepoint range contains, containsNone, and containsSome,
15476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // invalid or empty (start > end) ranges have UNDEFINED behavior.
15486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        b = set.contains(c, end);
15496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"* [\\u0000-\\U0010FFFF].contains(" + c +
15506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              "," + end + ") = " + b);
15516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        b = set.containsNone(c, end);
15536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"* [\\u0000-\\U0010FFFF].containsNone(" + c +
15546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              "," + end + ") = " + b);
15556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        b = set.containsSome(c, end);
15576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"* [\\u0000-\\U0010FFFF].containsSome(" + c +
15586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              "," + end + ") = " + b);
15596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t index = set.indexOf(c);
15616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ((index >= 0) == valid) {
15626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"[\\u0000-\\U0010FFFF].indexOf(" + c +
15636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  ") = " + index);
15646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
15656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: [\\u0000-\\U0010FFFF].indexOf(" + c +
15666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  ") = " + index);
15676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
15706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Used by TestSymbolTable
15726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgclass TokenSymbolTable : public SymbolTable {
15736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgpublic:
15746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    Hashtable contents;
15756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    TokenSymbolTable(UErrorCode& ec) : contents(FALSE, ec) {
15776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        contents.setValueDeleter(uprv_deleteUObject);
15786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ~TokenSymbolTable() {}
15816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /**
15836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * (Non-SymbolTable API) Add the given variable and value to
15846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * the table.  Variable should NOT contain leading '$'.
15856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
15866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    void add(const UnicodeString& var, const UnicodeString& value,
15876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org             UErrorCode& ec) {
15886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_SUCCESS(ec)) {
15896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            contents.put(var, new UnicodeString(value), ec);
15906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
15916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
15936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /**
15946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * SymbolTable API
15956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
15966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual const UnicodeString* lookup(const UnicodeString& s) const {
15976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return (const UnicodeString*) contents.get(s);
15986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
15996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /**
16016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * SymbolTable API
16026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
16036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual const UnicodeFunctor* lookupMatcher(UChar32 /*ch*/) const {
16046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return NULL;
16056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    /**
16086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     * SymbolTable API
16096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org     */
16106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    virtual UnicodeString parseReference(const UnicodeString& text,
16116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                         ParsePosition& pos, int32_t limit) const {
16126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t start = pos.getIndex();
16136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t i = start;
16146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString result;
16156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        while (i < limit) {
16166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UChar c = text.charAt(i);
16176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if ((i==start && !u_isIDStart(c)) || !u_isIDPart(c)) {
16186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                break;
16196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
16206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            ++i;
16216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (i == start) { // No valid name chars
16236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            return result; // Indicate failure with empty string
16246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        pos.setIndex(i);
16266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        text.extractBetween(start, i, result);
16276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return result;
16286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org};
16306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestSymbolTable() {
16326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // Multiple test cases can be set up here.  Each test case
16336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // is terminated by null:
16346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // var, value, var, value,..., input pat., exp. output pat., null
16356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* DATA[] = {
16366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "us", "a-z", "[0-1$us]", "[0-1a-z]", NULL,
16376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "us", "[a-z]", "[0-1$us]", "[0-1[a-z]]", NULL,
16386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "us", "\\[a\\-z\\]", "[0-1$us]", "[-01\\[\\]az]", NULL,
16396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        NULL
16406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
16416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; DATA[i]!=NULL; ++i) {
16436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode ec = U_ZERO_ERROR;
16446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        TokenSymbolTable sym(ec);
16456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
16466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: couldn't construct TokenSymbolTable");
16476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
16486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Set up variables
16516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        while (DATA[i+2] != NULL) {
16526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            sym.add(UnicodeString(DATA[i], -1, US_INV), UnicodeString(DATA[i+1], -1, US_INV), ec);
16536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (U_FAILURE(ec)) {
16546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                errln("FAIL: couldn't add to TokenSymbolTable");
16556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                continue;
16566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
16576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            i += 2;
16586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Input pattern and expected output pattern
16616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString inpat = UnicodeString(DATA[i], -1, US_INV), exppat = UnicodeString(DATA[i+1], -1, US_INV);
16626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        i += 2;
16636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        ParsePosition pos(0);
16656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet us(inpat, pos, USET_IGNORE_SPACE, &sym, ec);
16666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
16676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: couldn't construct UnicodeSet");
16686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
16696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // results
16726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (pos.getIndex() != inpat.length()) {
16736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"Failed to read to end of string \""
16746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  + inpat + "\": read to "
16756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  + pos.getIndex() + ", length is "
16766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  + inpat.length());
16776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet us2(exppat, ec);
16806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
16816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: couldn't construct expected UnicodeSet");
16826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
16836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString a, b;
16866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (us != us2) {
16876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"Failed, got " + us.toPattern(a, TRUE) +
16886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  ", expected " + us2.toPattern(b, TRUE));
16896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
16906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"Ok, got " + us.toPattern(a, TRUE));
16916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
16926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
16936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
16946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
16956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestSurrogate() {
16966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    const char* DATA[] = {
16976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // These should all behave identically
16986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[abc\\uD800\\uDC00]",
16996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // "[abc\uD800\uDC00]", // Can't do this on C -- only Java
17006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        "[abc\\U00010000]",
17016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        0
17026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    };
17036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int i=0; DATA[i] != 0; ++i) {
17046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UErrorCode ec = U_ZERO_ERROR;
17056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"Test pattern " + i + " :" + UnicodeString(DATA[i], -1, US_INV));
17066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString str = UnicodeString(DATA[i], -1, US_INV);
17076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeSet set(str, ec);
17086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (U_FAILURE(ec)) {
17096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln("FAIL: UnicodeSet constructor");
17106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
17116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        expectContainment(set,
17136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          CharsToUnicodeString("abc\\U00010000"),
17146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                          CharsToUnicodeString("\\uD800;\\uDC00")); // split apart surrogate-pair
17156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (set.size() != 4) {
17166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: " + UnicodeString(DATA[i], -1, US_INV) + ".size() == " +
17176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  set.size() + ", expected 4");
17186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestExhaustive() {
17236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // exhaustive tests. Simulate UnicodeSets with integers.
17246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // That gives us very solid tests (except for large memory tests).
17256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t limit = 128;
17276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet x, y, z, aa;
17296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i = 0; i < limit; ++i) {
17316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        bitsToSet(i, x);
17326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"Testing " + i + ", " + x);
17336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        _testComplement(i, x, y);
17346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // AS LONG AS WE ARE HERE, check roundtrip
17366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        checkRoundTrip(bitsToSet(i, aa));
17376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        for (int32_t j = 0; j < limit; ++j) {
17396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _testAdd(i,j,  x,y,z);
17406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _testXor(i,j,  x,y,z);
17416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _testRetain(i,j,  x,y,z);
17426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            _testRemove(i,j,  x,y,z);
17436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
17446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::_testComplement(int32_t a, UnicodeSet& x, UnicodeSet& z) {
17486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(a, x);
17496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z = x;
17506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z.complement();
17516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t c = setToBits(z);
17526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c != (~a)) {
17536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: add: ~" + x +  " != " + z);
17546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: add: ~" + a + " != " + c);
17556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkCanonicalRep(z, (UnicodeString)"complement " + a);
17576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::_testAdd(int32_t a, int32_t b, UnicodeSet& x, UnicodeSet& y, UnicodeSet& z) {
17606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(a, x);
17616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(b, y);
17626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z = x;
17636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z.addAll(y);
17646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t c = setToBits(z);
17656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c != (a | b)) {
17666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: add: " + x + " | " + y + " != " + z);
17676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: add: " + a + " | " + b + " != " + c);
17686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkCanonicalRep(z, (UnicodeString)"add " + a + "," + b);
17706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::_testRetain(int32_t a, int32_t b, UnicodeSet& x, UnicodeSet& y, UnicodeSet& z) {
17736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(a, x);
17746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(b, y);
17756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z = x;
17766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z.retainAll(y);
17776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t c = setToBits(z);
17786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c != (a & b)) {
17796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: retain: " + x + " & " + y + " != " + z);
17806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: retain: " + a + " & " + b + " != " + c);
17816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkCanonicalRep(z, (UnicodeString)"retain " + a + "," + b);
17836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::_testRemove(int32_t a, int32_t b, UnicodeSet& x, UnicodeSet& y, UnicodeSet& z) {
17866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(a, x);
17876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(b, y);
17886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z = x;
17896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z.removeAll(y);
17906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t c = setToBits(z);
17916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c != (a &~ b)) {
17926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: remove: " + x + " &~ " + y + " != " + z);
17936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: remove: " + a + " &~ " + b + " != " + c);
17946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
17956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkCanonicalRep(z, (UnicodeString)"remove " + a + "," + b);
17966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
17976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
17986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::_testXor(int32_t a, int32_t b, UnicodeSet& x, UnicodeSet& y, UnicodeSet& z) {
17996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(a, x);
18006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bitsToSet(b, y);
18016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z = x;
18026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    z.complementAll(y);
18036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t c = setToBits(z);
18046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (c != (a ^ b)) {
18056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: complement: " + x + " ^ " + y + " != " + z);
18066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAILED: complement: " + a + " ^ " + b + " != " + c);
18076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkCanonicalRep(z, (UnicodeString)"complement " + a + "," + b);
18096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
18126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Check that ranges are monotonically increasing and non-
18136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * overlapping.
18146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
18156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::checkCanonicalRep(const UnicodeSet& set, const UnicodeString& msg) {
18166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t n = set.getRangeCount();
18176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (n < 0) {
18186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL result of " + msg +
18196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              ": range count should be >= 0 but is " +
18206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              n /*+ " for " + set.toPattern())*/);
18216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
18226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar32 last = 0;
18246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i<n; ++i) {
18256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 start = set.getRangeStart(i);
18266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 end = set.getRangeEnd(i);
18276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (start > end) {
18286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL result of " + msg +
18296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  ": range " + (i+1) +
18306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  " start > end: " + (int)start + ", " + (int)end +
18316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  " for " + set);
18326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (i > 0 && start <= last) {
18346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL result of " + msg +
18356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  ": range " + (i+1) +
18366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  " overlaps previous range: " + (int)start + ", " + (int)end +
18376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  " for " + set);
18386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        last = end;
18406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
18446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Convert a bitmask to a UnicodeSet.
18456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
18466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSet& UnicodeSetTest::bitsToSet(int32_t a, UnicodeSet& result) {
18476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    result.clear();
18486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (UChar32 i = 0; i < 32; ++i) {
18496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if ((a & (1<<i)) != 0) {
18506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            result.add(i);
18516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return result;
18546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
18576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Convert a UnicodeSet to a bitmask.  Only the characters
18586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * U+0000 to U+0020 are represented in the bitmask.
18596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
18606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgint32_t UnicodeSetTest::setToBits(const UnicodeSet& x) {
18616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t result = 0;
18626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i = 0; i < 32; ++i) {
18636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (x.contains((UChar32)i)) {
18646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            result |= (1<<i);
18656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return result;
18686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
18716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Return the representation of an inversion list based UnicodeSet
18726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * as a pairs list.  Ranges are listed in ascending Unicode order.
18736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * For example, the set [a-zA-M3] is represented as "33AMaz".
18746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
18756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeString UnicodeSetTest::getPairs(const UnicodeSet& set) {
18766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pairs;
18776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i<set.getRangeCount(); ++i) {
18786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 start = set.getRangeStart(i);
18796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 end = set.getRangeEnd(i);
18806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (end > 0xFFFF) {
18816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            end = 0xFFFF;
18826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            i = set.getRangeCount(); // Should be unnecessary
18836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
18846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        pairs.append((UChar)start).append((UChar)end);
18856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
18866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return pairs;
18876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
18886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org/**
18906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * Basic consistency check for a few items.
18916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * That the iterator works, and that we can create a pattern and
18926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org * get the same thing back
18936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org */
18946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::checkRoundTrip(const UnicodeSet& s) {
18956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
18966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
18976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet t(s);
18986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkEqual(s, t, "copy ct");
18996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    t = s;
19016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkEqual(s, t, "operator=");
19026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    copyWithIterator(t, s, FALSE);
19046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkEqual(s, t, "iterator roundtrip");
19056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    copyWithIterator(t, s, TRUE); // try range
19076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    checkEqual(s, t, "iterator roundtrip");
19086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat; s.toPattern(pat, FALSE);
19106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    t.applyPattern(pat, ec);
19116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
19126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: applyPattern");
19136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
19146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
19156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        checkEqual(s, t, "toPattern(false)");
19166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    s.toPattern(pat, TRUE);
19196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    t.applyPattern(pat, ec);
19206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
19216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: applyPattern");
19226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
19236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
19246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        checkEqual(s, t, "toPattern(true)");
19256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::copyWithIterator(UnicodeSet& t, const UnicodeSet& s, UBool withRange) {
19296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    t.clear();
19306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSetIterator it(s);
19316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (withRange) {
19326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        while (it.nextRange()) {
19336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (it.isString()) {
19346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                t.add(it.getString());
19356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
19366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                t.add(it.getCodepoint(), it.getCodepointEnd());
19376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
19386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
19406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        while (it.next()) {
19416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (it.isString()) {
19426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                t.add(it.getString());
19436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
19446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                t.add(it.getCodepoint());
19456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
19466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
19476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUBool UnicodeSetTest::checkEqual(const UnicodeSet& s, const UnicodeSet& t, const char* message) {
19516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString source; s.toPattern(source, TRUE);
19526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString result; t.toPattern(result, TRUE);
19536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (s != t) {
19546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: " + message
19556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              + "; source = " + source
19566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              + "; result = " + result
19576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              );
19586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return FALSE;
19596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
19606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"Ok: " + message
19616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              + "; source = " + source
19626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              + "; result = " + result
19636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              );
19646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return TRUE;
19666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
19696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::expectContainment(const UnicodeString& pat,
19706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                  const UnicodeString& charsIn,
19716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                  const UnicodeString& charsOut) {
19726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode ec = U_ZERO_ERROR;
19736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet set(pat, ec);
19746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(ec)) {
19756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln((UnicodeString)"FAIL: pattern \"" +
19766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              pat + "\" => " + u_errorName(ec));
19776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
19786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
19796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectContainment(set, pat, charsIn, charsOut);
19806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
19836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::expectContainment(const UnicodeSet& set,
19846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                  const UnicodeString& charsIn,
19856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                  const UnicodeString& charsOut) {
19866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat;
19876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.toPattern(pat);
19886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    expectContainment(set, pat, charsIn, charsOut);
19896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
19906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
19916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
19926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::expectContainment(const UnicodeSet& set,
19936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                  const UnicodeString& setName,
19946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                  const UnicodeString& charsIn,
19956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                  const UnicodeString& charsOut) {
19966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString bad;
19976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UChar32 c;
19986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t i;
19996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i<charsIn.length(); i+=U16_LENGTH(c)) {
20016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        c = charsIn.char32At(i);
20026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (!set.contains(c)) {
20036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            bad.append(c);
20046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
20056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (bad.length() > 0) {
20076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"Fail: set " + setName + " does not contain " + prettify(bad) +
20086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              ", expected containment of " + prettify(charsIn));
20096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
20106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"Ok: set " + setName + " contains " + prettify(charsIn));
20116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    bad.truncate(0);
20146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (i=0; i<charsOut.length(); i+=U16_LENGTH(c)) {
20156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        c = charsOut.char32At(i);
20166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (set.contains(c)) {
20176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            bad.append(c);
20186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
20196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (bad.length() > 0) {
20216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"Fail: set " + setName + " contains " + prettify(bad) +
20226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              ", expected non-containment of " + prettify(charsOut));
20236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
20246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"Ok: set " + setName + " does not contain " + prettify(charsOut));
20256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
20296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::expectPattern(UnicodeSet& set,
20306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                              const UnicodeString& pattern,
20316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                              const UnicodeString& expectedPairs){
20326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode status = U_ZERO_ERROR;
20336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.applyPattern(pattern, status);
20346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) {
20356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln(UnicodeString("FAIL: applyPattern(\"") + pattern +
20366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              "\") failed");
20376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
20396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (getPairs(set) != expectedPairs ) {
20406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln(UnicodeString("FAIL: applyPattern(\"") + pattern +
20416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  "\") => pairs \"" +
20426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  escape(getPairs(set)) + "\", expected \"" +
20436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  escape(expectedPairs) + "\"");
20446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
20456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln(UnicodeString("Ok:   applyPattern(\"") + pattern +
20466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  "\") => pairs \"" +
20476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  escape(getPairs(set)) + "\"");
20486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
20496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // the result of calling set.toPattern(), which is the string representation of
20516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // this set(set), is passed to a  UnicodeSet constructor, and tested that it
20526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    // will produce another set that is equal to this one.
20536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString temppattern;
20546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.toPattern(temppattern);
20556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *tempset=new UnicodeSet(temppattern, status);
20566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (U_FAILURE(status)) {
20576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln(UnicodeString("FAIL: applyPattern(\""+ pattern + "\").toPattern() => " + temppattern + " => invalid pattern"));
20586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(*tempset != set || getPairs(*tempset) != getPairs(set)){
20616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln(UnicodeString("FAIL: applyPattern(\""+ pattern + "\").toPattern() => " + temppattern + " => pairs \""+ escape(getPairs(*tempset)) + "\", expected pairs \"" +
20626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            escape(getPairs(set)) + "\""));
20636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else{
20646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln(UnicodeString("Ok:   applyPattern(\""+ pattern + "\").toPattern() => " + temppattern + " => pairs \"" + escape(getPairs(*tempset)) + "\""));
20656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete tempset;
20686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
20726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::expectPairs(const UnicodeSet& set, const UnicodeString& expectedPairs) {
20736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (getPairs(set) != expectedPairs) {
20746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln(UnicodeString("FAIL: Expected pair list \"") +
20756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              escape(expectedPairs) + "\", got \"" +
20766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org              escape(getPairs(set)) + "\"");
20776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
20796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
20806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::expectToPattern(const UnicodeSet& set,
20816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     const UnicodeString& expPat,
20826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                                     const char** expStrings) {
20836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString pat;
20846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    set.toPattern(pat, TRUE);
20856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (pat == expPat) {
20866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        logln((UnicodeString)"Ok:   toPattern() => \"" + pat + "\"");
20876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
20886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln((UnicodeString)"FAIL: toPattern() => \"" + pat + "\", expected \"" + expPat + "\"");
20896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (expStrings == NULL) {
20926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
20936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
20946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UBool in = TRUE;
20956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; expStrings[i] != NULL; ++i) {
20966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (expStrings[i] == NOT) { // sic; pointer comparison
20976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            in = FALSE;
20986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            continue;
20996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
21006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UnicodeString s = CharsToUnicodeString(expStrings[i]);
21016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UBool contained = set.contains(s);
21026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (contained == in) {
21036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            logln((UnicodeString)"Ok: " + expPat +
21046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  (contained ? " contains {" : " does not contain {") +
21056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  escape(expStrings[i]) + "}");
21066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
21076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            errln((UnicodeString)"FAIL: " + expPat +
21086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  (contained ? " contains {" : " does not contain {") +
21096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                  escape(expStrings[i]) + "}");
21106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
21116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic UChar toHexString(int32_t i) { return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10))); }
21156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid
21176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::doAssert(UBool condition, const char *message)
21186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org{
21196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if (!condition) {
21206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln(UnicodeString("ERROR : ") + message);
21216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeString
21256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgUnicodeSetTest::escape(const UnicodeString& s) {
21266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString buf;
21276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    for (int32_t i=0; i<s.length(); )
21286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    {
21296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        UChar32 c = s.char32At(i);
21306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if (0x0020 <= c && c <= 0x007F) {
21316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += c;
21326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        } else {
21336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            if (c <= 0xFFFF) {
21346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                buf += (UChar)0x5c; buf += (UChar)0x75;
21356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            } else {
21366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                buf += (UChar)0x5c; buf += (UChar)0x55;
21376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                buf += toHexString((c & 0xF0000000) >> 28);
21386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                buf += toHexString((c & 0x0F000000) >> 24);
21396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                buf += toHexString((c & 0x00F00000) >> 20);
21406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                buf += toHexString((c & 0x000F0000) >> 16);
21416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            }
21426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += toHexString((c & 0xF000) >> 12);
21436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += toHexString((c & 0x0F00) >> 8);
21446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += toHexString((c & 0x00F0) >> 4);
21456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            buf += toHexString(c & 0x000F);
21466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        }
21476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        i += U16_LENGTH(c);
21486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    return buf;
21506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
21516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgvoid UnicodeSetTest::TestFreezable() {
21536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
21546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString idPattern=UNICODE_STRING("[:ID_Continue:]", 15);
21556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet idSet(idPattern, errorCode);
21566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
21576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: unable to create UnicodeSet([:ID_Continue:]) - %s", u_errorName(errorCode));
21586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
21596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeString wsPattern=UNICODE_STRING("[:White_Space:]", 15);
21626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet wsSet(wsPattern, errorCode);
21636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_FAILURE(errorCode)) {
21646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        dataerrln("FAIL: unable to create UnicodeSet([:White_Space:]) - %s", u_errorName(errorCode));
21656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return;
21666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    idSet.add(idPattern);
21696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet frozen(idSet);
21706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.freeze();
21716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(idSet.isFrozen() || !frozen.isFrozen()) {
21736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: isFrozen() is wrong");
21746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
21766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: a copy-constructed frozen set differs from its original");
21776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen=wsSet;
21806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
21816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: a frozen set was modified by operator=");
21826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
21846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet frozen2(frozen);
21856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen2!=frozen || frozen2!=idSet) {
21866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: a copied frozen set differs from its frozen original");
21876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(!frozen2.isFrozen()) {
21896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: copy-constructing a frozen set results in a thawed one");
21906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet frozen3(5, 55);  // Set to some values to really test assignment below, not copy construction.
21926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen3.contains(0, 4) || !frozen3.contains(5, 55) || frozen3.contains(56, 0x10ffff)) {
21936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet(5, 55) failed");
21946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen3=frozen;
21966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(!frozen3.isFrozen()) {
21976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: copying a frozen set results in a thawed one");
21986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
21996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *cloned=(UnicodeSet *)frozen.clone();
22016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(!cloned->isFrozen() || *cloned!=frozen || cloned->containsSome(0xd802, 0xd805)) {
22026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: clone() failed");
22036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    cloned->add(0xd802, 0xd805);
22056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(cloned->containsSome(0xd802, 0xd805)) {
22066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: unable to modify clone");
22076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete cloned;
22096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSet *thawed=(UnicodeSet *)frozen.cloneAsThawed();
22116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(thawed->isFrozen() || *thawed!=frozen || thawed->containsSome(0xd802, 0xd805)) {
22126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: cloneAsThawed() failed");
22136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    thawed->add(0xd802, 0xd805);
22156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(!thawed->contains(0xd802, 0xd805)) {
22166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: unable to modify thawed clone");
22176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    delete thawed;
22196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.set(5, 55);
22216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::set() modified a frozen set");
22236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.clear();
22266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::clear() modified a frozen set");
22286f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22296f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22306f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.closeOver(USET_CASE_INSENSITIVE);
22316f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22326f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::closeOver() modified a frozen set");
22336f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22346f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22356f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.compact();
22366f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22376f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::compact() modified a frozen set");
22386f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22396f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22406f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    ParsePosition pos;
22416f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.
22426f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        applyPattern(wsPattern, errorCode).
22436f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        applyPattern(wsPattern, USET_IGNORE_SPACE, NULL, errorCode).
22446f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        applyPattern(wsPattern, pos, USET_IGNORE_SPACE, NULL, errorCode).
22456f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        applyIntPropertyValue(UCHAR_CANONICAL_COMBINING_CLASS, 230, errorCode).
22466f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        applyPropertyAlias(UNICODE_STRING_SIMPLE("Assigned"), UnicodeString(), errorCode);
22476f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22486f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::applyXYZ() modified a frozen set");
22496f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22506f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22516f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.
22526f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        add(0xd800).
22536f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        add(0xd802, 0xd805).
22546f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        add(wsPattern).
22556f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        addAll(idPattern).
22566f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        addAll(wsSet);
22576f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22586f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::addXYZ() modified a frozen set");
22596f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22606f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22616f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.
22626f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        retain(0x62).
22636f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        retain(0x64, 0x69).
22646f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        retainAll(wsPattern).
22656f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        retainAll(wsSet);
22666f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22676f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::retainXYZ() modified a frozen set");
22686f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22696f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22706f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.
22716f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        remove(0x62).
22726f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        remove(0x64, 0x69).
22736f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        remove(idPattern).
22746f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        removeAll(idPattern).
22756f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        removeAll(idSet);
22766f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22776f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::removeXYZ() modified a frozen set");
22786f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22796f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22806f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    frozen.
22816f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        complement().
22826f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        complement(0x62).
22836f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        complement(0x64, 0x69).
22846f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        complement(idPattern).
22856f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        complementAll(idPattern).
22866f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        complementAll(idSet);
22876f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(frozen!=idSet || !(frozen==idSet)) {
22886f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        errln("FAIL: UnicodeSet::complementXYZ() modified a frozen set");
22896f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
22906f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
22916f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22926f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Test span() etc. -------------------------------------------------------- ***
22936f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
22946f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Append the UTF-8 version of the string to t and return the appended UTF-8 length.
22956f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgstatic int32_t
22966f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgappendUTF8(const UChar *s, int32_t length, char *t, int32_t capacity) {
22976f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UErrorCode errorCode=U_ZERO_ERROR;
22986f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    int32_t length8=0;
22996f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    u_strToUTF8(t, capacity, &length8, s, length, &errorCode);
23006f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    if(U_SUCCESS(errorCode)) {
23016f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return length8;
23026f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    } else {
23036f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // The string contains an unpaired surrogate.
23046f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        // Ignore this string.
23056f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        return 0;
23066f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    }
23076f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org}
23086f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23096f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgclass UnicodeSetWithStringsIterator;
23106f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org
23116f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org// Make the strings in a UnicodeSet easily accessible.
23126f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgclass UnicodeSetWithStrings {
23136f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.orgpublic:
23146f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org    UnicodeSetWithStrings(const UnicodeSet &normalSet) :
23156f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            set(normalSet), stringsLength(0), hasSurrogates(FALSE) {
23166f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        int32_t size=set.size();
23176f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org        if(size>0 && set.charAt(size-1)<0) {
23186f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // If a set's last element is not a code point, then it must contain strings.
23196f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // Iterate over the set, skip all code point ranges, and cache the strings.
23206f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            // Convert them to UTF-8 for spanUTF8().
23216f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            UnicodeSetIterator iter(set);
23226f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            const UnicodeString *s;
23236f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            char *s8=utf8;
23246f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            int32_t length8, utf8Count=0;
23256f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org            while(iter.nextRange() && stringsLength<LENGTHOF(strings)) {
23266f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                if(iter.isString()) {
23276f31ac30b9092fd02a8c97e5216cf53f3e4fae4jshin@chromium.org                    // Store the pointer to the set's string element
2328