Ejemplo n.º 1
0
  /** @throws Exception */
  public static void testCutString() throws Exception {
    String src, res, actual;

    src = Locale.getString("A_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("A_RESULT"); // $NON-NLS-1$
    actual = TextUtil.cutString(src, 80);
    assertNotNull(actual);
    assertEquals("A:", res, actual); // $NON-NLS-1$

    src = Locale.getString("B_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("B_RESULT"); // $NON-NLS-1$
    actual = TextUtil.cutString(src, 80);
    assertNotNull(actual);
    assertEquals("B:", res, actual); // $NON-NLS-1$

    src = Locale.getString("C_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("C_RESULT"); // $NON-NLS-1$
    actual = TextUtil.cutString(src, 80);
    assertNotNull(actual);
    assertEquals("C:", res, actual); // $NON-NLS-1$

    src = Locale.getString("D_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("D_RESULT"); // $NON-NLS-1$
    actual = TextUtil.cutString(src, 80);
    assertNotNull(actual);
    assertEquals("D:", res, actual); // $NON-NLS-1$
  }
Ejemplo n.º 2
0
  public static void testToHTML() {
    String source, expected, actual;

    source = Locale.getString("JAVA_HTML_SOURCE"); // $NON-NLS-1$
    expected = Locale.getString("JAVA_HTML_EXPECTED"); // $NON-NLS-1$

    assertNull(TextUtil.toHTML(null));

    actual = TextUtil.toHTML(source);
    assertEquals(expected, actual);
  }
Ejemplo n.º 3
0
  /** @throws Exception */
  public static void testCutStringAsArray() throws Exception {
    String src;
    String[] res;
    String[] actual;

    src = Locale.getString("A_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("A_RESULT").split("\n"); // $NON-NLS-1$ //$NON-NLS-2$
    actual = TextUtil.cutStringAsArray(src, 80);
    assertNotNull(actual);
    assertEquals(res.length, actual.length);
    for (int i = 0; i < res.length; i++) {
      assertTrue(
          "A:Line Size " + (i + 1) + ": " + actual[i] + " = " + actual[i].length(),
          actual[i].length() <= 80); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      assertEquals("A:Line " + (i + 1), res[i], actual[i]); // $NON-NLS-1$
    }

    src = Locale.getString("B_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("B_RESULT").split("\n"); // $NON-NLS-1$ //$NON-NLS-2$
    actual = TextUtil.cutStringAsArray(src, 80);
    assertNotNull(actual);
    assertEquals(res.length, actual.length);
    for (int i = 0; i < res.length; i++) {
      assertTrue(
          "B:Line Size " + (i + 1) + ": " + actual[i] + " = " + actual[i].length(),
          actual[i].length() <= 80); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      assertEquals("B:Line " + (i + 1), res[i], actual[i]); // $NON-NLS-1$
    }

    src = Locale.getString("C_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("C_RESULT").split("\n"); // $NON-NLS-1$ //$NON-NLS-2$
    actual = TextUtil.cutStringAsArray(src, 80);
    assertNotNull(actual);
    assertEquals(res.length, actual.length);
    for (int i = 0; i < res.length; i++) {
      assertTrue(
          "C:Line Size " + (i + 1) + ": " + actual[i] + " = " + actual[i].length(),
          actual[i].length() <= 80); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      assertEquals("C:Line " + (i + 1), res[i], actual[i]); // $NON-NLS-1$
    }

    src = Locale.getString("D_SOURCE"); // $NON-NLS-1$
    res = Locale.getString("D_RESULT").split("\n"); // $NON-NLS-1$ //$NON-NLS-2$
    actual = TextUtil.cutStringAsArray(src, 80);
    assertNotNull(actual);
    assertEquals(res.length, actual.length);
    for (int i = 0; i < res.length; i++) {
      assertTrue(
          "D:Line Size " + (i + 1) + ": " + actual[i] + " = " + actual[i].length(),
          actual[i].length() <= 80); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      assertEquals("D:Line " + (i + 1), res[i], actual[i]); // $NON-NLS-1$
    }
  }
Ejemplo n.º 4
0
  /** @throws Exception */
  public static void testSplitAsListCharCharStr() throws Exception {
    List<String> tab;

    tab = TextUtil.splitAsList('|', '=', "|a=|b=|c=|d="); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "a", //$NON-NLS-1$
          "b", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.splitAsList('|', '=', "start |a=bbb |b eee=|c=|d=zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b eee", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.splitAsList('|', '=', "start |a=bbb |b |eee==|c=|d=zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b |eee=", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.splitAsList('|', '=', "start |a=bbb |b |e|e|e=f===|c=|d=zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b |e|e|e=f==", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.splitAsList('|', '=', "start |a=bbb |b |e|e|e=f===|=|d=zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b |e|e|e=f==", //$NON-NLS-1$
          "", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);
  }
Ejemplo n.º 5
0
  /** @throws Exception */
  public static void testSplitBracketsAsList() throws Exception {
    List<String> tab;

    tab = TextUtil.splitBracketsAsList("{a}{b}{c}{d}"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "a", //$NON-NLS-1$
          "b", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.splitBracketsAsList("start {a}bbb {b eee}{c}{d}zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b eee", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.splitBracketsAsList("start {a}bbb {b {eee}}{c}{d}zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b {eee}", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.splitBracketsAsList("start {a}bbb {b {e{e{e}f}}}{c}{d}zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b {e{e{e}f}}", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.splitBracketsAsList("start {a}bbb {b {e{e{e}f}}}{}{d}zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b {e{e{e}f}}", //$NON-NLS-1$
          "", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);
  }
Ejemplo n.º 6
0
  /** @throws Exception */
  public static void testSplitCharCharStr() throws Exception {
    String[] tab;

    tab = TextUtil.split('(', ']', "(a](b](c](d]"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "a", //$NON-NLS-1$
          "b", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.split('(', ']', "start (a]bbb (b eee](c](d]zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b eee", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.split('(', ']', "start (a]bbb (b (eee]](c](d]zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b (eee]", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.split('(', ']', "start (a]bbb (b (e(e(e]f]]](c](d]zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b (e(e(e]f]]", //$NON-NLS-1$
          "c", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);

    tab = TextUtil.split('(', ']', "start (a]bbb (b (e(e(e]f]]](](d]zzz end"); // $NON-NLS-1$
    assertEquals(
        new String[] {
          "start", //$NON-NLS-1$
          "a", //$NON-NLS-1$
          "bbb", //$NON-NLS-1$
          "b (e(e(e]f]]", //$NON-NLS-1$
          "", //$NON-NLS-1$
          "d", //$NON-NLS-1$
          "zzz end", //$NON-NLS-1$
        },
        tab);
  }