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

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

Issue 12638039: dart:io | Add "followLinks" optional parameter to Directory.list, let it return Link objects when f… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Switch from Stream.reduce to Completer in link_test. Created 7 years, 9 months 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/link.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/link_test.dart
diff --git a/tests/standalone/io/link_test.dart b/tests/standalone/io/link_test.dart
index ae303a772ec4b75710c5867f9d18f2fa6d751f64..8d467d4bfdf7046fa6914832f86dbd659b56f78b 100644
--- a/tests/standalone/io/link_test.dart
+++ b/tests/standalone/io/link_test.dart
@@ -2,6 +2,7 @@
// 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:async";
import "dart:io";
import "dart:isolate";
@@ -76,7 +77,63 @@ testCreateSync() {
Expect.throws(() => FileSystemEntity.identicalSync(createdFile,
base.append('link/foo').toNativePath()));
- new Directory.fromPath(base).deleteSync(recursive: true);
+ var baseDir = new Directory.fromPath(base);
+
+ Map makeExpected(bool recursive, bool followLinks) {
+ Map expected = new Map();
+ expected['target'] = 'Directory';
+ expected['link'] = followLinks ? 'Directory' : 'Link';
+ if (recursive) {
+ expected['target/createdDirectly'] = 'Directory';
+ expected['target/createdThroughLink'] = 'Directory';
+ expected['target/createdFile'] = 'File';
+ if (followLinks) {
+ expected['link/createdDirectly'] = 'Directory';
+ expected['link/createdThroughLink'] = 'Directory';
+ expected['link/createdFile'] = 'File';
+ }
+ }
+ return expected;
+ }
+
+ void checkEntity(FileSystemEntity x, Map expected) {
+ String ending = new Path(x.path).relativeTo(base).toString();
+ Expect.isNotNull(expected[ending]);
+ Expect.isTrue(x.toString().startsWith(expected[ending]));
+ expected[ending] = 'Found';
+ }
+
+ List futures = [];
+ for (bool recursive in [true, false]) {
+ for (bool followLinks in [true, false]) {
+ Map expected = makeExpected(recursive, followLinks);
+ for (var x in baseDir.listSync(recursive: recursive,
+ followLinks: followLinks)) {
+ checkEntity(x, expected);
+ }
+ for (var v in expected.values) {
+ Expect.equals('Found', v);
+ }
+ expected = makeExpected(recursive, followLinks);
+ // We use Stream.reduce to run a function on each entry, and return
+ // a future that completes when done.
+ var f = new Completer();
+ futures.add(f.future);
+ baseDir.list(recursive: recursive, followLinks: followLinks).listen(
+ (entity) {
+ checkEntity(entity, expected);
+ },
+ onDone: () {
+ for (var v in expected.values) {
+ Expect.equals('Found', v);
+ }
+ f.complete(null);
+ });
+ }
+ }
+ Future.wait(futures).then((_) {
+ baseDir.deleteSync(recursive: true);
+ });
}
« no previous file with comments | « sdk/lib/io/link.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698