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

Side by Side Diff: tests/standalone/io/directory_test.dart

Issue 11748017: Add synchronous directory listing to dart:io Directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments, move tests that fail on Windows due to VM bug 7157 to a separate test file. Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // Directory listing test. 5 // Directory listing test.
6 6
7 import "dart:io"; 7 import "dart:io";
8 import "dart:isolate"; 8 import "dart:isolate";
9 9
10 class DirectoryTest { 10 class DirectoryTest {
11 static void testListing() { 11 static void testListing() {
12 bool listedDir = false; 12 bool listedDir = false;
13 bool listedFile = false; 13 bool listedFile = false;
14 14
15 Directory directory = new Directory("").createTempSync(); 15 Directory directory = new Directory("").createTempSync();
16 Directory subDirectory = new Directory("${directory.path}/subdir"); 16 Directory subDirectory = new Directory("${directory.path}/subdir");
17 Expect.isTrue('$directory'.contains(directory.path)); 17 Expect.isTrue('$directory'.contains(directory.path));
18 Expect.isFalse(subDirectory.existsSync()); 18 Expect.isFalse(subDirectory.existsSync());
19 subDirectory.createSync(); 19 subDirectory.createSync();
20 Expect.isTrue(subDirectory.existsSync()); 20 Expect.isTrue(subDirectory.existsSync());
21 File f = new File('${subDirectory.path}/file.txt'); 21 File f = new File('${subDirectory.path}/file.txt');
22 Expect.isFalse(f.existsSync()); 22 Expect.isFalse(f.existsSync());
23 f.createSync(); 23 f.createSync();
24 24
25 void testSyncListing(bool recursive) {
26 for (var entry in directory.listSync(recursive: recursive)) {
27 if (entry is File) {
28 Expect.isTrue(entry.name.contains(directory.path));
29 Expect.isTrue(entry.name.contains('subdir'));
30 Expect.isTrue(entry.name.contains('file.txt'));
31 Expect.isFalse(listedFile);
32 listedFile = true;
33 } else {
34 Expect.isTrue(entry is Directory);
35 Expect.isTrue(entry.path.contains(directory.path));
36 Expect.isTrue(entry.path.contains('subdir'));
37 Expect.isFalse(listedDir);
38 listedDir = true;
39 }
40 }
41 Expect.equals(listedFile, recursive);
42 Expect.isTrue(listedDir);
43 listedFile = false;
44 listedDir = false;
45 }
46
47 testSyncListing(true);
48 testSyncListing(false);
49
25 var lister = directory.list(recursive: true); 50 var lister = directory.list(recursive: true);
26 51
27 lister.onDir = (dir) { 52 lister.onDir = (dir) {
28 listedDir = true; 53 listedDir = true;
29 Expect.isTrue(dir.contains(directory.path)); 54 Expect.isTrue(dir.contains(directory.path));
30 Expect.isTrue(dir.contains('subdir')); 55 Expect.isTrue(dir.contains('subdir'));
31 }; 56 };
32 57
33 lister.onFile = (f) { 58 lister.onFile = (f) {
34 listedFile = true; 59 listedFile = true;
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 testCreateTempErrorSync(); 614 testCreateTempErrorSync();
590 testCreateTempError(); 615 testCreateTempError();
591 testCreateExistingSync(); 616 testCreateExistingSync();
592 testCreateExisting(); 617 testCreateExisting();
593 testCreateDirExistingFileSync(); 618 testCreateDirExistingFileSync();
594 testCreateDirExistingFile(); 619 testCreateDirExistingFile();
595 testCreateRecursive(); 620 testCreateRecursive();
596 testCreateRecursiveSync(); 621 testCreateRecursiveSync();
597 testRename(); 622 testRename();
598 } 623 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_list_nonexistent_test.dart ('k') | tests/standalone/io/file_system_links_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698