Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 import "dart:async"; | |
| 5 import "dart:io"; | 6 import "dart:io"; |
| 6 import "dart:isolate"; | 7 import "dart:isolate"; |
| 7 | 8 |
| 8 // Test the dart:io Link class. | 9 // Test the dart:io Link class. |
| 9 | 10 |
| 10 testCreateSync() { | 11 testCreateSync() { |
| 11 Path base = new Path(new Directory('').createTempSync().path); | 12 Path base = new Path(new Directory('').createTempSync().path); |
| 12 String link = base.append('link').toNativePath(); | 13 String link = base.append('link').toNativePath(); |
| 13 String target = base.append('target').toNativePath(); | 14 String target = base.append('target').toNativePath(); |
| 14 new Directory(target).createSync(); | 15 new Directory(target).createSync(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 70 |
| 70 String createdFile = base.append('target/createdFile').toNativePath(); | 71 String createdFile = base.append('target/createdFile').toNativePath(); |
| 71 new File(createdFile).createSync(); | 72 new File(createdFile).createSync(); |
| 72 Expect.isTrue(FileSystemEntity.identicalSync(createdFile, createdFile)); | 73 Expect.isTrue(FileSystemEntity.identicalSync(createdFile, createdFile)); |
| 73 Expect.isFalse(FileSystemEntity.identicalSync(createdFile, createdDirectly)); | 74 Expect.isFalse(FileSystemEntity.identicalSync(createdFile, createdDirectly)); |
| 74 Expect.isTrue(FileSystemEntity.identicalSync(createdFile, | 75 Expect.isTrue(FileSystemEntity.identicalSync(createdFile, |
| 75 base.append('link/createdFile').toNativePath())); | 76 base.append('link/createdFile').toNativePath())); |
| 76 Expect.throws(() => FileSystemEntity.identicalSync(createdFile, | 77 Expect.throws(() => FileSystemEntity.identicalSync(createdFile, |
| 77 base.append('link/foo').toNativePath())); | 78 base.append('link/foo').toNativePath())); |
| 78 | 79 |
| 79 new Directory.fromPath(base).deleteSync(recursive: true); | 80 var baseDir = new Directory.fromPath(base); |
| 81 | |
| 82 Map makeExpected(bool recursive, bool followLinks) { | |
| 83 Map expected = new Map(); | |
| 84 expected['target'] = 'Directory'; | |
| 85 expected['link'] = followLinks ? 'Directory' : 'Link'; | |
| 86 if (recursive) { | |
| 87 expected['target/createdDirectly'] = 'Directory'; | |
| 88 expected['target/createdThroughLink'] = 'Directory'; | |
| 89 expected['target/createdFile'] = 'File'; | |
| 90 if (followLinks) { | |
| 91 expected['link/createdDirectly'] = 'Directory'; | |
| 92 expected['link/createdThroughLink'] = 'Directory'; | |
| 93 expected['link/createdFile'] = 'File'; | |
| 94 } | |
| 95 } | |
| 96 return expected; | |
| 97 } | |
| 98 | |
| 99 void checkEntity(FileSystemEntity x, Map expected) { | |
| 100 String ending = new Path(x.path).relativeTo(base).toString(); | |
| 101 Expect.isNotNull(expected[ending]); | |
| 102 Expect.isTrue(x.toString().startsWith(expected[ending])); | |
| 103 expected[ending] = 'Found'; | |
| 104 } | |
| 105 | |
| 106 List futures = []; | |
| 107 for (bool recursive in [true, false]) { | |
| 108 for (bool followLinks in [true, false]) { | |
| 109 Map expected = makeExpected(recursive, followLinks); | |
| 110 for (var x in baseDir.listSync(recursive: recursive, | |
| 111 followLinks: followLinks)) { | |
|
Bill Hesse
2013/03/21 18:36:44
Indentation.
| |
| 112 checkEntity(x, expected); | |
| 113 } | |
| 114 for (var v in expected.values) { | |
| 115 Expect.equals('Found', v); | |
| 116 } | |
| 117 expected = makeExpected(recursive, followLinks); | |
| 118 futures.add( | |
| 119 baseDir.list(recursive: recursive, followLinks: followLinks).reduce( | |
|
Bill Hesse
2013/03/21 18:36:44
Use Stream.reduce to call a function with each eve
Søren Gjesse
2013/03/22 08:07:35
Run the same tests for listSync.
Bill Hesse
2013/03/22 09:58:55
I do! It is just so small you missed it - lines 1
Bill Hesse
2013/03/22 09:58:55
Switched to the more straightforward "create a Com
| |
| 120 null, | |
| 121 (_, x) { | |
| 122 checkEntity(x, expected); | |
| 123 }).then((_) { | |
| 124 for (var v in expected.values) { | |
| 125 Expect.equals('Found', v); | |
| 126 } | |
| 127 })); | |
| 128 } | |
| 129 } | |
| 130 Future.wait(futures).then((_) { | |
| 131 baseDir.deleteSync(recursive: true); | |
| 132 }); | |
| 80 } | 133 } |
| 81 | 134 |
| 82 | 135 |
| 83 main() { | 136 main() { |
| 84 testCreateSync(); | 137 testCreateSync(); |
| 85 } | 138 } |
| OLD | NEW |