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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/io_service.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) 2013, 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 // Dart test program for testing File.copy*
6
7 import 'dart:io';
8
9 import "package:expect/expect.dart";
10 import "package:async_helper/async_helper.dart";
11
12 const FILE_CONTENT1 = 'some string';
13 const FILE_CONTENT2 = 'some other string';
14
15 void testCopySync() {
16 var tmp = Directory.systemTemp.createTempSync('dart-file-copy');
17
18 var file1 = new File('${tmp.path}/file1');
19 file1.writeAsStringSync(FILE_CONTENT1);
20 Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
21
22 // Copy to new file works.
23 var file2 = file1.copySync('${tmp.path}/file2');
24 Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
25 Expect.equals(FILE_CONTENT1, file2.readAsStringSync());
26
27 // Override works for files.
28 file2.writeAsStringSync(FILE_CONTENT2);
29 file2.copySync(file1.path);
30 Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
31 Expect.equals(FILE_CONTENT2, file2.readAsStringSync());
32
33 // Fail when coping to directory.
34 var dir = new Directory('${tmp.path}/dir')..createSync();
35 Expect.throws(() => file1.copySync(dir.path));
36 Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
37
38 tmp.deleteSync(recursive: true);
39 }
40
41
42 void testCopy() {
43 asyncStart();
44 var tmp = Directory.systemTemp.createTempSync('dart-file-copy');
45
46 var file1 = new File('${tmp.path}/file1');
47 file1.writeAsStringSync(FILE_CONTENT1);
48 Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
49
50 // Copy to new file works.
51 file1.copy('${tmp.path}/file2')
52 .then((file2) {
53 Expect.equals(FILE_CONTENT1, file1.readAsStringSync());
54 Expect.equals(FILE_CONTENT1, file2.readAsStringSync());
55
56 // Override works for files.
57 file2.writeAsStringSync(FILE_CONTENT2);
58 return file2.copy(file1.path)
59 .then((_) {
60 Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
61 Expect.equals(FILE_CONTENT2, file2.readAsStringSync());
62
63 // Fail when coping to directory.
64 var dir = new Directory('${tmp.path}/dir')..createSync();
65
66 return file1.copy(dir.path)
67 .then((_) => Expect.fail('expected error'),
68 onError: (_) {})
69 .then((_) {
70 Expect.equals(FILE_CONTENT2, file1.readAsStringSync());
71 });
72
73 });
74 })
75 .whenComplete(() {
76 tmp.deleteSync(recursive: true);
77 asyncEnd();
78 });
79
80 }
81
82
83 main() {
84 testCopySync();
85 testCopy();
86 }
OLDNEW
« 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