| 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 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 | 7 |
| 8 testWriteAsBytesSync(dir) { | 8 testWriteAsBytesSync(dir) { |
| 9 var f = new File('${dir.path}/bytes_sync.txt'); | 9 var f = new File('${dir.path}/bytes_sync.txt'); |
| 10 var data = [50,50,50]; | 10 var data = [50,50,50]; |
| 11 f.writeAsBytesSync(data); | 11 f.writeAsBytesSync(data); |
| 12 Expect.listEquals(data, f.readAsBytesSync()); | 12 Expect.listEquals(data, f.readAsBytesSync()); |
| 13 f.writeAsBytesSync(data, FileMode.APPEND); | 13 f.writeAsBytesSync(data, FileMode.APPEND); |
| 14 var expected = [50, 50, 50, 50, 50, 50]; | 14 var expected = [50, 50, 50, 50, 50, 50]; |
| 15 Expect.listEquals(expected, f.readAsBytesSync()); | 15 Expect.listEquals(expected, f.readAsBytesSync()); |
| 16 } | 16 } |
| 17 | 17 |
| 18 testWriteAsStringSync(dir) { | 18 testWriteAsStringSync(dir) { |
| 19 var f = new File('${dir.path}/string_sync.txt'); | 19 var f = new File('${dir.path}/string_sync.txt'); |
| 20 var data = 'asdf'; | 20 var data = 'asdf'; |
| 21 f.writeAsStringSync(data); | 21 f.writeAsStringSync(data); |
| 22 Expect.equals(data, f.readAsStringSync()); | 22 Expect.equals(data, f.readAsStringSync()); |
| 23 f.writeAsStringSync(data, FileMode.APPEND); | 23 f.writeAsStringSync(data, mode: FileMode.APPEND); |
| 24 Expect.equals('$data$data', f.readAsStringSync()); | 24 Expect.equals('$data$data', f.readAsStringSync()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 Future testWriteAsBytes(dir) { | 27 Future testWriteAsBytes(dir) { |
| 28 var completer = new Completer(); | 28 var completer = new Completer(); |
| 29 var f = new File('${dir.path}/bytes.txt'); | 29 var f = new File('${dir.path}/bytes.txt'); |
| 30 var data = [50,50,50]; | 30 var data = [50,50,50]; |
| 31 f.writeAsBytes(data).then((file){ | 31 f.writeAsBytes(data).then((file){ |
| 32 Expect.equals(f, file); | 32 Expect.equals(f, file); |
| 33 f.readAsBytes().then((bytes) { | 33 f.readAsBytes().then((bytes) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 Future testWriteAsString(dir) { | 48 Future testWriteAsString(dir) { |
| 49 var completer = new Completer(); | 49 var completer = new Completer(); |
| 50 var f = new File('${dir.path}/strings.txt'); | 50 var f = new File('${dir.path}/strings.txt'); |
| 51 var data = 'asdf'; | 51 var data = 'asdf'; |
| 52 f.writeAsString(data).then((file){ | 52 f.writeAsString(data).then((file){ |
| 53 Expect.equals(f, file); | 53 Expect.equals(f, file); |
| 54 f.readAsString().then((str) { | 54 f.readAsString().then((str) { |
| 55 Expect.equals(data, str); | 55 Expect.equals(data, str); |
| 56 f.writeAsString(data, FileMode.APPEND).then((file) { | 56 f.writeAsString(data, mode: FileMode.APPEND).then((file) { |
| 57 Expect.equals(f, file); | 57 Expect.equals(f, file); |
| 58 f.readAsString().then((str) { | 58 f.readAsString().then((str) { |
| 59 Expect.equals('$data$data', str); | 59 Expect.equals('$data$data', str); |
| 60 completer.complete(true); | 60 completer.complete(true); |
| 61 }); | 61 }); |
| 62 }); | 62 }); |
| 63 }); | 63 }); |
| 64 }); | 64 }); |
| 65 return completer.future; | 65 return completer.future; |
| 66 } | 66 } |
| 67 | 67 |
| 68 main() { | 68 main() { |
| 69 var port = new ReceivePort(); | 69 var port = new ReceivePort(); |
| 70 var tempDir = new Directory('').createTempSync(); | 70 var tempDir = new Directory('').createTempSync(); |
| 71 testWriteAsBytesSync(tempDir); | 71 testWriteAsBytesSync(tempDir); |
| 72 testWriteAsStringSync(tempDir); | 72 testWriteAsStringSync(tempDir); |
| 73 testWriteAsBytes(tempDir).chain((_) { | 73 testWriteAsBytes(tempDir).chain((_) { |
| 74 return testWriteAsString(tempDir); | 74 return testWriteAsString(tempDir); |
| 75 }).then((_) { | 75 }).then((_) { |
| 76 tempDir.deleteSync(recursive: true); | 76 tempDir.deleteSync(recursive: true); |
| 77 port.close(); | 77 port.close(); |
| 78 }); | 78 }); |
| 79 } | 79 } |
| OLD | NEW |