private void doMultipleSelectionTest(RuleBasedBreakIterator iterator, String testText) { logln("Multiple selection test..."); RuleBasedBreakIterator testIterator = (RuleBasedBreakIterator) iterator.clone(); int offset = iterator.first(); int testOffset; int count = 0; do { testOffset = testIterator.first(); testOffset = testIterator.next(count); logln("next(" + count + ") -> " + testOffset); if (offset != testOffset) errln( "next(n) and next() not returning consistent results: for step " + count + ", next(n) returned " + testOffset + " and next() had " + offset); if (offset != RuleBasedBreakIterator.DONE) { count++; offset = iterator.next(); } } while (offset != RuleBasedBreakIterator.DONE); // now do it backwards... offset = iterator.last(); count = 0; do { testOffset = testIterator.last(); testOffset = testIterator.next(count); logln("next(" + count + ") -> " + testOffset); if (offset != testOffset) errln( "next(n) and next() not returning consistent results: for step " + count + ", next(n) returned " + testOffset + " and next() had " + offset); if (offset != RuleBasedBreakIterator.DONE) { count--; offset = iterator.previous(); } } while (offset != RuleBasedBreakIterator.DONE); }
private List<String> _testLastAndPrevious(RuleBasedBreakIterator rbbi, String text) { int p = rbbi.last(); int lastP = p; List<String> result = new ArrayList<String>(); if (p != text.length()) { errln("last() returned " + p + " instead of " + text.length()); } while (p != RuleBasedBreakIterator.DONE) { p = rbbi.previous(); if (p != RuleBasedBreakIterator.DONE) { if (p >= lastP) { errln( "previous() failed to move backward: previous() on position " + lastP + " yielded " + p); } result.add(0, text.substring(p, lastP)); } else { if (lastP != 0) { errln("previous() returned DONE prematurely: offset was " + lastP + " instead of 0"); } } lastP = p; } return result; }
/* * Tests the method public int last() */ public void TestLast() { RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;"); // Tests when "if (fText == null)" is true rbbi.setText((CharacterIterator) null); if (rbbi.last() != BreakIterator.DONE) { errln( "RuleBasedBreakIterator.last() was suppose to return " + "BreakIterator.DONE when the object has a null fText."); } }