1999-10-26 17:16:13 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2003-06-03 20:58:22 +00:00
|
|
|
* Copyright (C) 1999-2003 Alan Liu ,International Business Machines Corporation and
|
2001-03-21 20:09:56 +00:00
|
|
|
* others. All Rights Reserved.
|
1999-10-26 17:16:13 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 10/20/99 alan Creation.
|
2000-03-28 23:51:25 +00:00
|
|
|
* 03/22/2000 Madhu Added additional tests
|
1999-10-26 17:16:13 +00:00
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
1999-10-20 22:08:09 +00:00
|
|
|
#include "usettest.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/uniset.h"
|
2002-08-21 22:14:43 +00:00
|
|
|
#include "unicode/uchar.h"
|
2002-04-26 06:28:15 +00:00
|
|
|
#include "unicode/usetiter.h"
|
2003-02-17 23:31:10 +00:00
|
|
|
#include "unicode/ustring.h"
|
2003-09-29 23:00:39 +00:00
|
|
|
#include "unicode/parsepos.h"
|
2003-10-14 21:47:59 +00:00
|
|
|
#include "unicode/symtable.h"
|
2003-09-29 23:00:39 +00:00
|
|
|
#include "hash.h"
|
2001-12-03 18:41:21 +00:00
|
|
|
|
2000-05-25 19:28:53 +00:00
|
|
|
UnicodeString operator+(const UnicodeString& left, const UnicodeSet& set) {
|
|
|
|
UnicodeString pat;
|
|
|
|
set.toPattern(pat);
|
|
|
|
return left + UnicodeSetTest::escape(pat);
|
|
|
|
}
|
|
|
|
|
1999-10-20 22:08:09 +00:00
|
|
|
#define CASE(id,test) case id: \
|
|
|
|
name = #test; \
|
|
|
|
if (exec) { \
|
|
|
|
logln(#test "---"); \
|
|
|
|
logln((UnicodeString)""); \
|
|
|
|
test(); \
|
|
|
|
} \
|
2000-05-25 19:28:53 +00:00
|
|
|
break
|
1999-10-20 22:08:09 +00:00
|
|
|
|
|
|
|
void
|
2000-05-18 22:08:39 +00:00
|
|
|
UnicodeSetTest::runIndexedTest(int32_t index, UBool exec,
|
2000-08-23 19:11:16 +00:00
|
|
|
const char* &name, char* /*par*/) {
|
1999-10-20 22:08:09 +00:00
|
|
|
// if (exec) logln((UnicodeString)"TestSuite UnicodeSetTest");
|
|
|
|
switch (index) {
|
2000-05-25 19:28:53 +00:00
|
|
|
CASE(0,TestPatterns);
|
|
|
|
CASE(1,TestAddRemove);
|
|
|
|
CASE(2,TestCategories);
|
|
|
|
CASE(3,TestCloneEqualHash);
|
|
|
|
CASE(4,TestMinimalRep);
|
|
|
|
CASE(5,TestAPI);
|
2001-10-10 21:36:26 +00:00
|
|
|
CASE(6,TestScriptSet);
|
2001-10-17 19:21:12 +00:00
|
|
|
CASE(7,TestPropertySet);
|
2001-11-12 20:57:06 +00:00
|
|
|
CASE(8,TestClone);
|
|
|
|
CASE(9,TestExhaustive);
|
2001-12-01 01:33:41 +00:00
|
|
|
CASE(10,TestToPattern);
|
2001-12-11 01:13:33 +00:00
|
|
|
CASE(11,TestIndexOf);
|
2002-04-26 06:28:15 +00:00
|
|
|
CASE(12,TestStrings);
|
|
|
|
CASE(13,TestStringPatterns);
|
2002-08-29 23:23:45 +00:00
|
|
|
CASE(14,Testj2268);
|
2003-02-11 22:47:28 +00:00
|
|
|
CASE(15,TestCloseOver);
|
2003-02-17 23:31:10 +00:00
|
|
|
CASE(16,TestEscapePattern);
|
2003-05-14 22:30:21 +00:00
|
|
|
CASE(17,TestInvalidCodePoint);
|
2003-09-29 23:00:39 +00:00
|
|
|
CASE(18,TestSymbolTable);
|
2003-10-07 18:10:37 +00:00
|
|
|
CASE(19,TestSurrogate);
|
2000-08-10 00:28:31 +00:00
|
|
|
default: name = ""; break;
|
1999-10-20 22:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-29 23:23:45 +00:00
|
|
|
/**
|
|
|
|
* UVector was improperly copying contents
|
|
|
|
* This code will crash this is still true
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::Testj2268() {
|
|
|
|
UnicodeSet t;
|
|
|
|
t.add(UnicodeString("abc"));
|
|
|
|
UnicodeSet test(t);
|
|
|
|
UnicodeString ustrPat;
|
|
|
|
test.toPattern(ustrPat, TRUE);
|
|
|
|
}
|
|
|
|
|
2001-12-01 01:33:41 +00:00
|
|
|
/**
|
|
|
|
* Test that toPattern() round trips with syntax characters and
|
|
|
|
* whitespace.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::TestToPattern() {
|
2001-12-01 21:46:53 +00:00
|
|
|
static const char* OTHER_TOPATTERN_TESTS[] = {
|
|
|
|
"[[:latin:]&[:greek:]]",
|
|
|
|
"[[:latin:]-[:greek:]]",
|
|
|
|
"[:nonspacing mark:]",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int32_t j=0; OTHER_TOPATTERN_TESTS[j]!=NULL; ++j) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
UnicodeSet s(OTHER_TOPATTERN_TESTS[j], ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln((UnicodeString)"FAIL: bad pattern " + OTHER_TOPATTERN_TESTS[j]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
checkPat(OTHER_TOPATTERN_TESTS[j], s);
|
|
|
|
}
|
|
|
|
|
2001-12-01 01:33:41 +00:00
|
|
|
for (UChar32 i = 0; i <= 0x10FFFF; ++i) {
|
|
|
|
if ((i <= 0xFF && !u_isalpha(i)) || u_isspace(i)) {
|
2001-12-03 18:41:21 +00:00
|
|
|
|
2001-12-01 01:33:41 +00:00
|
|
|
// check various combinations to make sure they all work.
|
2001-12-03 18:41:21 +00:00
|
|
|
if (i != 0 && !toPatternAux(i, i)){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!toPatternAux(0, i)){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!toPatternAux(i, 0xFFFF)){
|
|
|
|
continue;
|
|
|
|
}
|
2001-12-01 01:33:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool UnicodeSetTest::toPatternAux(UChar32 start, UChar32 end) {
|
2001-12-03 18:41:21 +00:00
|
|
|
|
2001-12-01 01:33:41 +00:00
|
|
|
// use Integer.toString because Utility.hex doesn't handle ints
|
|
|
|
UnicodeString pat = "";
|
|
|
|
// TODO do these in hex
|
|
|
|
//String source = "0x" + Integer.toString(start,16).toUpperCase();
|
|
|
|
//if (start != end) source += "..0x" + Integer.toString(end,16).toUpperCase();
|
2001-12-03 21:31:39 +00:00
|
|
|
UnicodeString source;
|
|
|
|
source = source + (uint32_t)start;
|
2001-12-03 18:41:21 +00:00
|
|
|
if (start != end)
|
|
|
|
source = source + ".." + (uint32_t)end;
|
2001-12-01 01:33:41 +00:00
|
|
|
UnicodeSet testSet;
|
|
|
|
testSet.add(start, end);
|
2001-12-01 21:46:53 +00:00
|
|
|
return checkPat(source, testSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool UnicodeSetTest::checkPat(const UnicodeString& source,
|
|
|
|
const UnicodeSet& testSet) {
|
2001-12-01 01:33:41 +00:00
|
|
|
// What we want to make sure of is that a pattern generated
|
|
|
|
// by toPattern(), with or without escaped unprintables, can
|
|
|
|
// be passed back into the UnicodeSet constructor.
|
2001-12-03 18:41:21 +00:00
|
|
|
UnicodeString pat0;
|
|
|
|
|
|
|
|
testSet.toPattern(pat0, TRUE);
|
|
|
|
|
2001-12-01 01:33:41 +00:00
|
|
|
if (!checkPat(source + " (escaped)", testSet, pat0)) return FALSE;
|
|
|
|
|
|
|
|
//String pat1 = unescapeLeniently(pat0);
|
|
|
|
//if (!checkPat(source + " (in code)", testSet, pat1)) return false;
|
|
|
|
|
2001-12-03 18:41:21 +00:00
|
|
|
UnicodeString pat2;
|
|
|
|
testSet.toPattern(pat2, FALSE);
|
2001-12-01 01:33:41 +00:00
|
|
|
if (!checkPat(source, testSet, pat2)) return FALSE;
|
|
|
|
|
|
|
|
//String pat3 = unescapeLeniently(pat2);
|
2001-12-03 18:41:21 +00:00
|
|
|
// if (!checkPat(source + " (in code)", testSet, pat3)) return false;
|
2001-12-01 01:33:41 +00:00
|
|
|
|
|
|
|
//logln(source + " => " + pat0 + ", " + pat1 + ", " + pat2 + ", " + pat3);
|
|
|
|
logln((UnicodeString)source + " => " + pat0 + ", " + pat2);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-12-01 21:46:53 +00:00
|
|
|
|
2001-12-01 01:33:41 +00:00
|
|
|
UBool UnicodeSetTest::checkPat(const UnicodeString& source,
|
|
|
|
const UnicodeSet& testSet,
|
|
|
|
const UnicodeString& pat) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
UnicodeSet testSet2(pat, ec);
|
|
|
|
if (testSet2 != testSet) {
|
|
|
|
errln((UnicodeString)"Fail toPattern: " + source + " => " + pat);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-10-20 22:08:09 +00:00
|
|
|
void
|
1999-12-22 22:57:04 +00:00
|
|
|
UnicodeSetTest::TestPatterns(void) {
|
1999-10-26 17:16:13 +00:00
|
|
|
UnicodeSet set;
|
2000-08-02 19:06:18 +00:00
|
|
|
expectPattern(set, UnicodeString("[[a-m]&[d-z]&[k-y]]", ""), "km");
|
|
|
|
expectPattern(set, UnicodeString("[[a-z]-[m-y]-[d-r]]", ""), "aczz");
|
|
|
|
expectPattern(set, UnicodeString("[a\\-z]", ""), "--aazz");
|
|
|
|
expectPattern(set, UnicodeString("[-az]", ""), "--aazz");
|
|
|
|
expectPattern(set, UnicodeString("[az-]", ""), "--aazz");
|
|
|
|
expectPattern(set, UnicodeString("[[[a-z]-[aeiou]i]]", ""), "bdfnptvz");
|
1999-10-26 17:16:13 +00:00
|
|
|
|
|
|
|
// Throw in a test of complement
|
|
|
|
set.complement();
|
|
|
|
UnicodeString exp;
|
2000-06-28 22:26:59 +00:00
|
|
|
exp.append((UChar)0x0000).append("aeeoouu").append((UChar)(0x007a+1)).append((UChar)0xFFFF);
|
1999-10-26 17:16:13 +00:00
|
|
|
expectPairs(set, exp);
|
|
|
|
}
|
|
|
|
|
2000-01-12 18:04:21 +00:00
|
|
|
void
|
|
|
|
UnicodeSetTest::TestCategories(void) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
const char* pat = " [:Lu:] "; // Whitespace ok outside [:..:]
|
|
|
|
UnicodeSet set(pat, status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln((UnicodeString)"Fail: Can't construct set with " + pat);
|
|
|
|
} else {
|
|
|
|
expectContainment(set, pat, "ABC", "abc");
|
|
|
|
}
|
2000-05-25 19:28:53 +00:00
|
|
|
|
|
|
|
UChar32 i;
|
|
|
|
int32_t failures = 0;
|
|
|
|
// Make sure generation of L doesn't pollute cached Lu set
|
|
|
|
// First generate L, then Lu
|
|
|
|
set.applyPattern("[:L:]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
for (i=0; i<0x200; ++i) {
|
2002-08-21 19:09:33 +00:00
|
|
|
UBool l = u_isalpha((UChar)i);
|
2000-05-25 19:28:53 +00:00
|
|
|
if (l != set.contains(i)) {
|
2000-06-02 01:10:20 +00:00
|
|
|
errln((UnicodeString)"FAIL: L contains " + (unsigned short)i + " = " +
|
2000-05-25 19:28:53 +00:00
|
|
|
set.contains(i));
|
|
|
|
if (++failures == 10) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set.applyPattern("[:Lu:]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
for (i=0; i<0x200; ++i) {
|
2002-08-21 19:09:33 +00:00
|
|
|
UBool lu = (u_charType((UChar)i) == U_UPPERCASE_LETTER);
|
2000-05-25 19:28:53 +00:00
|
|
|
if (lu != set.contains(i)) {
|
2000-06-02 01:10:20 +00:00
|
|
|
errln((UnicodeString)"FAIL: Lu contains " + (unsigned short)i + " = " +
|
2000-05-25 19:28:53 +00:00
|
|
|
set.contains(i));
|
|
|
|
if (++failures == 20) break;
|
|
|
|
}
|
|
|
|
}
|
2000-01-12 18:04:21 +00:00
|
|
|
}
|
2000-03-28 23:51:25 +00:00
|
|
|
void
|
|
|
|
UnicodeSetTest::TestCloneEqualHash(void) {
|
2000-08-14 21:42:36 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2003-05-02 20:38:27 +00:00
|
|
|
// set1 and set2 used to be built with the obsolete constructor taking
|
|
|
|
// UCharCategory values; replaced with pattern constructors
|
|
|
|
// markus 20030502
|
|
|
|
UnicodeSet *set1=new UnicodeSet("\\p{Lowercase Letter}", status); // :Ll: Letter, lowercase
|
2001-10-26 05:42:31 +00:00
|
|
|
UnicodeSet *set1a=new UnicodeSet("[:Ll:]", status); // Letter, lowercase
|
2000-08-14 21:42:36 +00:00
|
|
|
if (U_FAILURE(status)){
|
2001-10-17 19:21:12 +00:00
|
|
|
errln((UnicodeString)"FAIL: Can't construst set with category->Ll");
|
2000-08-14 21:42:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-05-02 20:38:27 +00:00
|
|
|
UnicodeSet *set2=new UnicodeSet("\\p{Decimal Number}", status); //Number, Decimal digit
|
2001-10-26 05:42:31 +00:00
|
|
|
UnicodeSet *set2a=new UnicodeSet("[:Nd:]", status); //Number, Decimal digit
|
2000-08-14 21:42:36 +00:00
|
|
|
if (U_FAILURE(status)){
|
2001-10-17 19:21:12 +00:00
|
|
|
errln((UnicodeString)"FAIL: Can't construct set with category->Nd");
|
2000-08-14 21:42:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-26 05:42:31 +00:00
|
|
|
if (*set1 != *set1a) {
|
|
|
|
errln("FAIL: category constructor for Ll broken");
|
|
|
|
}
|
|
|
|
if (*set2 != *set2a) {
|
|
|
|
errln("FAIL: category constructor for Nd broken");
|
|
|
|
}
|
|
|
|
delete set1a;
|
|
|
|
delete set2a;
|
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
logln("Testing copy construction");
|
|
|
|
UnicodeSet *set1copy=new UnicodeSet(*set1);
|
|
|
|
if(*set1 != *set1copy || *set1 == *set2 ||
|
|
|
|
getPairs(*set1) != getPairs(*set1copy) ||
|
|
|
|
set1->hashCode() != set1copy->hashCode()){
|
|
|
|
errln("FAIL : Error in copy construction");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
logln("Testing =operator");
|
|
|
|
UnicodeSet set1equal=*set1;
|
|
|
|
UnicodeSet set2equal=*set2;
|
|
|
|
if(set1equal != *set1 || set1equal != *set1copy || set2equal != *set2 ||
|
|
|
|
set2equal == *set1 || set2equal == *set1copy || set2equal == set1equal){
|
|
|
|
errln("FAIL: Error in =operator");
|
|
|
|
}
|
|
|
|
|
|
|
|
logln("Testing clone()");
|
|
|
|
UnicodeSet *set1clone=(UnicodeSet*)set1->clone();
|
|
|
|
UnicodeSet *set2clone=(UnicodeSet*)set2->clone();
|
|
|
|
if(*set1clone != *set1 || *set1clone != *set1copy || *set1clone != set1equal ||
|
|
|
|
*set2clone != *set2 || *set2clone == *set1copy || *set2clone != set2equal ||
|
|
|
|
*set2clone == *set1 || *set2clone == set1equal || *set2clone == *set1clone){
|
|
|
|
errln("FAIL: Error in clone");
|
|
|
|
}
|
|
|
|
|
|
|
|
logln("Testing hashcode");
|
2000-03-28 23:51:25 +00:00
|
|
|
if(set1->hashCode() != set1equal.hashCode() || set1->hashCode() != set1clone->hashCode() ||
|
2000-08-14 21:42:36 +00:00
|
|
|
set2->hashCode() != set2equal.hashCode() || set2->hashCode() != set2clone->hashCode() ||
|
|
|
|
set1copy->hashCode() != set1equal.hashCode() || set1copy->hashCode() != set1clone->hashCode() ||
|
|
|
|
set1->hashCode() == set2->hashCode() || set1copy->hashCode() == set2->hashCode() ||
|
|
|
|
set2->hashCode() == set1clone->hashCode() || set2->hashCode() == set1equal.hashCode() ){
|
|
|
|
errln("FAIL: Error in hashCode()");
|
|
|
|
}
|
|
|
|
|
|
|
|
delete set1;
|
|
|
|
delete set1copy;
|
|
|
|
delete set2;
|
2001-09-19 02:08:04 +00:00
|
|
|
delete set1clone;
|
|
|
|
delete set2clone;
|
2000-03-28 23:51:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
1999-10-26 17:16:13 +00:00
|
|
|
void
|
1999-12-22 22:57:04 +00:00
|
|
|
UnicodeSetTest::TestAddRemove(void) {
|
1999-10-20 22:08:09 +00:00
|
|
|
UnicodeSet set; // Construct empty set
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.isEmpty() == TRUE, "set should be empty");
|
|
|
|
doAssert(set.size() == 0, "size should be 0");
|
2000-06-28 22:26:59 +00:00
|
|
|
set.add(0x0061, 0x007a);
|
1999-10-26 17:16:13 +00:00
|
|
|
expectPairs(set, "az");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.isEmpty() == FALSE, "set should not be empty");
|
2000-03-28 23:51:25 +00:00
|
|
|
doAssert(set.size() != 0, "size should not be equal to 0");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.size() == 26, "size should be equal to 26");
|
2000-06-28 22:26:59 +00:00
|
|
|
set.remove(0x006d, 0x0070);
|
2000-08-14 21:42:36 +00:00
|
|
|
expectPairs(set, "alqz");
|
|
|
|
doAssert(set.size() == 22, "size should be equal to 22");
|
2000-06-28 22:26:59 +00:00
|
|
|
set.remove(0x0065, 0x0067);
|
1999-10-26 17:16:13 +00:00
|
|
|
expectPairs(set, "adhlqz");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.size() == 19, "size should be equal to 19");
|
2000-06-28 22:26:59 +00:00
|
|
|
set.remove(0x0064, 0x0069);
|
1999-10-26 17:16:13 +00:00
|
|
|
expectPairs(set, "acjlqz");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.size() == 16, "size should be equal to 16");
|
2000-06-28 22:26:59 +00:00
|
|
|
set.remove(0x0063, 0x0072);
|
1999-10-26 17:16:13 +00:00
|
|
|
expectPairs(set, "absz");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.size() == 10, "size should be equal to 10");
|
2000-06-28 22:26:59 +00:00
|
|
|
set.add(0x0066, 0x0071);
|
1999-10-26 17:16:13 +00:00
|
|
|
expectPairs(set, "abfqsz");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.size() == 22, "size should be equal to 22");
|
2000-06-28 22:26:59 +00:00
|
|
|
set.remove(0x0061, 0x0067);
|
1999-10-26 17:16:13 +00:00
|
|
|
expectPairs(set, "hqsz");
|
2000-06-28 22:26:59 +00:00
|
|
|
set.remove(0x0061, 0x007a);
|
2000-03-28 23:51:25 +00:00
|
|
|
expectPairs(set, "");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.isEmpty() == TRUE, "set should be empty");
|
|
|
|
doAssert(set.size() == 0, "size should be 0");
|
|
|
|
set.add(0x0061);
|
|
|
|
doAssert(set.isEmpty() == FALSE, "set should not be empty");
|
2000-03-28 23:51:25 +00:00
|
|
|
doAssert(set.size() == 1, "size should not be equal to 1");
|
2000-08-14 21:42:36 +00:00
|
|
|
set.add(0x0062);
|
|
|
|
set.add(0x0063);
|
|
|
|
expectPairs(set, "ac");
|
|
|
|
doAssert(set.size() == 3, "size should not be equal to 3");
|
|
|
|
set.add(0x0070);
|
|
|
|
set.add(0x0071);
|
|
|
|
expectPairs(set, "acpq");
|
|
|
|
doAssert(set.size() == 5, "size should not be equal to 5");
|
|
|
|
set.clear();
|
1999-10-26 17:16:13 +00:00
|
|
|
expectPairs(set, "");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.isEmpty() == TRUE, "set should be empty");
|
|
|
|
doAssert(set.size() == 0, "size should be 0");
|
1999-10-20 22:08:09 +00:00
|
|
|
|
1999-10-26 17:16:13 +00:00
|
|
|
// Try removing an entire set from another set
|
|
|
|
expectPattern(set, "[c-x]", "cx");
|
|
|
|
UnicodeSet set2;
|
|
|
|
expectPattern(set2, "[f-ky-za-bc[vw]]", "acfkvwyz");
|
|
|
|
set.removeAll(set2);
|
|
|
|
expectPairs(set, "deluxx");
|
1999-10-20 22:08:09 +00:00
|
|
|
|
1999-10-26 17:16:13 +00:00
|
|
|
// Try adding an entire set to another set
|
|
|
|
expectPattern(set, "[jackiemclean]", "aacceein");
|
|
|
|
expectPattern(set2, "[hitoshinamekatajamesanderson]", "aadehkmort");
|
|
|
|
set.addAll(set2);
|
|
|
|
expectPairs(set, "aacehort");
|
2000-03-28 23:51:25 +00:00
|
|
|
doAssert(set.containsAll(set2) == TRUE, "set should contain all the elements in set2");
|
|
|
|
|
2000-08-14 21:42:36 +00:00
|
|
|
// Try retaining an set of elements contained in another set (intersection)
|
|
|
|
UnicodeSet set3;
|
|
|
|
expectPattern(set3, "[a-c]", "ac");
|
|
|
|
doAssert(set.containsAll(set3) == FALSE, "set doesn't contain all the elements in set3");
|
|
|
|
set3.remove(0x0062);
|
|
|
|
expectPairs(set3, "aacc");
|
|
|
|
doAssert(set.containsAll(set3) == TRUE, "set should contain all the elements in set3");
|
|
|
|
set.retainAll(set3);
|
|
|
|
expectPairs(set, "aacc");
|
|
|
|
doAssert(set.size() == set3.size(), "set.size() should be set3.size()");
|
|
|
|
doAssert(set.containsAll(set3) == TRUE, "set should contain all the elements in set3");
|
|
|
|
set.clear();
|
|
|
|
doAssert(set.size() != set3.size(), "set.size() != set3.size()");
|
1999-10-20 22:08:09 +00:00
|
|
|
|
1999-10-26 17:16:13 +00:00
|
|
|
// Test commutativity
|
|
|
|
expectPattern(set, "[hitoshinamekatajamesanderson]", "aadehkmort");
|
|
|
|
expectPattern(set2, "[jackiemclean]", "aacceein");
|
|
|
|
set.addAll(set2);
|
|
|
|
expectPairs(set, "aacehort");
|
2000-08-14 21:42:36 +00:00
|
|
|
doAssert(set.containsAll(set2) == TRUE, "set should contain all the elements in set2");
|
2000-03-28 23:51:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-10-26 17:16:13 +00:00
|
|
|
|
2000-03-28 23:51:25 +00:00
|
|
|
}
|
2000-05-25 19:28:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure minimal representation is maintained.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::TestMinimalRep() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
// This is pretty thoroughly tested by checkCanonicalRep()
|
|
|
|
// run against the exhaustive operation results. Use the code
|
|
|
|
// here for debugging specific spot problems.
|
|
|
|
|
|
|
|
// 1 overlap against 2
|
|
|
|
UnicodeSet set("[h-km-q]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
UnicodeSet set2("[i-o]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
set.addAll(set2);
|
|
|
|
expectPairs(set, "hq");
|
|
|
|
// right
|
|
|
|
set.applyPattern("[a-m]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
set2.applyPattern("[e-o]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
set.addAll(set2);
|
|
|
|
expectPairs(set, "ao");
|
|
|
|
// left
|
|
|
|
set.applyPattern("[e-o]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
set2.applyPattern("[a-m]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
set.addAll(set2);
|
|
|
|
expectPairs(set, "ao");
|
|
|
|
// 1 overlap against 3
|
|
|
|
set.applyPattern("[a-eg-mo-w]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
set2.applyPattern("[d-q]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
set.addAll(set2);
|
|
|
|
expectPairs(set, "aw");
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnicodeSetTest::TestAPI() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
// default ct
|
|
|
|
UnicodeSet set;
|
|
|
|
if (!set.isEmpty() || set.getRangeCount() != 0) {
|
|
|
|
errln((UnicodeString)"FAIL, set should be empty but isn't: " +
|
|
|
|
set);
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear(), isEmpty()
|
2000-06-28 22:26:59 +00:00
|
|
|
set.add(0x0061);
|
2000-05-25 19:28:53 +00:00
|
|
|
if (set.isEmpty()) {
|
|
|
|
errln((UnicodeString)"FAIL, set shouldn't be empty but is: " +
|
|
|
|
set);
|
|
|
|
}
|
|
|
|
set.clear();
|
|
|
|
if (!set.isEmpty()) {
|
|
|
|
errln((UnicodeString)"FAIL, set should be empty but isn't: " +
|
|
|
|
set);
|
|
|
|
}
|
|
|
|
|
|
|
|
// size()
|
|
|
|
set.clear();
|
|
|
|
if (set.size() != 0) {
|
|
|
|
errln((UnicodeString)"FAIL, size should be 0, but is " + set.size() +
|
|
|
|
": " + set);
|
|
|
|
}
|
2000-06-28 22:26:59 +00:00
|
|
|
set.add(0x0061);
|
2000-05-25 19:28:53 +00:00
|
|
|
if (set.size() != 1) {
|
|
|
|
errln((UnicodeString)"FAIL, size should be 1, but is " + set.size() +
|
|
|
|
": " + set);
|
|
|
|
}
|
2000-06-28 22:26:59 +00:00
|
|
|
set.add(0x0031, 0x0039);
|
2000-05-25 19:28:53 +00:00
|
|
|
if (set.size() != 10) {
|
|
|
|
errln((UnicodeString)"FAIL, size should be 10, but is " + set.size() +
|
|
|
|
": " + set);
|
|
|
|
}
|
|
|
|
|
|
|
|
// contains(first, last)
|
|
|
|
set.clear();
|
|
|
|
set.applyPattern("[A-Y 1-8 b-d l-y]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
for (int32_t i = 0; i<set.getRangeCount(); ++i) {
|
|
|
|
UChar32 a = set.getRangeStart(i);
|
|
|
|
UChar32 b = set.getRangeEnd(i);
|
|
|
|
if (!set.contains(a, b)) {
|
2000-06-02 01:10:20 +00:00
|
|
|
errln((UnicodeString)"FAIL, should contain " + (unsigned short)a + '-' + (unsigned short)b +
|
2000-05-25 19:28:53 +00:00
|
|
|
" but doesn't: " + set);
|
|
|
|
}
|
|
|
|
if (set.contains((UChar32)(a-1), b)) {
|
|
|
|
errln((UnicodeString)"FAIL, shouldn't contain " +
|
2000-06-02 01:10:20 +00:00
|
|
|
(unsigned short)(a-1) + '-' + (unsigned short)b +
|
2000-05-25 19:28:53 +00:00
|
|
|
" but does: " + set);
|
|
|
|
}
|
|
|
|
if (set.contains(a, (UChar32)(b+1))) {
|
|
|
|
errln((UnicodeString)"FAIL, shouldn't contain " +
|
2000-06-02 01:10:20 +00:00
|
|
|
(unsigned short)a + '-' + (unsigned short)(b+1) +
|
2000-05-25 19:28:53 +00:00
|
|
|
" but does: " + set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ported InversionList test.
|
|
|
|
UnicodeSet a((UChar32)3,(UChar32)10);
|
|
|
|
UnicodeSet b((UChar32)7,(UChar32)15);
|
|
|
|
UnicodeSet c;
|
|
|
|
|
|
|
|
logln((UnicodeString)"a [3-10]: " + a);
|
|
|
|
logln((UnicodeString)"b [7-15]: " + b);
|
2003-12-13 09:24:51 +00:00
|
|
|
c = a;
|
|
|
|
c.addAll(b);
|
2000-05-25 19:28:53 +00:00
|
|
|
UnicodeSet exp((UChar32)3,(UChar32)15);
|
|
|
|
if (c == exp) {
|
|
|
|
logln((UnicodeString)"c.set(a).add(b): " + c);
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: c.set(a).add(b) = " + c + ", expect " + exp);
|
|
|
|
}
|
|
|
|
c.complement();
|
|
|
|
exp.set((UChar32)0, (UChar32)2);
|
2000-05-26 02:07:25 +00:00
|
|
|
exp.add((UChar32)16, UnicodeSet::MAX_VALUE);
|
2000-05-25 19:28:53 +00:00
|
|
|
if (c == exp) {
|
|
|
|
logln((UnicodeString)"c.complement(): " + c);
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: c.complement() = " + c + ", expect " + exp);
|
|
|
|
}
|
|
|
|
c.complement();
|
|
|
|
exp.set((UChar32)3, (UChar32)15);
|
|
|
|
if (c == exp) {
|
|
|
|
logln((UnicodeString)"c.complement(): " + c);
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: c.complement() = " + c + ", expect " + exp);
|
|
|
|
}
|
2003-12-13 09:24:51 +00:00
|
|
|
c = a;
|
|
|
|
c.complementAll(b);
|
2000-05-25 19:28:53 +00:00
|
|
|
exp.set((UChar32)3,(UChar32)6);
|
|
|
|
exp.add((UChar32)11,(UChar32) 15);
|
|
|
|
if (c == exp) {
|
2000-05-26 16:40:29 +00:00
|
|
|
logln((UnicodeString)"c.set(a).exclusiveOr(b): " + c);
|
2000-05-25 19:28:53 +00:00
|
|
|
} else {
|
2000-05-26 16:40:29 +00:00
|
|
|
errln((UnicodeString)"FAIL: c.set(a).exclusiveOr(b) = " + c + ", expect " + exp);
|
2000-05-25 19:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exp = c;
|
2000-05-25 20:57:30 +00:00
|
|
|
bitsToSet(setToBits(c), c);
|
2000-05-25 19:28:53 +00:00
|
|
|
if (c == exp) {
|
|
|
|
logln((UnicodeString)"bitsToSet(setToBits(c)): " + c);
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: bitsToSet(setToBits(c)) = " + c + ", expect " + exp);
|
2000-03-28 23:51:25 +00:00
|
|
|
}
|
2002-11-26 18:24:44 +00:00
|
|
|
|
|
|
|
// Additional tests for coverage JB#2118
|
|
|
|
//UnicodeSet::complement(class UnicodeString const &)
|
|
|
|
//UnicodeSet::complementAll(class UnicodeString const &)
|
|
|
|
//UnicodeSet::containsNone(class UnicodeSet const &)
|
|
|
|
//UnicodeSet::containsNone(long,long)
|
|
|
|
//UnicodeSet::containsSome(class UnicodeSet const &)
|
|
|
|
//UnicodeSet::containsSome(long,long)
|
|
|
|
//UnicodeSet::removeAll(class UnicodeString const &)
|
|
|
|
//UnicodeSet::retain(long)
|
|
|
|
//UnicodeSet::retainAll(class UnicodeString const &)
|
|
|
|
//UnicodeSet::serialize(unsigned short *,long,enum UErrorCode &)
|
|
|
|
//UnicodeSetIterator::getString(void)
|
|
|
|
set.clear();
|
|
|
|
set.complement("ab");
|
|
|
|
exp.applyPattern("[{ab}]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
if (set != exp) { errln("FAIL: complement(\"ab\")"); return; }
|
|
|
|
|
|
|
|
UnicodeSetIterator iset(set);
|
|
|
|
if (!iset.next() || !iset.isString()) {
|
|
|
|
errln("FAIL: UnicodeSetIterator::next/isString");
|
|
|
|
} else if (iset.getString() != "ab") {
|
|
|
|
errln("FAIL: UnicodeSetIterator::getString");
|
|
|
|
}
|
|
|
|
|
|
|
|
set.add((UChar32)0x61, (UChar32)0x7A);
|
|
|
|
set.complementAll("alan");
|
|
|
|
exp.applyPattern("[{ab}b-kmo-z]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
if (set != exp) { errln("FAIL: complementAll(\"alan\")"); return; }
|
|
|
|
|
|
|
|
exp.applyPattern("[a-z]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
2002-11-28 00:53:05 +00:00
|
|
|
if (set.containsNone(exp)) { errln("FAIL: containsNone(UnicodeSet)"); }
|
|
|
|
if (!set.containsSome(exp)) { errln("FAIL: containsSome(UnicodeSet)"); }
|
2002-11-26 18:24:44 +00:00
|
|
|
exp.applyPattern("[aln]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
2002-11-28 00:53:05 +00:00
|
|
|
if (!set.containsNone(exp)) { errln("FAIL: containsNone(UnicodeSet)"); }
|
|
|
|
if (set.containsSome(exp)) { errln("FAIL: containsSome(UnicodeSet)"); }
|
2002-11-26 18:24:44 +00:00
|
|
|
|
|
|
|
if (set.containsNone((UChar32)0x61, (UChar32)0x7A)) {
|
|
|
|
errln("FAIL: containsNone(UChar32, UChar32)");
|
2002-11-28 00:53:05 +00:00
|
|
|
}
|
|
|
|
if (!set.containsSome((UChar32)0x61, (UChar32)0x7A)) {
|
|
|
|
errln("FAIL: containsSome(UChar32, UChar32)");
|
2002-11-26 18:24:44 +00:00
|
|
|
}
|
|
|
|
if (!set.containsNone((UChar32)0x41, (UChar32)0x5A)) {
|
|
|
|
errln("FAIL: containsNone(UChar32, UChar32)");
|
2002-11-28 00:53:05 +00:00
|
|
|
}
|
|
|
|
if (set.containsSome((UChar32)0x41, (UChar32)0x5A)) {
|
|
|
|
errln("FAIL: containsSome(UChar32, UChar32)");
|
2002-11-26 18:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set.removeAll("liu");
|
|
|
|
exp.applyPattern("[{ab}b-hj-kmo-tv-z]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
if (set != exp) { errln("FAIL: removeAll(\"liu\")"); return; }
|
|
|
|
|
|
|
|
set.retainAll("star");
|
|
|
|
exp.applyPattern("[rst]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
if (set != exp) { errln("FAIL: retainAll(\"star\")"); return; }
|
|
|
|
|
|
|
|
set.retain((UChar32)0x73);
|
|
|
|
exp.applyPattern("[s]", status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL"); return; }
|
|
|
|
if (set != exp) { errln("FAIL: retain('s')"); return; }
|
|
|
|
|
|
|
|
uint16_t buf[32];
|
|
|
|
int32_t slen = set.serialize(buf, sizeof(buf)/sizeof(buf[0]), status);
|
|
|
|
if (U_FAILURE(status)) { errln("FAIL: serialize"); return; }
|
|
|
|
if (slen != 3 || buf[0] != 2 || buf[1] != 0x73 || buf[2] != 0x74) {
|
|
|
|
errln("FAIL: serialize");
|
|
|
|
return;
|
|
|
|
}
|
2000-03-28 23:51:25 +00:00
|
|
|
}
|
2000-05-25 19:28:53 +00:00
|
|
|
|
2002-04-26 06:28:15 +00:00
|
|
|
void UnicodeSetTest::TestStrings() {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
UnicodeSet* testList[] = {
|
|
|
|
UnicodeSet::createFromAll("abc"),
|
|
|
|
new UnicodeSet("[a-c]", ec),
|
|
|
|
|
|
|
|
&(UnicodeSet::createFrom("ch")->add('a','z').add("ll")),
|
|
|
|
new UnicodeSet("[{ll}{ch}a-z]", ec),
|
|
|
|
|
|
|
|
UnicodeSet::createFrom("ab}c"),
|
|
|
|
new UnicodeSet("[{ab\\}c}]", ec),
|
|
|
|
|
|
|
|
&((new UnicodeSet('a','z'))->add('A', 'Z').retain('M','m').complement('X')),
|
|
|
|
new UnicodeSet("[[a-zA-Z]&[M-m]-[X]]", ec),
|
|
|
|
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: couldn't construct test sets");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t i = 0; testList[i] != NULL; i+=2) {
|
|
|
|
if (U_SUCCESS(ec)) {
|
|
|
|
UnicodeString pat0, pat1;
|
|
|
|
testList[i]->toPattern(pat0, TRUE);
|
|
|
|
testList[i+1]->toPattern(pat1, TRUE);
|
|
|
|
if (*testList[i] == *testList[i+1]) {
|
|
|
|
logln((UnicodeString)"Ok: " + pat0 + " == " + pat1);
|
|
|
|
} else {
|
|
|
|
logln((UnicodeString)"FAIL: " + pat0 + " != " + pat1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete testList[i];
|
|
|
|
delete testList[i+1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-21 23:53:07 +00:00
|
|
|
static const char NOT[] = "%%%%";
|
2002-04-26 06:28:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test pattern behavior of multicharacter strings.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::TestStringPatterns() {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
UnicodeSet* s = new UnicodeSet("[a-z {aa} {ab}]", ec);
|
|
|
|
|
|
|
|
// This loop isn't a loop. It's here to make the compiler happy.
|
|
|
|
// If you're curious, try removing it and changing the 'break'
|
|
|
|
// statements (except for the last) to goto's.
|
|
|
|
for (;;) {
|
|
|
|
if (U_FAILURE(ec)) break;
|
2002-05-21 23:53:07 +00:00
|
|
|
const char* exp1[] = {"aa", "ab", NOT, "ac", NULL};
|
2002-04-26 06:28:15 +00:00
|
|
|
expectToPattern(*s, "[a-z{aa}{ab}]", exp1);
|
|
|
|
|
|
|
|
s->add("ac");
|
2002-05-21 23:53:07 +00:00
|
|
|
const char* exp2[] = {"aa", "ab", "ac", NOT, "xy", NULL};
|
2002-04-26 06:28:15 +00:00
|
|
|
expectToPattern(*s, "[a-z{aa}{ab}{ac}]", exp2);
|
|
|
|
|
|
|
|
s->applyPattern("[a-z {\\{l} {r\\}}]", ec);
|
|
|
|
if (U_FAILURE(ec)) break;
|
2002-05-21 23:53:07 +00:00
|
|
|
const char* exp3[] = {"{l", "r}", NOT, "xy", NULL};
|
2003-09-29 23:00:39 +00:00
|
|
|
expectToPattern(*s, "[a-z{r\\}}{\\{l}]", exp3);
|
2002-04-26 06:28:15 +00:00
|
|
|
|
|
|
|
s->add("[]");
|
2002-05-21 23:53:07 +00:00
|
|
|
const char* exp4[] = {"{l", "r}", "[]", NOT, "xy", NULL};
|
2002-04-26 06:28:15 +00:00
|
|
|
expectToPattern(*s, "[a-z{\\[\\]}{r\\}}{\\{l}]", exp4);
|
|
|
|
|
|
|
|
s->applyPattern("[a-z {\\u4E01\\u4E02}{\\n\\r}]", ec);
|
|
|
|
if (U_FAILURE(ec)) break;
|
2002-05-21 23:53:07 +00:00
|
|
|
const char* exp5[] = {"\\u4E01\\u4E02", "\n\r", NULL};
|
2003-09-29 23:00:39 +00:00
|
|
|
expectToPattern(*s, "[a-z{\\u000A\\u000D}{\\u4E01\\u4E02}]", exp5);
|
2002-04-26 06:28:15 +00:00
|
|
|
|
2002-08-29 04:58:00 +00:00
|
|
|
// j2189
|
|
|
|
s->clear();
|
|
|
|
s->add(UnicodeString("abc", ""));
|
|
|
|
s->add(UnicodeString("abc", ""));
|
|
|
|
const char* exp6[] = {"abc", NOT, "ab", NULL};
|
|
|
|
expectToPattern(*s, "[{abc}]", exp6);
|
|
|
|
|
2002-04-26 06:28:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (U_FAILURE(ec)) errln("FAIL: pattern parse error");
|
|
|
|
delete s;
|
|
|
|
}
|
|
|
|
|
2001-10-10 21:36:26 +00:00
|
|
|
/**
|
|
|
|
* Test the [:Latin:] syntax.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::TestScriptSet() {
|
2003-02-14 21:18:41 +00:00
|
|
|
expectContainment("[:Latin:]", "aA", CharsToUnicodeString("\\u0391\\u03B1"));
|
2001-10-10 21:36:26 +00:00
|
|
|
|
2003-02-14 21:18:41 +00:00
|
|
|
expectContainment("[:Greek:]", CharsToUnicodeString("\\u0391\\u03B1"), "aA");
|
2001-11-03 03:03:43 +00:00
|
|
|
|
|
|
|
/* Jitterbug 1423 */
|
2003-02-14 21:18:41 +00:00
|
|
|
expectContainment("[[:Common:][:Inherited:]]", CharsToUnicodeString("\\U00003099\\U0001D169\\u0000"), "aA");
|
2001-11-03 03:03:43 +00:00
|
|
|
|
2001-10-10 21:36:26 +00:00
|
|
|
}
|
|
|
|
|
2001-10-17 19:21:12 +00:00
|
|
|
/**
|
|
|
|
* Test the [:Latin:] syntax.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::TestPropertySet() {
|
2002-06-06 00:47:14 +00:00
|
|
|
static const char* DATA[] = {
|
|
|
|
// Pattern, Chars IN, Chars NOT in
|
|
|
|
|
|
|
|
"[:Latin:]",
|
|
|
|
"aA",
|
|
|
|
"\\u0391\\u03B1",
|
|
|
|
|
|
|
|
"[\\p{Greek}]",
|
|
|
|
"\\u0391\\u03B1",
|
|
|
|
"aA",
|
|
|
|
|
|
|
|
"\\P{ GENERAL Category = upper case letter }",
|
|
|
|
"abc",
|
|
|
|
"ABC",
|
|
|
|
|
|
|
|
// Combining class: @since ICU 2.2
|
|
|
|
// Check both symbolic and numeric
|
2002-06-06 22:38:37 +00:00
|
|
|
"\\p{ccc=Nukta}",
|
2002-06-06 00:47:14 +00:00
|
|
|
"\\u0ABC",
|
|
|
|
"abc",
|
|
|
|
|
2002-06-06 22:38:37 +00:00
|
|
|
"\\p{Canonical Combining Class = 11}",
|
2002-06-06 00:47:14 +00:00
|
|
|
"\\u05B1",
|
|
|
|
"\\u05B2",
|
|
|
|
|
2002-06-06 22:38:37 +00:00
|
|
|
"[:c c c = iota subscript :]",
|
2002-06-06 00:47:14 +00:00
|
|
|
"\\u0345",
|
|
|
|
"xyz",
|
|
|
|
|
|
|
|
// Bidi class: @since ICU 2.2
|
|
|
|
"\\p{bidiclass=lefttoright}",
|
|
|
|
"abc",
|
|
|
|
"\\u0671\\u0672",
|
|
|
|
|
|
|
|
// Binary properties: @since ICU 2.2
|
|
|
|
"\\p{ideographic}",
|
|
|
|
"\\u4E0A",
|
|
|
|
"x",
|
|
|
|
|
2002-06-06 22:38:37 +00:00
|
|
|
"[:math=false:]",
|
2002-06-06 00:47:14 +00:00
|
|
|
"q",
|
|
|
|
"(*+)",
|
2002-08-28 20:23:00 +00:00
|
|
|
|
|
|
|
// JB#1767 \N{}, \p{ASCII}
|
|
|
|
"[:Ascii:]",
|
|
|
|
"abc\\u0000\\u007F",
|
|
|
|
"\\u0080\\u4E00",
|
|
|
|
|
|
|
|
"[\\N{ latin small letter a }[:name= latin small letter z:]]",
|
|
|
|
"az",
|
|
|
|
"qrs",
|
2002-10-30 18:27:36 +00:00
|
|
|
|
|
|
|
// JB#2015
|
|
|
|
"[:any:]",
|
|
|
|
"a\\U0010FFFF",
|
|
|
|
"",
|
|
|
|
|
|
|
|
"[:nv=0.5:]",
|
|
|
|
"\\u00BD\\u0F2A",
|
|
|
|
"\\u00BC",
|
2003-01-21 21:14:10 +00:00
|
|
|
|
|
|
|
// JB#2653: Age
|
|
|
|
"[:Age=1.1:]",
|
|
|
|
"\\u03D6", // 1.1
|
|
|
|
"\\u03D8\\u03D9", // 3.2
|
|
|
|
|
2003-02-26 01:29:03 +00:00
|
|
|
"[:Age=3.1:]",
|
|
|
|
"\\u1800\\u3400\\U0002f800",
|
|
|
|
"\\u0220\\u034f\\u30ff\\u33ff\\ufe73\\U00010000\\U00050000",
|
2003-02-20 22:47:50 +00:00
|
|
|
|
|
|
|
// JB#2350: Case_Sensitive
|
|
|
|
"[:Case Sensitive:]",
|
|
|
|
"A\\u1FFC\\U00010410",
|
|
|
|
";\\u00B4\\U00010500",
|
2003-04-25 20:34:44 +00:00
|
|
|
|
|
|
|
// JB#2832: C99-compatibility props
|
|
|
|
"[:blank:]",
|
|
|
|
" \\u0009",
|
|
|
|
"1-9A-Z",
|
|
|
|
|
|
|
|
"[:graph:]",
|
|
|
|
"19AZ",
|
|
|
|
" \\u0003\\u0007\\u0009\\u000A\\u000D",
|
|
|
|
|
|
|
|
"[:punct:]",
|
|
|
|
"!@#%&*()[]{}-_\\/;:,.?'\"",
|
|
|
|
"09azAZ",
|
|
|
|
|
|
|
|
"[:xdigit:]",
|
|
|
|
"09afAF",
|
|
|
|
"gG!",
|
2003-05-09 21:01:57 +00:00
|
|
|
|
|
|
|
// Regex compatibility test
|
|
|
|
"[-b]", // leading '-' is literal
|
|
|
|
"-b",
|
|
|
|
"ac",
|
|
|
|
|
|
|
|
"[^-b]", // leading '-' is literal
|
|
|
|
"ac",
|
|
|
|
"-b",
|
|
|
|
|
|
|
|
"[b-]", // trailing '-' is literal
|
|
|
|
"-b",
|
|
|
|
"ac",
|
|
|
|
|
|
|
|
"[^b-]", // trailing '-' is literal
|
|
|
|
"ac",
|
2003-09-29 23:00:39 +00:00
|
|
|
"-b",
|
|
|
|
|
|
|
|
"[a-b-]", // trailing '-' is literal
|
|
|
|
"ab-",
|
|
|
|
"c=",
|
|
|
|
|
|
|
|
"[[a-q]&[p-z]-]", // trailing '-' is literal
|
|
|
|
"pq-",
|
|
|
|
"or=",
|
|
|
|
|
|
|
|
"[\\s|\\)|:|$|\\>]", // from regex tests
|
|
|
|
"s|):$>",
|
2003-10-13 23:47:25 +00:00
|
|
|
"abc",
|
|
|
|
|
|
|
|
"[\\uDC00cd]", // JB#2906: isolated trail at start
|
|
|
|
"cd\\uDC00",
|
|
|
|
"ab\\uD800\\U00010000",
|
|
|
|
|
|
|
|
"[ab\\uD800]", // JB#2906: isolated trail at start
|
|
|
|
"ab\\uD800",
|
|
|
|
"cd\\uDC00\\U00010000",
|
|
|
|
|
|
|
|
"[ab\\uD800cd]", // JB#2906: isolated lead in middle
|
|
|
|
"abcd\\uD800",
|
|
|
|
"ef\\uDC00\\U00010000",
|
|
|
|
|
|
|
|
"[ab\\uDC00cd]", // JB#2906: isolated trail in middle
|
|
|
|
"abcd\\uDC00",
|
|
|
|
"ef\\uD800\\U00010000"
|
2002-06-06 00:47:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int32_t DATA_LEN = sizeof(DATA)/sizeof(DATA[0]);
|
|
|
|
|
2003-02-14 21:18:41 +00:00
|
|
|
for (int32_t i=0; i<DATA_LEN; i+=3) {
|
|
|
|
expectContainment(DATA[i], CharsToUnicodeString(DATA[i+1]),
|
2002-06-06 00:47:14 +00:00
|
|
|
CharsToUnicodeString(DATA[i+2]));
|
|
|
|
}
|
2001-10-17 19:21:12 +00:00
|
|
|
}
|
|
|
|
|
2001-11-12 20:57:06 +00:00
|
|
|
/**
|
|
|
|
* Test cloning of UnicodeSet. For C++, we test the copy constructor.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::TestClone() {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
UnicodeSet s("[abcxyz]", ec);
|
|
|
|
UnicodeSet t(s);
|
|
|
|
expectContainment(t, "abc", "def");
|
|
|
|
}
|
|
|
|
|
2001-12-11 01:13:33 +00:00
|
|
|
/**
|
|
|
|
* Test the indexOf() and charAt() methods.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::TestIndexOf() {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
UnicodeSet set("[a-cx-y3578]", ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: UnicodeSet constructor");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int32_t i=0; i<set.size(); ++i) {
|
|
|
|
UChar32 c = set.charAt(i);
|
|
|
|
if (set.indexOf(c) != i) {
|
2002-03-21 01:26:40 +00:00
|
|
|
errln("FAIL: charAt(%d) = %X => indexOf() => %d",
|
|
|
|
i, c, set.indexOf(c));
|
2001-12-11 01:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UChar32 c = set.charAt(set.size());
|
|
|
|
if (c != -1) {
|
2002-03-21 01:26:40 +00:00
|
|
|
errln("FAIL: charAt(<out of range>) = %X", c);
|
2001-12-11 01:13:33 +00:00
|
|
|
}
|
|
|
|
int32_t j = set.indexOf((UChar32)0x71/*'q'*/);
|
|
|
|
if (j != -1) {
|
|
|
|
errln((UnicodeString)"FAIL: indexOf('q') = " + j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-11 22:47:28 +00:00
|
|
|
/**
|
|
|
|
* Test closure API.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::TestCloseOver() {
|
2003-02-14 21:18:41 +00:00
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
char CASE[] = {(char)USET_CASE};
|
2003-02-11 22:47:28 +00:00
|
|
|
const char* DATA[] = {
|
|
|
|
// selector, input, output
|
|
|
|
CASE,
|
|
|
|
"[aq\\u00DF{Bc}{bC}{Fi}]",
|
|
|
|
"[aAqQ\\u00DF\\uFB01{ss}{bc}{fi}]",
|
|
|
|
|
|
|
|
CASE,
|
|
|
|
"[\\u01F1]", // 'DZ'
|
|
|
|
"[\\u01F1\\u01F2\\u01F3]",
|
|
|
|
|
|
|
|
CASE,
|
|
|
|
"[\\u1FB4]",
|
|
|
|
"[\\u1FB4{\\u03AC\\u03B9}]",
|
|
|
|
|
|
|
|
CASE,
|
|
|
|
"[{F\\uFB01}]",
|
|
|
|
"[\\uFB03{ffi}]",
|
|
|
|
|
|
|
|
CASE, // make sure binary search finds limits
|
|
|
|
"[a\\uFF3A]",
|
|
|
|
"[aA\\uFF3A\\uFF5A]",
|
|
|
|
|
2003-02-14 00:11:50 +00:00
|
|
|
CASE,
|
|
|
|
"[a-z]","[A-Za-z\\u017F\\u212A]",
|
|
|
|
CASE,
|
|
|
|
"[abc]","[A-Ca-c]",
|
|
|
|
CASE,
|
|
|
|
"[ABC]","[A-Ca-c]",
|
|
|
|
|
2003-02-11 22:47:28 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
UnicodeSet s;
|
|
|
|
UnicodeSet t;
|
|
|
|
for (int32_t i=0; DATA[i]!=NULL; i+=3) {
|
2003-02-14 21:18:41 +00:00
|
|
|
int32_t selector = DATA[i][0];
|
2003-02-11 22:47:28 +00:00
|
|
|
UnicodeString pat(DATA[i+1]);
|
|
|
|
UnicodeString exp(DATA[i+2]);
|
|
|
|
s.applyPattern(pat, ec);
|
|
|
|
s.closeOver(selector);
|
|
|
|
t.applyPattern(exp, ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: applyPattern failed");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (s == t) {
|
|
|
|
logln((UnicodeString)"Ok: " + pat + ".closeOver(" + selector + ") => " + exp);
|
|
|
|
} else {
|
|
|
|
UnicodeString buf;
|
|
|
|
errln((UnicodeString)"FAIL: " + pat + ".closeOver(" + selector + ") => " +
|
|
|
|
s.toPattern(buf, TRUE) + ", expected " + exp);
|
|
|
|
}
|
|
|
|
}
|
2003-02-14 21:18:41 +00:00
|
|
|
|
|
|
|
// Test the pattern API
|
2003-10-14 21:47:59 +00:00
|
|
|
s.applyPattern("[abc]", USET_CASE_INSENSITIVE, NULL, ec);
|
2003-02-14 21:18:41 +00:00
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: applyPattern failed");
|
|
|
|
} else {
|
|
|
|
expectContainment(s, "abcABC", "defDEF");
|
|
|
|
}
|
2003-10-14 21:47:59 +00:00
|
|
|
UnicodeSet v("[^abc]", USET_CASE_INSENSITIVE, NULL, ec);
|
2003-02-14 21:18:41 +00:00
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: constructor failed");
|
|
|
|
} else {
|
|
|
|
expectContainment(v, "defDEF", "abcABC");
|
|
|
|
}
|
2003-02-11 22:47:28 +00:00
|
|
|
}
|
|
|
|
|
2003-02-17 23:31:10 +00:00
|
|
|
void UnicodeSetTest::TestEscapePattern() {
|
|
|
|
const char pattern[] =
|
2003-10-04 00:37:18 +00:00
|
|
|
"[\\uFEFF \\u200A-\\u200E \\U0001D173-\\U0001D17A \\U000F0000-\\U000FFFFD ]";
|
2003-02-17 23:31:10 +00:00
|
|
|
const char exp[] =
|
2003-10-04 00:37:18 +00:00
|
|
|
"[\\u200A-\\u200E\\uFEFF\\U0001D173-\\U0001D17A\\U000F0000-\\U000FFFFD]";
|
2003-02-17 23:57:13 +00:00
|
|
|
// We test this with two passes; in the second pass we
|
2003-10-04 00:37:18 +00:00
|
|
|
// pre-unescape the pattern. Since U+200E is rule whitespace,
|
|
|
|
// this fails -- which is what we expect.
|
2003-02-17 23:57:13 +00:00
|
|
|
for (int32_t pass=1; pass<=2; ++pass) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
2003-02-17 23:31:10 +00:00
|
|
|
UnicodeString pat(pattern);
|
2003-02-17 23:57:13 +00:00
|
|
|
if (pass==2) {
|
|
|
|
pat = pat.unescape();
|
|
|
|
}
|
|
|
|
// Pattern is only good for pass 1
|
|
|
|
UBool isPatternValid = (pass==1);
|
2003-02-17 23:31:10 +00:00
|
|
|
|
2003-02-17 23:57:13 +00:00
|
|
|
UnicodeSet set(pat, ec);
|
|
|
|
if (U_SUCCESS(ec) != isPatternValid){
|
2003-02-17 23:31:10 +00:00
|
|
|
errln((UnicodeString)"FAIL: applyPattern(" +
|
2003-02-17 23:57:13 +00:00
|
|
|
escape(pat) + ") => " +
|
2003-02-17 23:31:10 +00:00
|
|
|
u_errorName(ec));
|
|
|
|
continue;
|
|
|
|
}
|
2003-02-17 23:57:13 +00:00
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
continue;
|
|
|
|
}
|
2003-02-17 23:31:10 +00:00
|
|
|
if (set.contains((UChar)0x0644)){
|
|
|
|
errln((UnicodeString)"FAIL: " + escape(pat) + " contains(U+0664)");
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString newpat;
|
|
|
|
set.toPattern(newpat, TRUE);
|
|
|
|
if (newpat == exp) {
|
|
|
|
logln(escape(pat) + " => " + newpat);
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: " + escape(pat) + " => " + newpat);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int32_t i=0; i<set.getRangeCount(); ++i) {
|
2003-02-17 23:57:13 +00:00
|
|
|
UnicodeString str("Range ");
|
2003-02-17 23:31:10 +00:00
|
|
|
str.append((UChar)(0x30 + i))
|
|
|
|
.append(": ")
|
|
|
|
.append((UChar32)set.getRangeStart(i))
|
|
|
|
.append(" - ")
|
|
|
|
.append((UChar32)set.getRangeEnd(i));
|
2003-02-17 23:57:13 +00:00
|
|
|
str = str + " (" + set.getRangeStart(i) + " - " +
|
|
|
|
set.getRangeEnd(i) + ")";
|
|
|
|
if (set.getRangeStart(i) < 0) {
|
|
|
|
errln((UnicodeString)"FAIL: " + escape(str));
|
|
|
|
} else {
|
|
|
|
logln(escape(str));
|
|
|
|
}
|
2003-02-17 23:31:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-14 22:30:21 +00:00
|
|
|
void UnicodeSetTest::expectRange(const UnicodeString& label,
|
|
|
|
const UnicodeSet& set,
|
|
|
|
UChar32 start, UChar32 end) {
|
|
|
|
UnicodeSet exp(start, end);
|
|
|
|
UnicodeString pat;
|
|
|
|
if (set == exp) {
|
|
|
|
logln(label + " => " + set.toPattern(pat, TRUE));
|
|
|
|
} else {
|
|
|
|
UnicodeString xpat;
|
|
|
|
errln((UnicodeString)"FAIL: " + label + " => " +
|
|
|
|
set.toPattern(pat, TRUE) +
|
|
|
|
", expected " + exp.toPattern(xpat, TRUE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnicodeSetTest::TestInvalidCodePoint() {
|
|
|
|
|
|
|
|
const UChar32 DATA[] = {
|
|
|
|
// Test range Expected range
|
|
|
|
0, 0x10FFFF, 0, 0x10FFFF,
|
|
|
|
(UChar32)-1, 8, 0, 8,
|
|
|
|
8, 0x110000, 8, 0x10FFFF
|
|
|
|
};
|
|
|
|
const int32_t DATA_LENGTH = sizeof(DATA)/sizeof(DATA[0]);
|
|
|
|
|
|
|
|
UnicodeString pat;
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i=0; i<DATA_LENGTH; i+=4) {
|
|
|
|
UChar32 start = DATA[i];
|
|
|
|
UChar32 end = DATA[i+1];
|
|
|
|
UChar32 xstart = DATA[i+2];
|
|
|
|
UChar32 xend = DATA[i+3];
|
|
|
|
|
|
|
|
// Try various API using the test code points
|
|
|
|
|
|
|
|
UnicodeSet set(start, end);
|
|
|
|
expectRange((UnicodeString)"ct(" + start + "," + end + ")",
|
|
|
|
set, xstart, xend);
|
|
|
|
|
|
|
|
set.clear();
|
|
|
|
set.set(start, end);
|
|
|
|
expectRange((UnicodeString)"set(" + start + "," + end + ")",
|
|
|
|
set, xstart, xend);
|
|
|
|
|
|
|
|
UBool b = set.contains(start);
|
|
|
|
b = set.contains(start, end);
|
|
|
|
b = set.containsNone(start, end);
|
|
|
|
b = set.containsSome(start, end);
|
|
|
|
|
2003-12-13 09:24:51 +00:00
|
|
|
/*int32_t index = set.indexOf(start);*/
|
2003-05-14 22:30:21 +00:00
|
|
|
|
|
|
|
set.clear();
|
|
|
|
set.add(start);
|
|
|
|
set.add(start, end);
|
|
|
|
expectRange((UnicodeString)"add(" + start + "," + end + ")",
|
|
|
|
set, xstart, xend);
|
|
|
|
|
|
|
|
set.set(0, 0x10FFFF);
|
|
|
|
set.retain(start, end);
|
|
|
|
expectRange((UnicodeString)"retain(" + start + "," + end + ")",
|
|
|
|
set, xstart, xend);
|
|
|
|
set.retain(start);
|
|
|
|
|
|
|
|
set.set(0, 0x10FFFF);
|
|
|
|
set.remove(start);
|
|
|
|
set.remove(start, end);
|
|
|
|
set.complement();
|
|
|
|
expectRange((UnicodeString)"!remove(" + start + "," + end + ")",
|
|
|
|
set, xstart, xend);
|
|
|
|
|
|
|
|
set.set(0, 0x10FFFF);
|
|
|
|
set.complement(start, end);
|
|
|
|
set.complement();
|
|
|
|
expectRange((UnicodeString)"!complement(" + start + "," + end + ")",
|
|
|
|
set, xstart, xend);
|
|
|
|
set.complement(start);
|
|
|
|
}
|
|
|
|
|
|
|
|
const UChar32 DATA2[] = {
|
|
|
|
0,
|
|
|
|
0x10FFFF,
|
|
|
|
(UChar32)-1,
|
|
|
|
0x110000
|
|
|
|
};
|
|
|
|
const int32_t DATA2_LENGTH = sizeof(DATA2)/sizeof(DATA2[0]);
|
|
|
|
|
|
|
|
for (i=0; i<DATA2_LENGTH; ++i) {
|
|
|
|
UChar32 c = DATA2[i], end = 0x10FFFF;
|
|
|
|
UBool valid = (c >= 0 && c <= 0x10FFFF);
|
|
|
|
|
|
|
|
UnicodeSet set(0, 0x10FFFF);
|
|
|
|
|
|
|
|
// For single-codepoint contains, invalid codepoints are NOT contained
|
|
|
|
UBool b = set.contains(c);
|
|
|
|
if (b == valid) {
|
|
|
|
logln((UnicodeString)"[\\u0000-\\U0010FFFF].contains(" + c +
|
|
|
|
") = " + b);
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: [\\u0000-\\U0010FFFF].contains(" + c +
|
|
|
|
") = " + b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For codepoint range contains, containsNone, and containsSome,
|
|
|
|
// invalid or empty (start > end) ranges have UNDEFINED behavior.
|
|
|
|
b = set.contains(c, end);
|
|
|
|
logln((UnicodeString)"* [\\u0000-\\U0010FFFF].contains(" + c +
|
|
|
|
"," + end + ") = " + b);
|
|
|
|
|
|
|
|
b = set.containsNone(c, end);
|
|
|
|
logln((UnicodeString)"* [\\u0000-\\U0010FFFF].containsNone(" + c +
|
|
|
|
"," + end + ") = " + b);
|
|
|
|
|
|
|
|
b = set.containsSome(c, end);
|
|
|
|
logln((UnicodeString)"* [\\u0000-\\U0010FFFF].containsSome(" + c +
|
|
|
|
"," + end + ") = " + b);
|
|
|
|
|
|
|
|
int32_t index = set.indexOf(c);
|
|
|
|
if ((index >= 0) == valid) {
|
|
|
|
logln((UnicodeString)"[\\u0000-\\U0010FFFF].indexOf(" + c +
|
|
|
|
") = " + index);
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: [\\u0000-\\U0010FFFF].indexOf(" + c +
|
|
|
|
") = " + index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-29 23:00:39 +00:00
|
|
|
// Used by TestSymbolTable
|
|
|
|
class TokenSymbolTable : public SymbolTable {
|
|
|
|
public:
|
|
|
|
Hashtable contents;
|
|
|
|
|
|
|
|
TokenSymbolTable(UErrorCode& ec) : contents(FALSE, ec) {
|
|
|
|
contents.setValueDeleter(uhash_deleteUnicodeString);
|
|
|
|
}
|
|
|
|
|
|
|
|
~TokenSymbolTable() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* (Non-SymbolTable API) Add the given variable and value to
|
|
|
|
* the table. Variable should NOT contain leading '$'.
|
|
|
|
*/
|
|
|
|
void add(const UnicodeString& var, const UnicodeString& value,
|
|
|
|
UErrorCode& ec) {
|
|
|
|
if (U_SUCCESS(ec)) {
|
|
|
|
contents.put(var, new UnicodeString(value), ec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SymbolTable API
|
|
|
|
*/
|
|
|
|
virtual const UnicodeString* lookup(const UnicodeString& s) const {
|
|
|
|
return (const UnicodeString*) contents.get(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SymbolTable API
|
|
|
|
*/
|
2003-12-01 22:48:01 +00:00
|
|
|
virtual const UnicodeFunctor* lookupMatcher(UChar32 /*ch*/) const {
|
2003-09-29 23:00:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SymbolTable API
|
|
|
|
*/
|
|
|
|
virtual UnicodeString parseReference(const UnicodeString& text,
|
|
|
|
ParsePosition& pos, int32_t limit) const {
|
|
|
|
int32_t start = pos.getIndex();
|
|
|
|
int32_t i = start;
|
|
|
|
UnicodeString result;
|
|
|
|
while (i < limit) {
|
|
|
|
UChar c = text.charAt(i);
|
|
|
|
if ((i==start && !u_isIDStart(c)) || !u_isIDPart(c)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i == start) { // No valid name chars
|
|
|
|
return result; // Indicate failure with empty string
|
|
|
|
}
|
|
|
|
pos.setIndex(i);
|
|
|
|
text.extractBetween(start, i, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void UnicodeSetTest::TestSymbolTable() {
|
|
|
|
// Multiple test cases can be set up here. Each test case
|
|
|
|
// is terminated by null:
|
|
|
|
// var, value, var, value,..., input pat., exp. output pat., null
|
|
|
|
const char* DATA[] = {
|
|
|
|
"us", "a-z", "[0-1$us]", "[0-1a-z]", NULL,
|
|
|
|
"us", "[a-z]", "[0-1$us]", "[0-1[a-z]]", NULL,
|
|
|
|
"us", "\\[a\\-z\\]", "[0-1$us]", "[-01\\[\\]az]", NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int32_t i=0; DATA[i]!=NULL; ++i) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
TokenSymbolTable sym(ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: couldn't construct TokenSymbolTable");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up variables
|
|
|
|
while (DATA[i+2] != NULL) {
|
|
|
|
sym.add(DATA[i], DATA[i+1], ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: couldn't add to TokenSymbolTable");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input pattern and expected output pattern
|
|
|
|
UnicodeString inpat = DATA[i], exppat = DATA[i+1];
|
|
|
|
i += 2;
|
|
|
|
|
|
|
|
ParsePosition pos(0);
|
2003-10-14 21:47:59 +00:00
|
|
|
UnicodeSet us(inpat, pos, USET_IGNORE_SPACE, &sym, ec);
|
2003-09-29 23:00:39 +00:00
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: couldn't construct UnicodeSet");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// results
|
|
|
|
if (pos.getIndex() != inpat.length()) {
|
|
|
|
errln((UnicodeString)"Failed to read to end of string \""
|
|
|
|
+ inpat + "\": read to "
|
|
|
|
+ pos.getIndex() + ", length is "
|
|
|
|
+ inpat.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeSet us2(exppat, ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: couldn't construct expected UnicodeSet");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString a, b;
|
|
|
|
if (us != us2) {
|
|
|
|
errln((UnicodeString)"Failed, got " + us.toPattern(a, TRUE) +
|
|
|
|
", expected " + us2.toPattern(b, TRUE));
|
|
|
|
} else {
|
|
|
|
logln((UnicodeString)"Ok, got " + us.toPattern(a, TRUE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-07 18:10:37 +00:00
|
|
|
void UnicodeSetTest::TestSurrogate() {
|
|
|
|
const char* DATA[] = {
|
|
|
|
// These should all behave identically
|
|
|
|
"[abc\\uD800\\uDC00]",
|
|
|
|
// "[abc\uD800\uDC00]", // Can't do this on C -- only Java
|
|
|
|
"[abc\\U00010000]",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
for (int i=0; DATA[i] != 0; ++i) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
logln((UnicodeString)"Test pattern " + i + " :" + DATA[i]);
|
|
|
|
UnicodeSet set(DATA[i], ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: UnicodeSet constructor");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
expectContainment(set,
|
|
|
|
CharsToUnicodeString("abc\\U00010000"),
|
|
|
|
CharsToUnicodeString("\\uD800;\\uDC00")); // split apart surrogate-pair
|
|
|
|
if (set.size() != 4) {
|
|
|
|
errln((UnicodeString)"FAIL: " + DATA[i] + ".size() == " +
|
|
|
|
set.size() + ", expected 4");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-25 19:28:53 +00:00
|
|
|
void UnicodeSetTest::TestExhaustive() {
|
|
|
|
// exhaustive tests. Simulate UnicodeSets with integers.
|
|
|
|
// That gives us very solid tests (except for large memory tests).
|
|
|
|
|
2002-03-23 00:20:35 +00:00
|
|
|
int32_t limit = 128;
|
2000-05-25 19:28:53 +00:00
|
|
|
|
2002-04-26 06:28:15 +00:00
|
|
|
UnicodeSet x, y, z, aa;
|
2000-05-25 20:57:30 +00:00
|
|
|
|
2002-03-21 01:26:40 +00:00
|
|
|
for (int32_t i = 0; i < limit; ++i) {
|
2000-05-25 20:57:30 +00:00
|
|
|
bitsToSet(i, x);
|
|
|
|
logln((UnicodeString)"Testing " + i + ", " + x);
|
|
|
|
_testComplement(i, x, y);
|
2002-04-26 06:28:15 +00:00
|
|
|
|
|
|
|
// AS LONG AS WE ARE HERE, check roundtrip
|
|
|
|
checkRoundTrip(bitsToSet(i, aa));
|
|
|
|
|
2002-03-23 00:20:35 +00:00
|
|
|
for (int32_t j = 0; j < limit; ++j) {
|
2000-05-25 20:57:30 +00:00
|
|
|
_testAdd(i,j, x,y,z);
|
|
|
|
_testXor(i,j, x,y,z);
|
|
|
|
_testRetain(i,j, x,y,z);
|
|
|
|
_testRemove(i,j, x,y,z);
|
2000-05-25 19:28:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-25 20:57:30 +00:00
|
|
|
void UnicodeSetTest::_testComplement(int32_t a, UnicodeSet& x, UnicodeSet& z) {
|
|
|
|
bitsToSet(a, x);
|
|
|
|
z = x;
|
2000-05-25 19:28:53 +00:00
|
|
|
z.complement();
|
|
|
|
int32_t c = setToBits(z);
|
|
|
|
if (c != (~a)) {
|
|
|
|
errln((UnicodeString)"FAILED: add: ~" + x + " != " + z);
|
|
|
|
errln((UnicodeString)"FAILED: add: ~" + a + " != " + c);
|
|
|
|
}
|
2001-09-19 02:08:04 +00:00
|
|
|
checkCanonicalRep(z, (UnicodeString)"complement " + a);
|
2000-05-25 19:28:53 +00:00
|
|
|
}
|
|
|
|
|
2000-05-25 20:57:30 +00:00
|
|
|
void UnicodeSetTest::_testAdd(int32_t a, int32_t b, UnicodeSet& x, UnicodeSet& y, UnicodeSet& z) {
|
|
|
|
bitsToSet(a, x);
|
|
|
|
bitsToSet(b, y);
|
|
|
|
z = x;
|
2000-05-25 19:28:53 +00:00
|
|
|
z.addAll(y);
|
|
|
|
int32_t c = setToBits(z);
|
|
|
|
if (c != (a | b)) {
|
|
|
|
errln((UnicodeString)"FAILED: add: " + x + " | " + y + " != " + z);
|
|
|
|
errln((UnicodeString)"FAILED: add: " + a + " | " + b + " != " + c);
|
|
|
|
}
|
|
|
|
checkCanonicalRep(z, (UnicodeString)"add " + a + "," + b);
|
|
|
|
}
|
|
|
|
|
2000-05-25 20:57:30 +00:00
|
|
|
void UnicodeSetTest::_testRetain(int32_t a, int32_t b, UnicodeSet& x, UnicodeSet& y, UnicodeSet& z) {
|
|
|
|
bitsToSet(a, x);
|
|
|
|
bitsToSet(b, y);
|
|
|
|
z = x;
|
2000-05-25 19:28:53 +00:00
|
|
|
z.retainAll(y);
|
|
|
|
int32_t c = setToBits(z);
|
|
|
|
if (c != (a & b)) {
|
|
|
|
errln((UnicodeString)"FAILED: retain: " + x + " & " + y + " != " + z);
|
|
|
|
errln((UnicodeString)"FAILED: retain: " + a + " & " + b + " != " + c);
|
|
|
|
}
|
|
|
|
checkCanonicalRep(z, (UnicodeString)"retain " + a + "," + b);
|
|
|
|
}
|
|
|
|
|
2000-05-25 20:57:30 +00:00
|
|
|
void UnicodeSetTest::_testRemove(int32_t a, int32_t b, UnicodeSet& x, UnicodeSet& y, UnicodeSet& z) {
|
|
|
|
bitsToSet(a, x);
|
|
|
|
bitsToSet(b, y);
|
|
|
|
z = x;
|
2000-05-25 19:28:53 +00:00
|
|
|
z.removeAll(y);
|
|
|
|
int32_t c = setToBits(z);
|
|
|
|
if (c != (a &~ b)) {
|
|
|
|
errln((UnicodeString)"FAILED: remove: " + x + " &~ " + y + " != " + z);
|
|
|
|
errln((UnicodeString)"FAILED: remove: " + a + " &~ " + b + " != " + c);
|
|
|
|
}
|
|
|
|
checkCanonicalRep(z, (UnicodeString)"remove " + a + "," + b);
|
|
|
|
}
|
|
|
|
|
2000-05-25 20:57:30 +00:00
|
|
|
void UnicodeSetTest::_testXor(int32_t a, int32_t b, UnicodeSet& x, UnicodeSet& y, UnicodeSet& z) {
|
|
|
|
bitsToSet(a, x);
|
|
|
|
bitsToSet(b, y);
|
|
|
|
z = x;
|
2000-05-26 18:32:15 +00:00
|
|
|
z.complementAll(y);
|
2000-05-25 19:28:53 +00:00
|
|
|
int32_t c = setToBits(z);
|
|
|
|
if (c != (a ^ b)) {
|
2000-05-26 18:32:15 +00:00
|
|
|
errln((UnicodeString)"FAILED: complement: " + x + " ^ " + y + " != " + z);
|
|
|
|
errln((UnicodeString)"FAILED: complement: " + a + " ^ " + b + " != " + c);
|
2000-05-25 19:28:53 +00:00
|
|
|
}
|
2000-05-26 18:32:15 +00:00
|
|
|
checkCanonicalRep(z, (UnicodeString)"complement " + a + "," + b);
|
2000-05-25 19:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that ranges are monotonically increasing and non-
|
|
|
|
* overlapping.
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::checkCanonicalRep(const UnicodeSet& set, const UnicodeString& msg) {
|
|
|
|
int32_t n = set.getRangeCount();
|
|
|
|
if (n < 0) {
|
|
|
|
errln((UnicodeString)"FAIL result of " + msg +
|
|
|
|
": range count should be >= 0 but is " +
|
|
|
|
n /*+ " for " + set.toPattern())*/);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UChar32 last = 0;
|
|
|
|
for (int32_t i=0; i<n; ++i) {
|
|
|
|
UChar32 start = set.getRangeStart(i);
|
|
|
|
UChar32 end = set.getRangeEnd(i);
|
|
|
|
if (start > end) {
|
|
|
|
errln((UnicodeString)"FAIL result of " + msg +
|
|
|
|
": range " + (i+1) +
|
2002-03-21 01:26:40 +00:00
|
|
|
" start > end: " + (int)start + ", " + (int)end +
|
2000-05-25 19:28:53 +00:00
|
|
|
" for " + set);
|
|
|
|
}
|
|
|
|
if (i > 0 && start <= last) {
|
|
|
|
errln((UnicodeString)"FAIL result of " + msg +
|
|
|
|
": range " + (i+1) +
|
2002-03-21 01:26:40 +00:00
|
|
|
" overlaps previous range: " + (int)start + ", " + (int)end +
|
2000-05-25 19:28:53 +00:00
|
|
|
" for " + set);
|
|
|
|
}
|
|
|
|
last = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a bitmask to a UnicodeSet.
|
|
|
|
*/
|
2002-04-26 06:28:15 +00:00
|
|
|
UnicodeSet& UnicodeSetTest::bitsToSet(int32_t a, UnicodeSet& result) {
|
2000-05-25 20:57:30 +00:00
|
|
|
result.clear();
|
|
|
|
for (UChar32 i = 0; i < 32; ++i) {
|
2000-05-25 19:28:53 +00:00
|
|
|
if ((a & (1<<i)) != 0) {
|
2000-05-25 20:57:30 +00:00
|
|
|
result.add(i);
|
2000-05-25 19:28:53 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-26 06:28:15 +00:00
|
|
|
return result;
|
2000-05-25 19:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a UnicodeSet to a bitmask. Only the characters
|
|
|
|
* U+0000 to U+0020 are represented in the bitmask.
|
|
|
|
*/
|
|
|
|
int32_t UnicodeSetTest::setToBits(const UnicodeSet& x) {
|
|
|
|
int32_t result = 0;
|
|
|
|
for (int32_t i = 0; i < 32; ++i) {
|
|
|
|
if (x.contains((UChar32)i)) {
|
|
|
|
result |= (1<<i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the representation of an inversion list based UnicodeSet
|
|
|
|
* as a pairs list. Ranges are listed in ascending Unicode order.
|
|
|
|
* For example, the set [a-zA-M3] is represented as "33AMaz".
|
|
|
|
*/
|
|
|
|
UnicodeString UnicodeSetTest::getPairs(const UnicodeSet& set) {
|
|
|
|
UnicodeString pairs;
|
|
|
|
for (int32_t i=0; i<set.getRangeCount(); ++i) {
|
|
|
|
UChar32 start = set.getRangeStart(i);
|
|
|
|
UChar32 end = set.getRangeEnd(i);
|
|
|
|
if (end > 0xFFFF) {
|
|
|
|
end = 0xFFFF;
|
|
|
|
i = set.getRangeCount(); // Should be unnecessary
|
|
|
|
}
|
|
|
|
pairs.append((UChar)start).append((UChar)end);
|
|
|
|
}
|
|
|
|
return pairs;
|
|
|
|
}
|
|
|
|
|
2002-04-26 06:28:15 +00:00
|
|
|
/**
|
|
|
|
* Basic consistency check for a few items.
|
|
|
|
* That the iterator works, and that we can create a pattern and
|
|
|
|
* get the same thing back
|
|
|
|
*/
|
|
|
|
void UnicodeSetTest::checkRoundTrip(const UnicodeSet& s) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
UnicodeSet t(s);
|
|
|
|
checkEqual(s, t, "copy ct");
|
|
|
|
|
|
|
|
t = s;
|
|
|
|
checkEqual(s, t, "operator=");
|
|
|
|
|
|
|
|
copyWithIterator(t, s, FALSE);
|
|
|
|
checkEqual(s, t, "iterator roundtrip");
|
|
|
|
|
|
|
|
copyWithIterator(t, s, TRUE); // try range
|
|
|
|
checkEqual(s, t, "iterator roundtrip");
|
|
|
|
|
|
|
|
UnicodeString pat; s.toPattern(pat, FALSE);
|
|
|
|
t.applyPattern(pat, ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: applyPattern");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
checkEqual(s, t, "toPattern(false)");
|
|
|
|
}
|
|
|
|
|
|
|
|
s.toPattern(pat, TRUE);
|
|
|
|
t.applyPattern(pat, ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln("FAIL: applyPattern");
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
checkEqual(s, t, "toPattern(true)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnicodeSetTest::copyWithIterator(UnicodeSet& t, const UnicodeSet& s, UBool withRange) {
|
|
|
|
t.clear();
|
|
|
|
UnicodeSetIterator it(s);
|
|
|
|
if (withRange) {
|
|
|
|
while (it.nextRange()) {
|
2002-04-30 22:11:18 +00:00
|
|
|
if (it.isString()) {
|
|
|
|
t.add(it.getString());
|
2002-04-26 06:28:15 +00:00
|
|
|
} else {
|
2002-04-30 22:11:18 +00:00
|
|
|
t.add(it.getCodepoint(), it.getCodepointEnd());
|
2002-04-26 06:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (it.next()) {
|
2002-04-30 22:11:18 +00:00
|
|
|
if (it.isString()) {
|
|
|
|
t.add(it.getString());
|
2002-04-26 06:28:15 +00:00
|
|
|
} else {
|
2002-04-30 22:11:18 +00:00
|
|
|
t.add(it.getCodepoint());
|
2002-04-26 06:28:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UBool UnicodeSetTest::checkEqual(const UnicodeSet& s, const UnicodeSet& t, const char* message) {
|
|
|
|
UnicodeString source; s.toPattern(source, TRUE);
|
|
|
|
UnicodeString result; t.toPattern(result, TRUE);
|
|
|
|
if (s != t) {
|
|
|
|
errln((UnicodeString)"FAIL: " + message
|
|
|
|
+ "; source = " + source
|
|
|
|
+ "; result = " + result
|
|
|
|
);
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
logln((UnicodeString)"Ok: " + message
|
|
|
|
+ "; source = " + source
|
|
|
|
+ "; result = " + result
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-02-14 21:18:41 +00:00
|
|
|
void
|
|
|
|
UnicodeSetTest::expectContainment(const UnicodeString& pat,
|
|
|
|
const UnicodeString& charsIn,
|
|
|
|
const UnicodeString& charsOut) {
|
|
|
|
UErrorCode ec = U_ZERO_ERROR;
|
|
|
|
UnicodeSet set(pat, ec);
|
|
|
|
if (U_FAILURE(ec)) {
|
|
|
|
errln((UnicodeString)"FAIL: pattern \"" +
|
|
|
|
pat + "\" => " + u_errorName(ec));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
expectContainment(set, pat, charsIn, charsOut);
|
|
|
|
}
|
|
|
|
|
2001-10-17 19:21:12 +00:00
|
|
|
void
|
|
|
|
UnicodeSetTest::expectContainment(const UnicodeSet& set,
|
|
|
|
const UnicodeString& charsIn,
|
|
|
|
const UnicodeString& charsOut) {
|
|
|
|
UnicodeString pat;
|
|
|
|
set.toPattern(pat);
|
|
|
|
expectContainment(set, pat, charsIn, charsOut);
|
|
|
|
}
|
|
|
|
|
2000-01-12 18:04:21 +00:00
|
|
|
void
|
|
|
|
UnicodeSetTest::expectContainment(const UnicodeSet& set,
|
|
|
|
const UnicodeString& setName,
|
|
|
|
const UnicodeString& charsIn,
|
|
|
|
const UnicodeString& charsOut) {
|
|
|
|
UnicodeString bad;
|
2003-02-26 01:29:03 +00:00
|
|
|
UChar32 c;
|
2000-01-12 18:04:21 +00:00
|
|
|
int32_t i;
|
2001-11-03 03:03:43 +00:00
|
|
|
|
2003-02-26 01:29:03 +00:00
|
|
|
for (i=0; i<charsIn.length(); i+=U16_LENGTH(c)) {
|
|
|
|
c = charsIn.char32At(i);
|
2000-01-12 18:04:21 +00:00
|
|
|
if (!set.contains(c)) {
|
|
|
|
bad.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bad.length() > 0) {
|
2001-11-07 19:57:35 +00:00
|
|
|
errln((UnicodeString)"Fail: set " + setName + " does not contain " + prettify(bad) +
|
2001-11-03 03:03:43 +00:00
|
|
|
", expected containment of " + prettify(charsIn));
|
2000-01-12 18:04:21 +00:00
|
|
|
} else {
|
2002-06-06 00:47:14 +00:00
|
|
|
logln((UnicodeString)"Ok: set " + setName + " contains " + prettify(charsIn));
|
2000-01-12 18:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bad.truncate(0);
|
2003-02-26 01:29:03 +00:00
|
|
|
for (i=0; i<charsOut.length(); i+=U16_LENGTH(c)) {
|
|
|
|
c = charsOut.char32At(i);
|
2000-01-12 18:04:21 +00:00
|
|
|
if (set.contains(c)) {
|
|
|
|
bad.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bad.length() > 0) {
|
2003-02-26 01:29:03 +00:00
|
|
|
errln((UnicodeString)"Fail: set " + setName + " contains " + prettify(bad) +
|
2002-06-06 00:47:14 +00:00
|
|
|
", expected non-containment of " + prettify(charsOut));
|
2000-01-12 18:04:21 +00:00
|
|
|
} else {
|
2002-06-06 00:47:14 +00:00
|
|
|
logln((UnicodeString)"Ok: set " + setName + " does not contain " + prettify(charsOut));
|
2000-01-12 18:04:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-26 17:16:13 +00:00
|
|
|
void
|
|
|
|
UnicodeSetTest::expectPattern(UnicodeSet& set,
|
|
|
|
const UnicodeString& pattern,
|
2000-03-28 23:51:25 +00:00
|
|
|
const UnicodeString& expectedPairs){
|
1999-10-26 17:16:13 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2000-08-14 21:42:36 +00:00
|
|
|
set.applyPattern(pattern, status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
errln(UnicodeString("FAIL: applyPattern(\"") + pattern +
|
1999-10-26 17:16:13 +00:00
|
|
|
"\") failed");
|
2000-08-14 21:42:36 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2000-05-25 19:28:53 +00:00
|
|
|
if (getPairs(set) != expectedPairs ) {
|
1999-10-26 17:16:13 +00:00
|
|
|
errln(UnicodeString("FAIL: applyPattern(\"") + pattern +
|
|
|
|
"\") => pairs \"" +
|
2000-05-25 19:28:53 +00:00
|
|
|
escape(getPairs(set)) + "\", expected \"" +
|
1999-10-26 17:16:13 +00:00
|
|
|
escape(expectedPairs) + "\"");
|
|
|
|
} else {
|
|
|
|
logln(UnicodeString("Ok: applyPattern(\"") + pattern +
|
|
|
|
"\") => pairs \"" +
|
2000-05-25 19:28:53 +00:00
|
|
|
escape(getPairs(set)) + "\"");
|
1999-10-26 17:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
2000-08-14 21:42:36 +00:00
|
|
|
// the result of calling set.toPattern(), which is the string representation of
|
|
|
|
// this set(set), is passed to a UnicodeSet constructor, and tested that it
|
|
|
|
// will produce another set that is equal to this one.
|
|
|
|
UnicodeString temppattern;
|
|
|
|
set.toPattern(temppattern);
|
|
|
|
UnicodeSet *tempset=new UnicodeSet(temppattern, status);
|
|
|
|
if (U_FAILURE(status)) {
|
2001-06-12 18:08:22 +00:00
|
|
|
errln(UnicodeString("FAIL: applyPattern(\""+ pattern + "\").toPattern() => " + temppattern + " => invalid pattern"));
|
2000-03-28 23:51:25 +00:00
|
|
|
return;
|
2000-08-14 21:42:36 +00:00
|
|
|
}
|
|
|
|
if(*tempset != set || getPairs(*tempset) != getPairs(set)){
|
2001-06-12 18:08:22 +00:00
|
|
|
errln(UnicodeString("FAIL: applyPattern(\""+ pattern + "\").toPattern() => " + temppattern + " => pairs \""+ escape(getPairs(*tempset)) + "\", expected pairs \"" +
|
2000-08-14 21:42:36 +00:00
|
|
|
escape(getPairs(set)) + "\""));
|
|
|
|
} else{
|
2001-06-12 18:08:22 +00:00
|
|
|
logln(UnicodeString("Ok: applyPattern(\""+ pattern + "\").toPattern() => " + temppattern + " => pairs \"" + escape(getPairs(*tempset)) + "\""));
|
2000-08-14 21:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete tempset;
|
|
|
|
|
1999-10-20 22:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-10-26 17:16:13 +00:00
|
|
|
UnicodeSetTest::expectPairs(const UnicodeSet& set, const UnicodeString& expectedPairs) {
|
2000-05-25 19:28:53 +00:00
|
|
|
if (getPairs(set) != expectedPairs) {
|
1999-10-20 22:08:09 +00:00
|
|
|
errln(UnicodeString("FAIL: Expected pair list \"") +
|
|
|
|
escape(expectedPairs) + "\", got \"" +
|
2000-05-25 19:28:53 +00:00
|
|
|
escape(getPairs(set)) + "\"");
|
1999-10-20 22:08:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-26 06:28:15 +00:00
|
|
|
void UnicodeSetTest::expectToPattern(const UnicodeSet& set,
|
|
|
|
const UnicodeString& expPat,
|
2002-05-21 23:53:07 +00:00
|
|
|
const char** expStrings) {
|
2002-04-29 20:24:16 +00:00
|
|
|
UnicodeString pat;
|
|
|
|
set.toPattern(pat, TRUE);
|
2002-04-26 06:28:15 +00:00
|
|
|
if (pat == expPat) {
|
|
|
|
logln((UnicodeString)"Ok: toPattern() => \"" + pat + "\"");
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: toPattern() => \"" + pat + "\", expected \"" + expPat + "\"");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UBool in = TRUE;
|
|
|
|
for (int32_t i=0; expStrings[i] != NULL; ++i) {
|
|
|
|
if (expStrings[i] == NOT) { // sic; pointer comparison
|
|
|
|
in = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
UnicodeString s = CharsToUnicodeString(expStrings[i]);
|
|
|
|
UBool contained = set.contains(s);
|
|
|
|
if (contained == in) {
|
|
|
|
logln((UnicodeString)"Ok: " + expPat +
|
|
|
|
(contained ? " contains {" : " does not contain {") +
|
|
|
|
escape(expStrings[i]) + "}");
|
|
|
|
} else {
|
|
|
|
errln((UnicodeString)"FAIL: " + expPat +
|
|
|
|
(contained ? " contains {" : " does not contain {") +
|
|
|
|
escape(expStrings[i]) + "}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-10 00:28:31 +00:00
|
|
|
static UChar toHexString(int32_t i) { return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10))); }
|
1999-10-20 22:08:09 +00:00
|
|
|
|
2000-05-25 19:28:53 +00:00
|
|
|
void
|
|
|
|
UnicodeSetTest::doAssert(UBool condition, const char *message)
|
|
|
|
{
|
|
|
|
if (!condition) {
|
|
|
|
errln(UnicodeString("ERROR : ") + message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-20 22:08:09 +00:00
|
|
|
UnicodeString
|
|
|
|
UnicodeSetTest::escape(const UnicodeString& s) {
|
|
|
|
UnicodeString buf;
|
2003-02-17 23:31:10 +00:00
|
|
|
for (int32_t i=0; i<s.length(); )
|
1999-10-20 22:08:09 +00:00
|
|
|
{
|
2003-02-17 23:31:10 +00:00
|
|
|
UChar32 c = s.char32At(i);
|
2000-06-28 22:26:59 +00:00
|
|
|
if (0x0020 <= c && c <= 0x007F) {
|
1999-10-26 17:16:13 +00:00
|
|
|
buf += c;
|
|
|
|
} else {
|
2003-02-17 23:31:10 +00:00
|
|
|
if (c <= 0xFFFF) {
|
|
|
|
buf += (UChar)0x5c; buf += (UChar)0x75;
|
|
|
|
} else {
|
|
|
|
buf += (UChar)0x5c; buf += (UChar)0x55;
|
|
|
|
buf += toHexString((c & 0xF0000000) >> 28);
|
|
|
|
buf += toHexString((c & 0x0F000000) >> 24);
|
|
|
|
buf += toHexString((c & 0x00F00000) >> 20);
|
|
|
|
buf += toHexString((c & 0x000F0000) >> 16);
|
|
|
|
}
|
1999-10-20 22:08:09 +00:00
|
|
|
buf += toHexString((c & 0xF000) >> 12);
|
|
|
|
buf += toHexString((c & 0x0F00) >> 8);
|
|
|
|
buf += toHexString((c & 0x00F0) >> 4);
|
|
|
|
buf += toHexString(c & 0x000F);
|
|
|
|
}
|
2003-02-17 23:31:10 +00:00
|
|
|
i += U16_LENGTH(c);
|
1999-10-20 22:08:09 +00:00
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|