| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // TODO(srdjan): Move StringBuffer to visible names. | |
| 6 | |
| 7 class StringBufferTest { | |
| 8 static testConstructor() { | |
| 9 StringBuffer bf = new StringBuffer(""); | |
| 10 Expect.equals(true, bf.isEmpty()); | |
| 11 | |
| 12 bf = new StringBuffer("abc"); | |
| 13 Expect.equals(3, bf.length); | |
| 14 Expect.equals("abc", bf.toString()); | |
| 15 } | |
| 16 | |
| 17 static testAdd() { | |
| 18 StringBuffer bf = new StringBuffer(""); | |
| 19 Expect.equals(true, bf.isEmpty()); | |
| 20 | |
| 21 bf.add("a"); | |
| 22 Expect.equals(1, bf.length); | |
| 23 Expect.equals("a", bf.toString()); | |
| 24 | |
| 25 bf = new StringBuffer(""); | |
| 26 bf.add("a"); | |
| 27 bf.add("b"); | |
| 28 Expect.equals("ab", bf.toString()); | |
| 29 | |
| 30 bf = new StringBuffer("abc"); | |
| 31 bf.add("d"); | |
| 32 bf.add("e"); | |
| 33 bf.add("f"); | |
| 34 bf.add("g"); | |
| 35 bf.add("h"); | |
| 36 bf.add("i"); | |
| 37 bf.add("j"); | |
| 38 bf.add("k"); | |
| 39 bf.add("l"); | |
| 40 bf.add("m"); | |
| 41 bf.add("n"); | |
| 42 bf.add("o"); | |
| 43 bf.add("p"); | |
| 44 bf.add("q"); | |
| 45 bf.add("r"); | |
| 46 bf.add("s"); | |
| 47 bf.add("t"); | |
| 48 bf.add("u"); | |
| 49 bf.add("v"); | |
| 50 bf.add("w"); | |
| 51 bf.add("x"); | |
| 52 bf.add("y"); | |
| 53 bf.add("z"); | |
| 54 bf.add("\n"); | |
| 55 bf.add("thequickbrownfoxjumpsoverthelazydog"); | |
| 56 Expect.equals("abcdefghijklmnopqrstuvwxyz\n" + | |
| 57 "thequickbrownfoxjumpsoverthelazydog", | |
| 58 bf.toString()); | |
| 59 | |
| 60 bf = new StringBuffer(""); | |
| 61 for (int i = 0; i < 100000; i++) { | |
| 62 bf.add(''); | |
| 63 bf.add(""); | |
| 64 } | |
| 65 Expect.equals("", bf.toString()); | |
| 66 | |
| 67 Expect.equals(bf, bf.add("foo")); | |
| 68 } | |
| 69 | |
| 70 static testLength() { | |
| 71 StringBuffer bf = new StringBuffer(""); | |
| 72 Expect.equals(0, bf.length); | |
| 73 bf.add("foo"); | |
| 74 Expect.equals(3, bf.length); | |
| 75 bf.add("bar"); | |
| 76 Expect.equals(6, bf.length); | |
| 77 bf.add(""); | |
| 78 Expect.equals(6, bf.length); | |
| 79 } | |
| 80 | |
| 81 static testIsEmpty() { | |
| 82 StringBuffer bf = new StringBuffer(""); | |
| 83 Expect.equals(true, bf.isEmpty()); | |
| 84 bf.add("foo"); | |
| 85 Expect.equals(false, bf.isEmpty()); | |
| 86 } | |
| 87 | |
| 88 static testAddAll() { | |
| 89 StringBuffer bf = new StringBuffer(""); | |
| 90 bf.addAll(["foo", "bar", "a", "b", "c"]); | |
| 91 Expect.equals("foobarabc", bf.toString()); | |
| 92 | |
| 93 bf.addAll([]); | |
| 94 Expect.equals("foobarabc", bf.toString()); | |
| 95 | |
| 96 bf.addAll(["", "", ""]); | |
| 97 Expect.equals("foobarabc", bf.toString()); | |
| 98 | |
| 99 Expect.equals(bf, bf.addAll(["foo"])); | |
| 100 } | |
| 101 | |
| 102 static testClear() { | |
| 103 StringBuffer bf = new StringBuffer(""); | |
| 104 bf.add("foo"); | |
| 105 bf.clear(); | |
| 106 Expect.equals("", bf.toString()); | |
| 107 Expect.equals(0, bf.length); | |
| 108 | |
| 109 bf.add("bar"); | |
| 110 Expect.equals("bar", bf.toString()); | |
| 111 Expect.equals(3, bf.length); | |
| 112 bf.clear(); | |
| 113 Expect.equals("", bf.toString()); | |
| 114 Expect.equals(0, bf.length); | |
| 115 | |
| 116 Expect.equals(bf, bf.clear()); | |
| 117 } | |
| 118 | |
| 119 static testToString() { | |
| 120 StringBuffer bf = new StringBuffer(""); | |
| 121 Expect.equals("", bf.toString()); | |
| 122 | |
| 123 bf = new StringBuffer("foo"); | |
| 124 Expect.equals("foo", bf.toString()); | |
| 125 | |
| 126 bf = new StringBuffer("foo"); | |
| 127 bf.add("bar"); | |
| 128 Expect.equals("foobar", bf.toString()); | |
| 129 } | |
| 130 | |
| 131 static testChaining() { | |
| 132 StringBuffer bf = new StringBuffer(""); | |
| 133 StringBuffer bf2 = new StringBuffer(""); | |
| 134 bf2.add("bf2"); | |
| 135 bf.add("foo") | |
| 136 .add("bar") | |
| 137 .add(bf2) | |
| 138 .add(bf2) | |
| 139 .add("toto"); | |
| 140 Expect.equals("foobarbf2bf2toto", bf.toString()); | |
| 141 } | |
| 142 | |
| 143 static testMain() { | |
| 144 testToString(); | |
| 145 testConstructor(); | |
| 146 testLength(); | |
| 147 testIsEmpty(); | |
| 148 testAdd(); | |
| 149 testAddAll(); | |
| 150 testClear(); | |
| 151 testChaining(); | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 main() { | |
| 156 StringBufferTest.testMain(); | |
| 157 } | |
| OLD | NEW |