@Test
  public void list_clear() {
    CollectionBuilder cb = new CollectionBuilder().setPrintCount(true);

    cb.append("111\n222\n333");
    cb.append("444\n555\n");
    cb.append("666");

    buf.append("list ");
    buf.append(cb);

    result += "[\n";
    result += "  [1/3] 111\n";
    result += "        222\n";
    result += "        333\n";
    result += "  [2/3] 444\n";
    result += "        555\n";
    result += "  [3/3] 666\n";
    result += "]";

    assertEquals("list " + result, buf.toString());
    assertEquals(result, cb.toString());

    cb.clear();
    buf.clear();

    assertEquals("[]", cb.toString());
    assertEquals("", buf.toString());
  }
  @Test
  public void map_clear() {
    MapBuilder mb = new MapBuilder().setSortKeys(true).setPrintCount(true);

    mb.append("dddd", "111\n222\n333");
    mb.append("ccc", "444\n555\n");
    mb.append("a", "666");

    buf.append("map ");
    buf.append(mb);

    result += "{\n";
    result += "  [1/3] a    = 666\n";
    result += "  [2/3] ccc  = 444\n";
    result += "               555\n";
    result += "  [3/3] dddd = 111\n";
    result += "               222\n";
    result += "               333\n";
    result += "}";

    assertEquals("map " + result, buf.toString());
    assertEquals(result, mb.toString());

    mb.clear();
    buf.clear();

    assertEquals("{}", mb.toString());
    assertEquals("", buf.toString());
  }
  @Test
  public void objects() {
    buf.append("aaa\rbbb\r\nccc");
    assertEquals("aaa\nbbb\nccc", buf.toString());

    buf.append("ddd\n\reee\n");
    assertEquals("aaa\nbbb\ncccddd\n\neee\n", buf.toString());
  }
  @Test
  public void list_noCount() {
    CollectionBuilder cb = new CollectionBuilder();

    cb.append("111\n222\n333");
    cb.append("444\n555\n");
    cb.append("666");

    buf.append("list ");
    buf.append(cb);

    result += "[\n";
    result += "  111\n";
    result += "    222\n";
    result += "    333\n";
    result += "  444\n";
    result += "    555\n";
    result += "  666\n";
    result += "]";

    assertEquals(result, cb.toString());
    assertEquals("list " + result, buf.toString());
  }
  @Test
  public void list_oneline() {
    CollectionBuilder cb = new CollectionBuilder().setOneLine(true);

    cb.append("111");
    cb.append("444");
    cb.append("666");

    buf.append(cb);

    result += "[111, 444, 666]";

    assertEquals(result, cb.toString());
  }
  @Test
  public void primitiveArrays_multilines_no_desc() {
    Object[] values = getPrimitiveArrayData(18);

    buf.append(values);

    result += "[\n";
    result += "  [1/9] [\n";
    result += "          [01-10/18] true  false true  false true  false true  false true  false\n";
    result += "          [11-18/18] true  false true  false true  false true  false\n";
    result += "        ]\n";
    result += "  [2/9] [\n";
    result += "          [01-10/18] 00 01 02 03 04 05 06 07 08 09\n";
    result += "          [11-18/18] 0a 0b 0c 0d 0e 0f 10 11\n";
    result += "        ]\n";
    result += "  [3/9] [\n";
    result += "          [01-10/18] 0 1 2 3 4 5 6 7 8 9\n";
    result += "          [11-18/18] : ; < = > ? @ A\n";
    result += "        ]\n";
    result += "  [4/9] [\n";
    result += "          [01-10/18] 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0\n";
    result += "          [11-18/18] 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0\n";
    result += "        ]\n";
    result += "  [5/9] [\n";
    result += "          [01-10/18] 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0\n";
    result += "          [11-18/18] 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0\n";
    result += "        ]\n";
    result += "  [6/9] [\n";
    result += "          [01-10/18] 0 1 2 3 4 5 6 7 8 9\n";
    result += "          [11-18/18] 10 11 12 13 14 15 16 17\n";
    result += "        ]\n";
    result += "  [7/9] [\n";
    result += "          [01-10/18] 0 1 2 3 4 5 6 7 8 9\n";
    result += "          [11-18/18] 10 11 12 13 14 15 16 17\n";
    result += "        ]\n";
    result += "  [8/9] [\n";
    result += "          [01-10/18] 0 1 2 3 4 5 6 7 8 9\n";
    result += "          [11-18/18] 10 11 12 13 14 15 16 17\n";
    result += "        ]\n";
    result += "  [9/9] aaa\n";
    result += "        bbb\n";
    result += "        ccc\n";
    result += "]";

    assertEquals(result, buf.toString());
  }
  @Test
  public void map_noCount() {
    MapBuilder mb = new MapBuilder().setSortKeys(true).setPrintCount(false);

    mb.append("dddd", "111\n222\n333");
    mb.append("ccc", "444\n555\n");
    mb.append("a", "666");

    buf.append(mb);

    result += "{\n";
    result += "  a    = 666\n";
    result += "  ccc  = 444\n";
    result += "         555\n";
    result += "  dddd = 111\n";
    result += "         222\n";
    result += "         333\n";
    result += "}";

    assertEquals(result, mb.toString());
  }
  @Test
  public void primitiveArrays_oneline_no_desc() {
    Object[] values = getPrimitiveArrayData(8);

    buf.append(values);

    result += "[\n";
    result += "  [1/9] [true, false, true, false, true, false, true, false]\n";
    result += "  [2/9] [0, 1, 2, 3, 4, 5, 6, 7]\n";
    result += "  [3/9] [0, 1, 2, 3, 4, 5, 6, 7]\n";
    result += "  [4/9] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]\n";
    result += "  [5/9] [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]\n";
    result += "  [6/9] [0, 1, 2, 3, 4, 5, 6, 7]\n";
    result += "  [7/9] [0, 1, 2, 3, 4, 5, 6, 7]\n";
    result += "  [8/9] [0, 1, 2, 3, 4, 5, 6, 7]\n";
    result += "  [9/9] aaa\n";
    result += "        bbb\n";
    result += "        ccc\n";
    result += "]";

    assertEquals(result, buf.toString());
  }
  @Test
  public void primitives() {
    buf.append(true).append("\n");
    buf.append((byte) 123).append("\n");
    buf.append('c').append("\n");
    buf.append(123.456D).append("\n");
    buf.append(123.456F).append("\n");
    buf.append(123).append("\n");
    buf.append(123456L).append("\n");
    buf.append((short) 123).append("\n");

    result += "true\n";
    result += "123\n";
    result += "c\n";
    result += "123.456\n";
    result += "123.456\n";
    result += "123\n";
    result += "123456\n";
    result += "123\n";

    assertEquals(result, buf.toString());
  }
 @Test
 public void _null() {
   buf.append(null);
   assertEquals("<null>", buf.toString());
 }