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

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: Address comments. 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
« no previous file with comments | « tests/standalone/io/file_non_ascii_test.dart ('k') | tests/standalone/io/process_non_ascii_test.dart » ('j') | 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..5212b797b733518515abbd4390972d61897a465b
--- /dev/null
+++ b/tests/standalone/io/file_write_as_test.dart
@@ -0,0 +1,79 @@
+// 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.equals(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((file){
+ Expect.equals(f, file);
+ f.readAsBytes().then((bytes) {
+ Expect.listEquals(data, bytes);
+ f.writeAsBytes(data, FileMode.APPEND).then((file) {
+ Expect.equals(f, file);
+ 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((file){
+ Expect.equals(f, file);
+ f.readAsString().then((str) {
+ Expect.equals(data, str);
+ f.writeAsString(data, FileMode.APPEND).then((file) {
+ Expect.equals(f, file);
+ 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();
+ });
+}
« no previous file with comments | « tests/standalone/io/file_non_ascii_test.dart ('k') | tests/standalone/io/process_non_ascii_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698