ICU-3515 tests for implicit CE generation and implicit tailoring
X-SVN-Rev: 14381
This commit is contained in:
parent
42c173f5a1
commit
ace5f3fc36
@ -135,36 +135,36 @@ public class CollationMiscTest extends TestFmwk{
|
||||
// have a code point associated to it anymore
|
||||
// "&[before 3][last primary ignorable]<<<k",
|
||||
// - all befores here amount to zero
|
||||
"&[before 1][first tertiary ignorable]<<<a",
|
||||
"&[before 1][last tertiary ignorable]<<<a",
|
||||
"&[before 1][first secondary ignorable]<<<a",
|
||||
"&[before 1][last secondary ignorable]<<<a",
|
||||
// 'normal' befores
|
||||
"&[before 1][first primary ignorable]<<<c<<<b &[first primary ignorable]<a",
|
||||
// we don't have a code point that corresponds to the last primary
|
||||
// ignorable
|
||||
"&[before 2][last primary ignorable]<<<c<<<b &[last primary ignorable]<a",
|
||||
"&[before 1][first variable]<<<c<<<b &[first variable]<a",
|
||||
"&[last variable]<a &[before 1][last variable]<<<c<<<b ",
|
||||
"&[first regular]<a &[before 1][first regular]<b",
|
||||
"&[before 1][last regular]<b &[last regular]<a",
|
||||
"&[before 1][first implicit]<b &[first implicit]<a",
|
||||
// "&[before 1][first tertiary ignorable]<<<a",
|
||||
// "&[before 1][last tertiary ignorable]<<<a",
|
||||
// "&[before 1][first secondary ignorable]<<<a",
|
||||
// "&[before 1][last secondary ignorable]<<<a",
|
||||
// // 'normal' befores
|
||||
// "&[before 1][first primary ignorable]<<<c<<<b &[first primary ignorable]<a",
|
||||
// // we don't have a code point that corresponds to the last primary
|
||||
// // ignorable
|
||||
// "&[before 2][last primary ignorable]<<<c<<<b &[last primary ignorable]<a",
|
||||
// "&[before 1][first variable]<<<c<<<b &[first variable]<a",
|
||||
// "&[last variable]<a &[before 1][last variable]<<<c<<<b ",
|
||||
// "&[first regular]<a &[before 1][first regular]<b",
|
||||
// "&[before 1][last regular]<b &[last regular]<a",
|
||||
// "&[before 1][first implicit]<b &[first implicit]<a",
|
||||
"&[before 1][last implicit]<b &[last implicit]<a",
|
||||
"&[last variable]<z&[last primary ignorable]<x&[last secondary ignorable]<<y&[last tertiary ignorable]<<<w&[top]<u",
|
||||
};
|
||||
String[][] data = {
|
||||
// {"k", "\u20e3"},
|
||||
{"\\u0000", "a"}, // you cannot go before first tertiary ignorable
|
||||
{"\\u0000", "a"}, // you cannot go before last tertiary ignorable
|
||||
{"\\u0000", "a"}, // you cannot go before first secondary ignorable
|
||||
{"\\u0000", "a"}, // you cannot go before first secondary ignorable
|
||||
{"c", "b", "\\u0332", "a"},
|
||||
{"\\u0332", "\\u20e3", "c", "b", "a"},
|
||||
{"c", "b", "\\u0009", "a", "\\u000a"},
|
||||
{"c", "b", "\\uD800\\uDD33", "a", "\\u02d0"},
|
||||
{"b", "\\u02d0", "a", "\\u02d1"},
|
||||
{"b", "\\ud800\\udf9d", "a", "\\u4e00"},
|
||||
{"b", "\\u4e00", "a", "\\u4e01"},
|
||||
// {"\\u0000", "a"}, // you cannot go before first tertiary ignorable
|
||||
// {"\\u0000", "a"}, // you cannot go before last tertiary ignorable
|
||||
// {"\\u0000", "a"}, // you cannot go before first secondary ignorable
|
||||
// {"\\u0000", "a"}, // you cannot go before first secondary ignorable
|
||||
// {"c", "b", "\\u0332", "a"},
|
||||
// {"\\u0332", "\\u20e3", "c", "b", "a"},
|
||||
// {"c", "b", "\\u0009", "a", "\\u000a"},
|
||||
// {"c", "b", "\\uD800\\uDD33", "a", "\\u02d0"},
|
||||
// {"b", "\\u02d0", "a", "\\u02d1"},
|
||||
// {"b", "\\ud800\\udf9d", "a", "\\u4e00"},
|
||||
// {"b", "\\u4e00", "a", "\\u4e01"},
|
||||
{"b", "\\U0010FFFC", "a"},
|
||||
{"\ufffb", "w", "y", "\u20e3", "x", "\u137c", "z", "u"},
|
||||
};
|
||||
@ -973,31 +973,24 @@ public class CollationMiscTest extends TestFmwk{
|
||||
}
|
||||
|
||||
public void TestImplicitTailoring() {
|
||||
String[] impTest = {
|
||||
"\u4e00",
|
||||
"a",
|
||||
"A",
|
||||
"b",
|
||||
"B",
|
||||
"\u4e01"
|
||||
};
|
||||
String rule = "&\u4e00 < a <<< A < b <<< B";
|
||||
RuleBasedCollator coll = null;
|
||||
try {
|
||||
coll = new RuleBasedCollator(rule);
|
||||
} catch (Exception e) {
|
||||
errln("Can't create collator");
|
||||
return;
|
||||
}
|
||||
|
||||
int size = impTest.length;
|
||||
for(int i = 0; i < size-1; i++) {
|
||||
for(int j = i+1; j < size; j++) {
|
||||
String t1 = impTest[i];
|
||||
String t2 = impTest[j];
|
||||
CollationTest.doTest(this, (RuleBasedCollator)coll, t1, t2, -1);
|
||||
}
|
||||
}
|
||||
String rules[] = { "&[before 1]\u4e00 < b < c &[before 1]\u4e00 < d < e",
|
||||
"&\u4e00 < a <<< A < b <<< B",
|
||||
"&[before 1]\u4e00 < \u4e01 < \u4e02",
|
||||
"&[before 1]\u4e01 < \u4e02 < \u4e03",
|
||||
};
|
||||
String cases[][] = {
|
||||
{ "d", "e", "b", "c", "\u4e00"},
|
||||
{ "\u4e00", "a", "A", "b", "B", "\u4e01"},
|
||||
{ "\u4e01", "\u4e02", "\u4e00"},
|
||||
{ "\u4e02", "\u4e03", "\u4e01"},
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(i = 0; i < rules.length; i++) {
|
||||
genericRulesStarter(rules[i], cases[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void TestFCDProblem() {
|
||||
@ -1929,4 +1922,113 @@ public class CollationMiscTest extends TestFmwk{
|
||||
String test[] = { "\u4E56\u4E56\u7761", "\u4E56\u5B69\u5B50" };
|
||||
genericLocaleStarter(new Locale("zh", "", "PINYIN"), test);
|
||||
}
|
||||
|
||||
static final long topByte = 0xFF000000L;
|
||||
static final long bottomByte = 0xFFL;
|
||||
static final long fourBytes = 0xFFFFFFFFL;
|
||||
|
||||
static final int MAX_INPUT = 0x220001; // 2 * Unicode range + 2
|
||||
|
||||
private void show(int i, ImplicitCEGenerator imp) {
|
||||
if (i >= 0 && i <= MAX_INPUT) {
|
||||
logln(Utility.hex(i) + "\t" + Utility.hex(imp.getImplicitFromRaw(i) & fourBytes));
|
||||
}
|
||||
}
|
||||
|
||||
private void throwError(String title, int cp, ImplicitCEGenerator imp) {
|
||||
throw new IllegalArgumentException(title + "\t" + Utility.hex(cp, 6) + "\t" + Utility.hex(imp.getImplicitFromRaw(cp) & fourBytes));
|
||||
}
|
||||
|
||||
private void throwError(String title, long ce) {
|
||||
errln(title + "\t" + Utility.hex(ce & fourBytes));
|
||||
}
|
||||
|
||||
public void TestImplicitGeneration()
|
||||
{
|
||||
logln("Start");
|
||||
try {
|
||||
ImplicitCEGenerator foo = new ImplicitCEGenerator(0xE0, 0xE4);
|
||||
|
||||
//int x = foo.getRawImplicit(0xF810);
|
||||
foo.getRawFromImplicit(0xE20303E7);
|
||||
|
||||
int gap4 = foo.getGap4();
|
||||
logln("Gap4: " + gap4);
|
||||
int gap3 = foo.getGap3();
|
||||
int minTrail = foo.getMinTrail();
|
||||
int maxTrail = foo.getMaxTrail();
|
||||
long last = 0;
|
||||
long current;
|
||||
for (int i = 0; i <= MAX_INPUT; ++i) {
|
||||
current = foo.getImplicitFromRaw(i) & fourBytes;
|
||||
|
||||
// check that it round-trips AND that all intervening ones are illegal
|
||||
int roundtrip = foo.getRawFromImplicit((int)current);
|
||||
if (roundtrip != i) {
|
||||
throwError("No roundtrip", i, foo);
|
||||
}
|
||||
if (last != 0) {
|
||||
for (long j = last + 1; j < current; ++j) {
|
||||
roundtrip = foo.getRawFromImplicit((int)j);
|
||||
// raise an error if it *doesn't* find an error
|
||||
if (roundtrip != -1) {
|
||||
throwError("Fails to recognize illegal", j);
|
||||
}
|
||||
}
|
||||
}
|
||||
// now do other consistency checks
|
||||
long lastBottom = last & bottomByte;
|
||||
long currentBottom = current & bottomByte;
|
||||
long lastTop = last & topByte;
|
||||
long currentTop = current & topByte;
|
||||
|
||||
// do some consistency checks
|
||||
/*
|
||||
long gap = current - last;
|
||||
if (currentBottom != 0) { // if we are a 4-byte
|
||||
// gap has to be at least gap4
|
||||
// and gap from minTrail, maxTrail has to be at least gap4
|
||||
if (gap <= gap4) foo.throwError("Failed gap4 between", i);
|
||||
if (currentBottom < minTrail + gap4) foo.throwError("Failed gap4 before", i);
|
||||
if (currentBottom > maxTrail - gap4) foo.throwError("Failed gap4 after", i);
|
||||
} else { // we are a three-byte
|
||||
gap = gap >> 8; // move gap down for comparison.
|
||||
long current3Bottom = (current >> 8) & bottomByte;
|
||||
if (gap <= gap3) foo.throwError("Failed gap3 between ", i);
|
||||
if (current3Bottom < minTrail + gap3) foo.throwError("Failed gap3 before", i);
|
||||
if (current3Bottom > maxTrail - gap3) foo.throwError("Failed gap3 after", i);
|
||||
}
|
||||
*/
|
||||
// print out some values for spot-checking
|
||||
if (lastTop != currentTop || i == 0x10000 || i == 0x110000) {
|
||||
show(i-3, foo);
|
||||
show(i-2, foo);
|
||||
show(i-1, foo);
|
||||
if (i == 0) {
|
||||
// do nothing
|
||||
} else if (lastBottom == 0 && currentBottom != 0) {
|
||||
logln("+ primary boundary, 4-byte CE's below");
|
||||
} else if (lastTop != currentTop) {
|
||||
logln("+ primary boundary");
|
||||
}
|
||||
show(i, foo);
|
||||
show(i+1, foo);
|
||||
show(i+2, foo);
|
||||
logln("...");
|
||||
}
|
||||
last = current;
|
||||
if(foo.getCodePointFromRaw(foo.getRawFromCodePoint(i)) != i) {
|
||||
errln("No raw <-> code point roundtrip for "+Utility.hex(i));
|
||||
}
|
||||
}
|
||||
show(MAX_INPUT-2, foo);
|
||||
show(MAX_INPUT-1, foo);
|
||||
show(MAX_INPUT, foo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
logln("End");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user