// A special test for RegexpSplitter with a re matching the empty
 // string
 public void test_REsplitterEmptyRE() throws Exception {
   TextSplitter sp = new RegexpSplitter("[@]", RegexpSplitter.SPLIT);
   Formatter fmt = new PrintfFormatter("[%(1,0,][)]");
   StringBuffer b = new StringBuffer("abc@def@123");
   TextStore ts = new TextStore();
   sp.split(ts, b, 0);
   b.setLength(0);
   fmt.format(b, ts, null);
   // System.out.println("++"+b);
   // System.out.println(">>"+ts);
   assertEquals("[abc][def][123]", b.toString());
 }
 // depending on the object in 'client' the strings in 'tests' should
 // probably be changed!! (Needs some thought if additional Splitters
 // are implemented.
 public void testGeneric1() {
   for (int i = 0; i < tests.length; i++) {
     store.clear();
     client.split(store, new StringBuffer(tests[i][0]), 0);
     assertEquals(tests[i].length, store.getNumParts());
     StringBuffer sb = new StringBuffer();
     store.getPart(sb, 0);
     assertEquals(tests[i][0], sb.toString());
     for (int j = 1; j < tests[i].length; j++) {
       sb.setLength(0);
       store.getPart(sb, j);
       assertEquals("loop with j=" + j, tests[i][j], sb.toString());
     }
   }
 }
  public void testSubstring() {
    client.split(store, new StringBuffer(testAIn), 3);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 2; i++) {
      int L = testAOut[i].length();

      sb.setLength(0);
      store.getPart(sb, i);
      assertEquals("i=" + i, testAOut[i], sb.toString());
      assertEquals("i=" + i, testAOut[i].length(), store.getPartLen(i));

      sb.setLength(0);
      store.getPart(sb, i, 1, -1);
      assertEquals("i=" + i, testAOut[i].substring(1, L - 1), sb.toString());

      sb.setLength(0);
      store.getPart(sb, i, -3, 0);
      assertEquals(testAOut[i].substring(L - 3, L), sb.toString());

      sb.setLength(0);
      store.getPart(sb, i, 2, 2);
      assertEquals("", sb.toString());

      sb.setLength(0);
      store.getPart(sb, i, 2, 3);
      assertEquals(testAOut[i].substring(2, 3), sb.toString());

      // test left index too small
      sb.setLength(0);
      store.getPart(sb, i, -100, 0);
      assertEquals(testAOut[i], sb.toString());
      //       Exception e = null;
      //       try {
      // 	store.getPart(sb, i, -100, 0);
      // 	System.out.println("*************"+sb);
      //       } catch( Exception _e) {
      // 	e = _e;
      //       }
      //       assertTrue(e instanceof StringIndexOutOfBoundsException);

      // test left index much too large
      sb.setLength(0);
      store.getPart(sb, i, 10000, 0);
      assertEquals("", sb.toString());
      //       e = null;
      //       try {
      // 	store.getPart(sb, i, 10000, 0);
      //       } catch( Exception _e) {
      // 	e = _e;
      //       }
      //       assertTrue(e instanceof StringIndexOutOfBoundsException);

      // test right index too small
      sb.setLength(0);
      store.getPart(sb, i, 0, -10000);
      assertEquals("", sb.toString());
      //       e = null;
      //       try {
      // 	store.getPart(sb, i, 0, -10000);
      //       } catch( Exception _e) {
      // 	e = _e;
      //       }
      //       assertTrue(e instanceof StringIndexOutOfBoundsException);

      // test right index far too large
      sb.setLength(0);
      store.getPart(sb, i, 0, 10000);
      assertEquals(testAOut[i], sb.toString());
      //       e = null;
      //       try {
      // 	store.getPart(sb, i, 0, 10000);
      //       } catch( Exception _e) {
      // 	e = _e;
      //       }
      //       assertTrue(e instanceof StringIndexOutOfBoundsException);

      // out of range part should return empty string
      sb.setLength(0);
      store.getPart(sb, 299, 0, 10000);
      assertEquals("", sb.toString());
      //       e = null;
      //       try {
      // 	store.getPart(sb, 1000, 0, 1);
      //       } catch( Exception _e) {
      // 	e = _e;
      //       }
      //       assertTrue(e instanceof ArrayIndexOutOfBoundsException);

      // yet another one, this time in getPartLen
      assertEquals(0, store.getPartLen(1000));
      //       e = null;
      //       try {
      // 	store.getPartLen(1000);
      //       } catch( Exception _e) {
      // 	e = _e;
      //       }
      //       assertTrue(e instanceof ArrayIndexOutOfBoundsException);

    }
  }
Пример #4
0
 @Test
 public void testColorLC() {
   String text = "#fff";
   correctListToCheck(TextSplitter.getInstance(), text);
 }