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

Unified Diff: tests/standalone/io/file_copy_test.dart

Issue 105133004: Add File.copy(Sync) to dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix permissions. Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/io_service.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_copy_test.dart
diff --git a/tests/standalone/io/file_copy_test.dart b/tests/standalone/io/file_copy_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2ef7358dd53161624dad4664ed4450656111f7f5
--- /dev/null
+++ b/tests/standalone/io/file_copy_test.dart
@@ -0,0 +1,86 @@
+// Copyright (c) 2013, 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.
+//
+// Dart test program for testing File.copy*
+
+import 'dart:io';
+
+import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+
+const FILE_CONTENT1 = 'some string';
+const FILE_CONTENT2 = 'some other string';
+
+void testCopySync() {
+ var tmp = Directory.systemTemp.createTempSync('dart-file-copy');
+
+ var file1 = new File('${tmp.path}/file1');
+ file1.writeAsStringSync(FILE_CONTENT1);
+ Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
+
+ // Copy to new file works.
+ var file2 = file1.copySync('${tmp.path}/file2');
+ Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
+ Expect.equals(FILE_CONTENT1, file2.readAsStringSync());
+
+ // Override works for files.
+ file2.writeAsStringSync(FILE_CONTENT2);
+ file2.copySync(file1.path);
+ Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
+ Expect.equals(FILE_CONTENT2, file2.readAsStringSync());
+
+ // Fail when coping to directory.
+ var dir = new Directory('${tmp.path}/dir')..createSync();
+ Expect.throws(() => file1.copySync(dir.path));
+ Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
+
+ tmp.deleteSync(recursive: true);
+}
+
+
+void testCopy() {
+ asyncStart();
+ var tmp = Directory.systemTemp.createTempSync('dart-file-copy');
+
+ var file1 = new File('${tmp.path}/file1');
+ file1.writeAsStringSync(FILE_CONTENT1);
+ Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
+
+ // Copy to new file works.
+ file1.copy('${tmp.path}/file2')
+ .then((file2) {
+ Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
+ Expect.equals(FILE_CONTENT1, file2.readAsStringSync());
+
+ // Override works for files.
+ file2.writeAsStringSync(FILE_CONTENT2);
+ return file2.copy(file1.path)
+ .then((_) {
+ Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
+ Expect.equals(FILE_CONTENT2, file2.readAsStringSync());
+
+ // Fail when coping to directory.
+ var dir = new Directory('${tmp.path}/dir')..createSync();
+
+ return file1.copy(dir.path)
+ .then((_) => Expect.fail('expected error'),
+ onError: (_) {})
+ .then((_) {
+ Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
+ });
+
+ });
+ })
+ .whenComplete(() {
+ tmp.deleteSync(recursive: true);
+ asyncEnd();
+ });
+
+}
+
+
+main() {
+ testCopySync();
+ testCopy();
+}
« no previous file with comments | « sdk/lib/io/io_service.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698