Esempio n. 1
0
  /*
   * Tests the method public int preceding(int offset)
   */
  public void TestPreceding() {
    RuleBasedBreakIterator rbbi = new RuleBasedBreakIterator(".;");
    // Tests when "if (fText == null || offset > fText.getEndIndex())" is true
    rbbi.setText((CharacterIterator) null);
    if (rbbi.preceding(-1) != BreakIterator.DONE) {
      errln(
          "RuleBasedBreakIterator.preceding(-1) was suppose to return "
              + "0 when the object has a fText of null.");
    }

    // Tests when "else if (offset < fText.getBeginIndex())" is true
    rbbi.setText("dummy");
    if (rbbi.preceding(-1) != 0) {
      errln(
          "RuleBasedBreakIterator.preceding(-1) was suppose to return "
              + "0 when the object has a fText of dummy.");
    }
  }
Esempio n. 2
0
 private void _testPreceding(RuleBasedBreakIterator rbbi, String text, int[] boundaries) {
   logln("testPreceding():");
   int p = 0;
   for (int i = 0; i <= text.length(); i++) {
     int b = rbbi.preceding(i);
     logln("rbbi.preceding(" + i + ") -> " + b);
     if (b != boundaries[p])
       errln(
           "Wrong result from preceding() for "
               + i
               + ": expected "
               + boundaries[p]
               + ", got "
               + b);
     if (i == boundaries[p + 1]) ++p;
   }
 }