Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: tests/standalone/io/string_stream_test.dart

Issue 12282038: Remove deprecated string features. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "dart:io"; 5 import "dart:io";
6 import "dart:isolate"; 6 import "dart:isolate";
7 7
8 void testUtf8() { 8 void testUtf8() {
9 List<int> data = [0x01, 9 List<int> data = [0x01,
10 0x7f, 10 0x7f,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 } 98 }
99 99
100 void streamClosed() { 100 void streamClosed() {
101 Expect.equals(true, stream.closed); 101 Expect.equals(true, stream.closed);
102 Expect.equals(2, stage); 102 Expect.equals(2, stage);
103 } 103 }
104 104
105 stream.onData = stringData; 105 stream.onData = stringData;
106 stream.onClosed = streamClosed; 106 stream.onClosed = streamClosed;
107 s.write("Line".charCodes); 107 s.write("Line".codeUnits);
108 } 108 }
109 109
110 void testReadLine2() { 110 void testReadLine2() {
111 ListInputStream s = new ListInputStream(); 111 ListInputStream s = new ListInputStream();
112 StringInputStream stream = new StringInputStream(s); 112 StringInputStream stream = new StringInputStream(s);
113 var stage = 0; 113 var stage = 0;
114 114
115 void stringData() { 115 void stringData() {
116 var line; 116 var line;
117 if (stage == 0) { 117 if (stage == 0) {
118 Expect.equals(21, stream.available()); 118 Expect.equals(21, stream.available());
119 line = stream.readLine(); 119 line = stream.readLine();
120 Expect.equals("Line1", line); 120 Expect.equals("Line1", line);
121 Expect.equals(15, stream.available()); 121 Expect.equals(15, stream.available());
122 line = stream.readLine(); 122 line = stream.readLine();
123 Expect.equals("Line2", line); 123 Expect.equals("Line2", line);
124 Expect.equals(8, stream.available()); 124 Expect.equals(8, stream.available());
125 line = stream.readLine(); 125 line = stream.readLine();
126 Expect.equals("Line3", line); 126 Expect.equals("Line3", line);
127 line = stream.readLine(); 127 line = stream.readLine();
128 Expect.equals(2, stream.available()); 128 Expect.equals(2, stream.available());
129 Expect.equals(null, line); 129 Expect.equals(null, line);
130 stage++; 130 stage++;
131 s.write("ne4\n".charCodes); 131 s.write("ne4\n".codeUnits);
132 } else if (stage == 1) { 132 } else if (stage == 1) {
133 Expect.equals(6, stream.available()); 133 Expect.equals(6, stream.available());
134 line = stream.readLine(); 134 line = stream.readLine();
135 Expect.equals("Line4", line); 135 Expect.equals("Line4", line);
136 Expect.equals(0, stream.available()); 136 Expect.equals(0, stream.available());
137 line = stream.readLine(); 137 line = stream.readLine();
138 Expect.equals(null, line); 138 Expect.equals(null, line);
139 stage++; 139 stage++;
140 s.write("\n\n\r\n\r\n\r\r".charCodes); 140 s.write("\n\n\r\n\r\n\r\r".codeUnits);
141 } else if (stage == 2) { 141 } else if (stage == 2) {
142 // Expect 5 empty lines. As long as the stream is not closed the 142 // Expect 5 empty lines. As long as the stream is not closed the
143 // final \r cannot be interpreted as a end of line. 143 // final \r cannot be interpreted as a end of line.
144 Expect.equals(8, stream.available()); 144 Expect.equals(8, stream.available());
145 for (int i = 0; i < 5; i++) { 145 for (int i = 0; i < 5; i++) {
146 line = stream.readLine(); 146 line = stream.readLine();
147 Expect.equals("", line); 147 Expect.equals("", line);
148 } 148 }
149 Expect.equals(1, stream.available()); 149 Expect.equals(1, stream.available());
150 line = stream.readLine(); 150 line = stream.readLine();
(...skipping 11 matching lines...) Expand all
162 } 162 }
163 } 163 }
164 164
165 void streamClosed() { 165 void streamClosed() {
166 Expect.equals(4, stage); 166 Expect.equals(4, stage);
167 Expect.equals(true, stream.closed); 167 Expect.equals(true, stream.closed);
168 } 168 }
169 169
170 stream.onLine = stringData; 170 stream.onLine = stringData;
171 stream.onClosed = streamClosed; 171 stream.onClosed = streamClosed;
172 s.write("Line1\nLine2\r\nLine3\rLi".charCodes); 172 s.write("Line1\nLine2\r\nLine3\rLi".codeUnits);
173 } 173 }
174 174
175 void testReadChunks() { 175 void testReadChunks() {
176 ListInputStream s = new ListInputStream(); 176 ListInputStream s = new ListInputStream();
177 StringInputStream stream = new StringInputStream(s); 177 StringInputStream stream = new StringInputStream(s);
178 178
179 void stringData() { 179 void stringData() {
180 var data; 180 var data;
181 Expect.equals(8, stream.available()); 181 Expect.equals(8, stream.available());
182 data = stream.read(1); 182 data = stream.read(1);
(...skipping 15 matching lines...) Expand all
198 Expect.equals(null, data); 198 Expect.equals(null, data);
199 Expect.equals(0, stream.available()); 199 Expect.equals(0, stream.available());
200 data = stream.read(3); 200 data = stream.read(3);
201 Expect.equals(null, data); 201 Expect.equals(null, data);
202 Expect.equals(0, stream.available()); 202 Expect.equals(0, stream.available());
203 data = stream.read(); 203 data = stream.read();
204 Expect.equals(null, data); 204 Expect.equals(null, data);
205 Expect.equals(0, stream.available()); 205 Expect.equals(0, stream.available());
206 } 206 }
207 207
208 s.write("ABCD1234".charCodes); 208 s.write("ABCD1234".codeUnits);
209 stream.onData = stringData; 209 stream.onData = stringData;
210 } 210 }
211 211
212 void testReadMixed() { 212 void testReadMixed() {
213 ListInputStream s = new ListInputStream(); 213 ListInputStream s = new ListInputStream();
214 StringInputStream stream = new StringInputStream(s); 214 StringInputStream stream = new StringInputStream(s);
215 var stage = 0; 215 var stage = 0;
216 216
217 void stringData() { 217 void stringData() {
218 var data; 218 var data;
219 if (stage == 0) { 219 if (stage == 0) {
220 Expect.equals(11, stream.available()); 220 Expect.equals(11, stream.available());
221 data = stream.read(2); 221 data = stream.read(2);
222 Expect.equals("A\r", data); 222 Expect.equals("A\r", data);
223 Expect.equals(9, stream.available()); 223 Expect.equals(9, stream.available());
224 data = stream.readLine(); 224 data = stream.readLine();
225 Expect.equals("", data); 225 Expect.equals("", data);
226 Expect.equals(8, stream.available()); 226 Expect.equals(8, stream.available());
227 data = stream.read(4); 227 data = stream.read(4);
228 Expect.equals("BCD\n", data); 228 Expect.equals("BCD\n", data);
229 Expect.equals(4, stream.available()); 229 Expect.equals(4, stream.available());
230 data = stream.readLine(); 230 data = stream.readLine();
231 Expect.equals(null, data); 231 Expect.equals(null, data);
232 data = stream.read(4); 232 data = stream.read(4);
233 Expect.equals("1234", data); 233 Expect.equals("1234", data);
234 s.write("A\r\nBCD\n1234".charCodes); 234 s.write("A\r\nBCD\n1234".codeUnits);
235 stage++; 235 stage++;
236 } else if (stage == 1) { 236 } else if (stage == 1) {
237 Expect.equals(11, stream.available()); 237 Expect.equals(11, stream.available());
238 data = stream.read(1); 238 data = stream.read(1);
239 Expect.equals("A", data); 239 Expect.equals("A", data);
240 Expect.equals(10, stream.available()); 240 Expect.equals(10, stream.available());
241 data = stream.read(1); 241 data = stream.read(1);
242 Expect.equals("\r", data); 242 Expect.equals("\r", data);
243 Expect.equals(9, stream.available()); 243 Expect.equals(9, stream.available());
244 data = stream.read(1); 244 data = stream.read(1);
245 Expect.equals("\n", data); 245 Expect.equals("\n", data);
246 Expect.equals(8, stream.available()); 246 Expect.equals(8, stream.available());
247 data = stream.readLine(); 247 data = stream.readLine();
248 Expect.equals("BCD", data); 248 Expect.equals("BCD", data);
249 data = stream.readLine(); 249 data = stream.readLine();
250 Expect.equals(null, data); 250 Expect.equals(null, data);
251 data = stream.read(4); 251 data = stream.read(4);
252 Expect.equals("1234", data); 252 Expect.equals("1234", data);
253 s.write("A\r\nBCD\n1234".charCodes); 253 s.write("A\r\nBCD\n1234".codeUnits);
254 stage++; 254 stage++;
255 } else if (stage == 2) { 255 } else if (stage == 2) {
256 Expect.equals(11, stream.available()); 256 Expect.equals(11, stream.available());
257 data = stream.read(7); 257 data = stream.read(7);
258 Expect.equals("A\r\nBCD\n", data); 258 Expect.equals("A\r\nBCD\n", data);
259 Expect.equals(4, stream.available()); 259 Expect.equals(4, stream.available());
260 data = stream.readLine(); 260 data = stream.readLine();
261 Expect.equals(null, data); 261 Expect.equals(null, data);
262 data = stream.read(); 262 data = stream.read();
263 Expect.equals("1234", data); 263 Expect.equals("1234", data);
264 stage++; 264 stage++;
265 s.markEndOfStream(); 265 s.markEndOfStream();
266 } 266 }
267 } 267 }
268 268
269 void streamClosed() { 269 void streamClosed() {
270 Expect.equals(3, stage); 270 Expect.equals(3, stage);
271 Expect.equals(true, stream.closed); 271 Expect.equals(true, stream.closed);
272 } 272 }
273 273
274 s.write("A\r\nBCD\n1234".charCodes); 274 s.write("A\r\nBCD\n1234".codeUnits);
275 stream.onData = stringData; 275 stream.onData = stringData;
276 stream.onClosed = streamClosed; 276 stream.onClosed = streamClosed;
277 } 277 }
278 278
279 class TestException implements Exception { 279 class TestException implements Exception {
280 TestException(); 280 TestException();
281 } 281 }
282 282
283 class ErrorInputStream implements InputStream { 283 class ErrorInputStream implements InputStream {
284 ErrorInputStream(); 284 ErrorInputStream();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 testUtf8(); 326 testUtf8();
327 testLatin1(); 327 testLatin1();
328 testAscii(); 328 testAscii();
329 testReadLine1(); 329 testReadLine1();
330 testReadLine2(); 330 testReadLine2();
331 testReadChunks(); 331 testReadChunks();
332 testReadMixed(); 332 testReadMixed();
333 testErrorHandler(); 333 testErrorHandler();
334 testEncodingErrorWithHandler(); 334 testEncodingErrorWithHandler();
335 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698