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

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

Issue 11663004: Fix File.writeAsString to use named optional arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
« no previous file with comments | « 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
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
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 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698