| 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 void testReadAsString() { | 9 void testReadAsString() { |
| 10 var tmp = Directory.systemTemp.createTempSync('dart_file_read_encoded'); | 10 var tmp = Directory.systemTemp.createTempSync('dart_file_read_encoded'); |
| 11 | 11 |
| 12 var file = new File('${tmp.path}/file'); | 12 var file = new File('${tmp.path}/file'); |
| 13 file.createSync(); | 13 file.createSync(); |
| 14 | 14 |
| 15 file.writeAsBytesSync([0xb0]); | 15 file.writeAsBytesSync([0xb0]); |
| 16 | 16 |
| 17 Expect.throws(file.readAsStringSync, (e) => e is FileException); | 17 Expect.throws(file.readAsStringSync, (e) => e is FileSystemException); |
| 18 | 18 |
| 19 asyncStart(); | 19 asyncStart(); |
| 20 file.readAsString().then((_) { | 20 file.readAsString().then((_) { |
| 21 Expect.fail("expected exception"); | 21 Expect.fail("expected exception"); |
| 22 }).catchError((e) { | 22 }).catchError((e) { |
| 23 tmp.deleteSync(recursive: true); | 23 tmp.deleteSync(recursive: true); |
| 24 asyncEnd(); | 24 asyncEnd(); |
| 25 }, test: (e) => e is FileException); | 25 }, test: (e) => e is FileSystemException); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void testReadAsLines() { | 28 void testReadAsLines() { |
| 29 var tmp = Directory.systemTemp.createTempSync('dart_file_read_encoded'); | 29 var tmp = Directory.systemTemp.createTempSync('dart_file_read_encoded'); |
| 30 | 30 |
| 31 var file = new File('${tmp.path}/file'); | 31 var file = new File('${tmp.path}/file'); |
| 32 file.createSync(); | 32 file.createSync(); |
| 33 | 33 |
| 34 file.writeAsBytesSync([0xb0]); | 34 file.writeAsBytesSync([0xb0]); |
| 35 | 35 |
| 36 Expect.throws(file.readAsLinesSync, (e) => e is FileException); | 36 Expect.throws(file.readAsLinesSync, (e) => e is FileSystemException); |
| 37 | 37 |
| 38 asyncStart(); | 38 asyncStart(); |
| 39 file.readAsLines().then((_) { | 39 file.readAsLines().then((_) { |
| 40 Expect.fail("expected exception"); | 40 Expect.fail("expected exception"); |
| 41 }).catchError((e) { | 41 }).catchError((e) { |
| 42 tmp.deleteSync(recursive: true); | 42 tmp.deleteSync(recursive: true); |
| 43 asyncEnd(); | 43 asyncEnd(); |
| 44 }, test: (e) => e is FileException); | 44 }, test: (e) => e is FileSystemException); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void main() { | 47 void main() { |
| 48 testReadAsString(); | 48 testReadAsString(); |
| 49 testReadAsLines(); | 49 testReadAsLines(); |
| 50 } | 50 } |
| OLD | NEW |