OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // TODO(srdjan): Move StringBuffer to visible names. | 7 // TODO(srdjan): Move StringBuffer to visible names. |
8 | 8 |
9 void testConstructor() { | 9 void testConstructor() { |
10 StringBuffer bf = new StringBuffer(""); | 10 StringBuffer bf = new StringBuffer(""); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 void testWriteAll() { | 89 void testWriteAll() { |
90 StringBuffer bf = new StringBuffer(""); | 90 StringBuffer bf = new StringBuffer(""); |
91 bf.writeAll(["foo", "bar", "a", "b", "c"]); | 91 bf.writeAll(["foo", "bar", "a", "b", "c"]); |
92 Expect.equals("foobarabc", bf.toString()); | 92 Expect.equals("foobarabc", bf.toString()); |
93 | 93 |
94 bf.writeAll([]); | 94 bf.writeAll([]); |
95 Expect.equals("foobarabc", bf.toString()); | 95 Expect.equals("foobarabc", bf.toString()); |
96 | 96 |
97 bf.writeAll(["", "", ""]); | 97 bf.writeAll(["", "", ""]); |
98 Expect.equals("foobarabc", bf.toString()); | 98 Expect.equals("foobarabc", bf.toString()); |
99 | |
100 bf.writeAll(["", "", ""], ""); | |
101 Expect.equals("foobarabc", bf.toString()); | |
102 | |
103 StringBuffer bf2 = new StringBuffer(""); | |
104 bf2.writeAll([], "s"); | |
105 Expect.equals("", bf2.toString()); | |
106 | |
107 StringBuffer bf3 = new StringBuffer(""); | |
108 bf3.writeAll(["a"], "s"); | |
109 Expect.equals("a", bf3.toString()); | |
110 | |
111 StringBuffer bf4 = new StringBuffer(""); | |
112 bf4.writeAll(["a", "b"], "s"); | |
113 Expect.equals("asb", bf4.toString()); | |
114 } | |
115 | |
116 void testWriteAll2() { | |
117 // Passing `null` for separator is an error that is checked when the iterable | |
118 // is not empty. This is not specified in the documentation but we want | |
119 // implementations to be consistent. | |
120 StringBuffer bf1 = new StringBuffer(""); | |
121 bf1.writeAll([], null); | |
122 Expect.equals("", bf1.toString()); | |
123 | |
124 StringBuffer bf2 = new StringBuffer(""); | |
125 Expect.throws(() { bf2.writeAll([1], null); }); | |
126 } | |
127 | |
128 void testWriteln() { | |
129 StringBuffer bf1 = new StringBuffer(""); | |
130 bf1.writeln("Hello"); | |
131 Expect.equals("Hello\n", bf1.toString()); | |
132 | |
133 StringBuffer bf2 = new StringBuffer(""); | |
134 bf2.writeln(); | |
135 Expect.equals("\n", bf2.toString()); | |
136 | |
137 StringBuffer bf3 = new StringBuffer(""); | |
138 bf3.writeln("\n"); | |
139 bf3.writeln(null); | |
140 bf3.writeln(1); | |
141 Expect.equals("\n\nnull\n1\n", bf3.toString()); | |
142 } | 99 } |
143 | 100 |
144 void testClear() { | 101 void testClear() { |
145 StringBuffer bf = new StringBuffer(""); | 102 StringBuffer bf = new StringBuffer(""); |
146 bf.write("foo"); | 103 bf.write("foo"); |
147 bf.clear(); | 104 bf.clear(); |
148 Expect.equals("", bf.toString()); | 105 Expect.equals("", bf.toString()); |
149 testBufferLength(0, bf); | 106 testBufferLength(0, bf); |
150 | 107 |
151 bf.write("bar"); | 108 bf.write("bar"); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 179 } |
223 | 180 |
224 void main() { | 181 void main() { |
225 testToString(); | 182 testToString(); |
226 testConstructor(); | 183 testConstructor(); |
227 testLength(); | 184 testLength(); |
228 testIsEmpty(); | 185 testIsEmpty(); |
229 testWrite(); | 186 testWrite(); |
230 testWriteCharCode(); | 187 testWriteCharCode(); |
231 testWriteAll(); | 188 testWriteAll(); |
232 testWriteAll2(); | |
233 testWriteln(); | |
234 testClear(); | 189 testClear(); |
235 testChaining(); | 190 testChaining(); |
236 } | 191 } |
OLD | NEW |