OLD | NEW |
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 | 6 |
7 void testUtf8() { | 7 void testUtf8() { |
8 List<int> data = [0x01, | 8 List<int> data = [0x01, |
9 0x7f, | 9 0x7f, |
10 0xc2, 0x80, | 10 0xc2, 0x80, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 TestException(); | 169 TestException(); |
170 } | 170 } |
171 | 171 |
172 class ErrorInputStream implements InputStream { | 172 class ErrorInputStream implements InputStream { |
173 ErrorInputStream(); | 173 ErrorInputStream(); |
174 List<int> read([int len]) => null; | 174 List<int> read([int len]) => null; |
175 int readInto(List<int> buffer, [int offset, int len]) => 0; | 175 int readInto(List<int> buffer, [int offset, int len]) => 0; |
176 int available() => 0; | 176 int available() => 0; |
177 void pipe(OutputStream output, [bool close]){ } | 177 void pipe(OutputStream output, [bool close]){ } |
178 void close() { } | 178 void close() { } |
179 bool get closed() => true; | 179 bool get closed => true; |
180 void set onData(void callback()) { } | 180 void set onData(void callback()) { } |
181 void set onClosed(void callback()) { } | 181 void set onClosed(void callback()) { } |
182 void set onError(void callback(Exception e)) { | 182 void set onError(void callback(Exception e)) { |
183 callback(new TestException()); | 183 callback(new TestException()); |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 testErrorHandler() { | 187 testErrorHandler() { |
188 var errors = 0; | 188 var errors = 0; |
189 var stream = new StringInputStream(new ErrorInputStream()); | 189 var stream = new StringInputStream(new ErrorInputStream()); |
190 stream.onError = (e) { | 190 stream.onError = (e) { |
191 errors++; | 191 errors++; |
192 Expect.isTrue(e is TestException); | 192 Expect.isTrue(e is TestException); |
193 }; | 193 }; |
194 Expect.equals(1, errors); | 194 Expect.equals(1, errors); |
195 } | 195 } |
196 | 196 |
197 main() { | 197 main() { |
198 testUtf8(); | 198 testUtf8(); |
199 testLatin1(); | 199 testLatin1(); |
200 testAscii(); | 200 testAscii(); |
201 testReadLine1(); | 201 testReadLine1(); |
202 testReadLine2(); | 202 testReadLine2(); |
203 testErrorHandler(); | 203 testErrorHandler(); |
204 } | 204 } |
OLD | NEW |