publicclass IteratorTest extends CollatorTest { // TODO: // - Test previous() with contracting character sequences, which don't work // at the moment. // - Test edge cases on setOffset(), e.g. offset > length, etc. // publicstaticvoid main(String[] args) throws Exception { new IteratorTest().run(args);
}
/** *TestforCollationElementIterator.previous() * *@bug4108758-Makesureitworkswithcontractingcharacters *
*/ publicvoid TestPrevious() throws ParseException { // A basic test to see if it's working at all
backAndForth(en_us.getCollationElementIterator(test1));
// Test with a contracting character sequence
RuleBasedCollator c1 = new RuleBasedCollator( "< a,A < b,B < c,C, d,D < z,Z < ch,cH,Ch,CH" );
// Run through the second iterator just to exercise it int c = iter2.next(); int i = 0; while ( ++i < 10 && c != CollationElementIterator.NULLORDER) {
c = iter2.next();
}
// Now set it to point to the same string as the first iterator
iter2.setText(test1);
assertEqual(iter1, iter2);
}
/** @bug 4108762 *TestforgetMaxExpansion()
*/ publicvoid TestMaxExpansion() throws ParseException { // Try a simple one first: // The only expansion ends with 'e' and has length 2
String[][] test1 = {
{ "< a & ae = \u00e4 < b < e", "" },
{ "a", "1" },
{ "b", "1" },
{ "e", "2" },
};
verifyExpansion(test1);
// Now a more complicated one: // "a1" --> "ae" // "z" --> "aeef" //
String[][] test2 = {
{ "< a & ae = a1 & aeef = z < b < e < f", "" },
{ "a", "1" },
{ "b", "1" },
{ "e", "2" },
{ "f", "4" },
};
verifyExpansion(test2);
}
/* *@bug4157299
*/ publicvoid TestClearBuffers() throws ParseException {
RuleBasedCollator c = new RuleBasedCollator("< a < b < c & ab = d");
CollationElementIterator i = c.getCollationElementIterator("abcd"); int e0 = i.next(); // save the first collation element
i.setOffset(3); // go to the expanding character
i.next(); // but only use up half of it
i.setOffset(0); // go back to the beginning int e = i.next(); // and get this one again if (e != e0) {
errln("got " + Integer.toString(e, 16) + ", expected " +
Integer.toString(e0, 16));
}
}
privatevoid backAndForth(CollationElementIterator iter) { // Run through the iterator forwards and stick it into an array int [] orders = getOrders(iter);
// Now go through it backwards and make sure we get the same values int index = orders.length; int o;
while ((o = iter.previous()) != CollationElementIterator.NULLORDER) { if (o != orders[--index]) {
errln("Mismatch at index " + index + ": "
+ orders[index] + " vs " + o); break;
}
} if (index != 0) {
errln("Didn't get back to beginning - index is " + index);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.