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

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

Issue 11316102: Add utility methods to write the contents of a file as one operation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
« sdk/lib/io/file_impl.dart ('K') | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:io';
6 import 'dart:isolate';
7
8 testWriteAsBytesSync(dir) {
9 var f = new File('${dir.path}/bytes_sync.txt');
10 var data = [50,50,50];
11 f.writeAsBytesSync(data);
12 Expect.listEquals(data, f.readAsBytesSync());
13 f.writeAsBytesSync(data, FileMode.APPEND);
14 var expected = [50, 50, 50, 50, 50, 50];
15 Expect.listEquals(expected, f.readAsBytesSync());
16 }
17
18 testWriteAsStringSync(dir) {
19 var f = new File('${dir.path}/string_sync.txt');
20 var data = 'asdf';
21 f.writeAsStringSync(data);
22 Expect.listEquals(data, f.readAsStringSync());
23 f.writeAsStringSync(data, FileMode.APPEND);
24 Expect.equals('$data$data', f.readAsStringSync());
25 }
26
27 Future testWriteAsBytes(dir) {
28 var completer = new Completer();
29 var f = new File('${dir.path}/bytes.txt');
30 var data = [50,50,50];
31 f.writeAsBytes(data).then((_){
Søren Gjesse 2012/11/20 13:23:34 Maybe expect _ is f.
32 f.readAsBytes().then((bytes) {
33 Expect.listEquals(data, bytes);
34 f.writeAsBytes(data, FileMode.APPEND).then((_) {
Søren Gjesse 2012/11/20 13:23:34 Ditto.
35 f.readAsBytes().then((bytes) {
36 var expected = [50, 50, 50, 50, 50, 50];
37 Expect.listEquals(expected, bytes);
38 completer.complete(true);
39 });
40 });
41 });
42 });
43 return completer.future;
44 }
45
46 Future testWriteAsString(dir) {
47 var completer = new Completer();
48 var f = new File('${dir.path}/strings.txt');
49 var data = 'asdf';
50 f.writeAsString(data).then((_){
Søren Gjesse 2012/11/20 13:23:34 Ditto.
51 f.readAsString().then((str) {
52 Expect.equals(data, str);
53 f.writeAsString(data, FileMode.APPEND).then((_) {
Søren Gjesse 2012/11/20 13:23:34 Ditto.
54 f.readAsString().then((str) {
55 Expect.equals('$data$data', str);
56 completer.complete(true);
57 });
58 });
59 });
60 });
61 return completer.future;
62 }
63
64 main() {
65 var port = new ReceivePort();
66 var tempDir = new Directory('').createTempSync();
67 testWriteAsBytesSync(tempDir);
68 testWriteAsStringSync(tempDir);
69 testWriteAsBytes(tempDir).chain((_) {
70 return testWriteAsString(tempDir);
71 }).then((_) {
72 tempDir.deleteSync(recursive: true);
73 port.close();
74 });
75 }
OLDNEW
« sdk/lib/io/file_impl.dart ('K') | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698