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

Side by Side Diff: pkg/analysis_server/test/physical_resource_provider_test.dart

Issue 355453005: Add a Resource.parent getter, which gets the parent directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library test.physical.resource.provider; 5 library test.physical.resource.provider;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io' as io; 8 import 'dart:io' as io;
9 9
10 import 'package:analysis_server/src/resource.dart'; 10 import 'package:analysis_server/src/resource.dart';
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 file.hashCode; 153 file.hashCode;
154 }); 154 });
155 155
156 test('shortName', () { 156 test('shortName', () {
157 expect(file.shortName, 'file.txt'); 157 expect(file.shortName, 'file.txt');
158 }); 158 });
159 159
160 test('toString', () { 160 test('toString', () {
161 expect(file.toString(), path); 161 expect(file.toString(), path);
162 }); 162 });
163
164 test('parent', () {
165 Resource parent = file.parent;
166 expect(parent, new isInstanceOf<Folder>());
167 expect(parent.path, equals(tempPath));
168 });
163 }); 169 });
164 170
165 group('Folder', () { 171 group('Folder', () {
166 String path; 172 String path;
167 Folder folder; 173 Folder folder;
168 174
169 setUp(() { 175 setUp(() {
170 path = join(tempPath, 'folder'); 176 path = join(tempPath, 'folder');
171 new io.Directory(path).createSync(); 177 new io.Directory(path).createSync();
172 folder = PhysicalResourceProvider.INSTANCE.getResource(path); 178 folder = PhysicalResourceProvider.INSTANCE.getResource(path);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 }); 215 });
210 // check names 216 // check names
211 expect(children[0].shortName, 'a.txt'); 217 expect(children[0].shortName, 'a.txt');
212 expect(children[1].shortName, 'bFolder'); 218 expect(children[1].shortName, 'bFolder');
213 expect(children[2].shortName, 'c.txt'); 219 expect(children[2].shortName, 'c.txt');
214 // check types 220 // check types
215 expect(children[0], _isFile); 221 expect(children[0], _isFile);
216 expect(children[1], _isFolder); 222 expect(children[1], _isFolder);
217 expect(children[2], _isFile); 223 expect(children[2], _isFile);
218 }); 224 });
225
226 test('parent', () {
227 Resource parent = folder.parent;
228 expect(parent, new isInstanceOf<Folder>());
229 expect(parent.path, equals(tempPath));
230
231 // Since the OS is in control of where tempPath is, we don't know how
232 // far it should be from the root. So just verify that each call to
233 // parent results in a a folder with a shorter path, and that we
234 // reach the root eventually.
235 while (true) {
236 Resource grandParent = parent.parent;
237 if (grandParent == null) {
238 break;
239 }
240 expect(grandParent, new isInstanceOf<Folder>());
241 expect(grandParent.path.length, lessThan(parent.path.length));
242 parent = grandParent;
243 }
244 });
219 }); 245 });
220 }); 246 });
221 } 247 }
222 248
223 var _isFile = new isInstanceOf<File>(); 249 var _isFile = new isInstanceOf<File>();
224 var _isFolder = new isInstanceOf<Folder>(); 250 var _isFolder = new isInstanceOf<Folder>();
225 var _isMemoryResourceException = new isInstanceOf<MemoryResourceException>(); 251 var _isMemoryResourceException = new isInstanceOf<MemoryResourceException>();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698