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

Unified 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/io/file_impl.dart ('K') | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/file_write_as_test.dart
diff --git a/tests/standalone/io/file_write_as_test.dart b/tests/standalone/io/file_write_as_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..bcea421bb1566620d91a0c1b8be5ee0cf5ca6934
--- /dev/null
+++ b/tests/standalone/io/file_write_as_test.dart
@@ -0,0 +1,75 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:io';
+import 'dart:isolate';
+
+testWriteAsBytesSync(dir) {
+ var f = new File('${dir.path}/bytes_sync.txt');
+ var data = [50,50,50];
+ f.writeAsBytesSync(data);
+ Expect.listEquals(data, f.readAsBytesSync());
+ f.writeAsBytesSync(data, FileMode.APPEND);
+ var expected = [50, 50, 50, 50, 50, 50];
+ Expect.listEquals(expected, f.readAsBytesSync());
+}
+
+testWriteAsStringSync(dir) {
+ var f = new File('${dir.path}/string_sync.txt');
+ var data = 'asdf';
+ f.writeAsStringSync(data);
+ Expect.listEquals(data, f.readAsStringSync());
+ f.writeAsStringSync(data, FileMode.APPEND);
+ Expect.equals('$data$data', f.readAsStringSync());
+}
+
+Future testWriteAsBytes(dir) {
+ var completer = new Completer();
+ var f = new File('${dir.path}/bytes.txt');
+ var data = [50,50,50];
+ f.writeAsBytes(data).then((_){
Søren Gjesse 2012/11/20 13:23:34 Maybe expect _ is f.
+ f.readAsBytes().then((bytes) {
+ Expect.listEquals(data, bytes);
+ f.writeAsBytes(data, FileMode.APPEND).then((_) {
Søren Gjesse 2012/11/20 13:23:34 Ditto.
+ f.readAsBytes().then((bytes) {
+ var expected = [50, 50, 50, 50, 50, 50];
+ Expect.listEquals(expected, bytes);
+ completer.complete(true);
+ });
+ });
+ });
+ });
+ return completer.future;
+}
+
+Future testWriteAsString(dir) {
+ var completer = new Completer();
+ var f = new File('${dir.path}/strings.txt');
+ var data = 'asdf';
+ f.writeAsString(data).then((_){
Søren Gjesse 2012/11/20 13:23:34 Ditto.
+ f.readAsString().then((str) {
+ Expect.equals(data, str);
+ f.writeAsString(data, FileMode.APPEND).then((_) {
Søren Gjesse 2012/11/20 13:23:34 Ditto.
+ f.readAsString().then((str) {
+ Expect.equals('$data$data', str);
+ completer.complete(true);
+ });
+ });
+ });
+ });
+ return completer.future;
+}
+
+main() {
+ var port = new ReceivePort();
+ var tempDir = new Directory('').createTempSync();
+ testWriteAsBytesSync(tempDir);
+ testWriteAsStringSync(tempDir);
+ testWriteAsBytes(tempDir).chain((_) {
+ return testWriteAsString(tempDir);
+ }).then((_) {
+ tempDir.deleteSync(recursive: true);
+ port.close();
+ });
+}
« 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