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

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

Issue 345063005: Fix operator== and hashCode for File and Folder objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
« no previous file with comments | « pkg/analysis_server/test/physical_resource_provider_test.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
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.resource; 5 library test.resource;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/resource.dart'; 9 import 'package:analysis_server/src/resource.dart';
10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 File fileA = provider.getResource('/fileA.txt'); 216 File fileA = provider.getResource('/fileA.txt');
217 File fileB = provider.getResource('/fileB.txt'); 217 File fileB = provider.getResource('/fileB.txt');
218 expect(fileA == new Object(), isFalse); 218 expect(fileA == new Object(), isFalse);
219 expect(fileA == fileB, isFalse); 219 expect(fileA == fileB, isFalse);
220 }); 220 });
221 221
222 test('true', () { 222 test('true', () {
223 File file = provider.getResource('/file.txt'); 223 File file = provider.getResource('/file.txt');
224 expect(file == file, isTrue); 224 expect(file == file, isTrue);
225 }); 225 });
226
227 test('before and after creation', () {
228 String path = '/file.txt';
229 File file1 = provider.getResource(path);
230 provider.newFile(path, 'contents');
231 File file2 = provider.getResource(path);
232 expect(file1 == file2, isTrue);
233 });
226 }); 234 });
227 235
228 group('exists', () { 236 group('exists', () {
229 test('false', () { 237 test('false', () {
230 File file = provider.getResource('/file.txt'); 238 File file = provider.getResource('/file.txt');
231 expect(file, isNotNull); 239 expect(file, isNotNull);
232 expect(file.exists, isFalse); 240 expect(file.exists, isFalse);
233 }); 241 });
234 242
235 test('true', () { 243 test('true', () {
236 provider.newFile('/foo/file.txt', 'qwerty'); 244 provider.newFile('/foo/file.txt', 'qwerty');
237 File file = provider.getResource('/foo/file.txt'); 245 File file = provider.getResource('/foo/file.txt');
238 expect(file, isNotNull); 246 expect(file, isNotNull);
239 expect(file.exists, isTrue); 247 expect(file.exists, isTrue);
240 }); 248 });
241 }); 249 });
242 250
243 test('fullName', () { 251 test('fullName', () {
244 File file = provider.getResource('/foo/bar/file.txt'); 252 File file = provider.getResource('/foo/bar/file.txt');
245 expect(file.path, '/foo/bar/file.txt'); 253 expect(file.path, '/foo/bar/file.txt');
246 }); 254 });
247 255
248 test('hashCode', () { 256 test('hashCode', () {
249 File file = provider.getResource('/foo/bar/file.txt'); 257 String path = '/foo/bar/file.txt';
250 file.hashCode; 258 File file1 = provider.getResource(path);
259 provider.newFile(path, 'contents');
260 File file2 = provider.getResource(path);
261 expect(file1.hashCode, equals(file2.hashCode));
251 }); 262 });
252 263
253 test('shortName', () { 264 test('shortName', () {
254 File file = provider.getResource('/foo/bar/file.txt'); 265 File file = provider.getResource('/foo/bar/file.txt');
255 expect(file.shortName, 'file.txt'); 266 expect(file.shortName, 'file.txt');
256 }); 267 });
257 268
258 test('toString', () { 269 test('toString', () {
259 File file = provider.getResource('/foo/bar/file.txt'); 270 File file = provider.getResource('/foo/bar/file.txt');
260 expect(file.toString(), '/foo/bar/file.txt'); 271 expect(file.toString(), '/foo/bar/file.txt');
261 }); 272 });
262 273
263 test('parent', () { 274 test('parent', () {
264 provider.newFile('/foo/bar/file.txt', 'content'); 275 provider.newFile('/foo/bar/file.txt', 'content');
265 File file = provider.getResource('/foo/bar/file.txt'); 276 File file = provider.getResource('/foo/bar/file.txt');
266 Resource parent = file.parent; 277 Resource parent = file.parent;
267 expect(parent, new isInstanceOf<Folder>()); 278 expect(parent, new isInstanceOf<Folder>());
268 expect(parent.path, equals('/foo/bar')); 279 expect(parent.path, equals('/foo/bar'));
269 }); 280 });
270 }); 281 });
271 282
272 group('Folder', () { 283 group('Folder', () {
273 Folder folder; 284 Folder folder;
285 const String path = '/foo/bar';
274 286
275 setUp(() { 287 setUp(() {
276 folder = provider.newFolder('/foo/bar'); 288 folder = provider.newFolder(path);
289 });
290
291 test('hashCode', () {
292 Folder folder2 = provider.getResource(path);
293 expect(folder.hashCode, equals(folder2.hashCode));
294 });
295
296 test('equality', () {
297 Folder folder2 = provider.getResource(path);
298 expect(folder == folder2, isTrue);
scheglov 2014/07/02 00:32:56 Any test for a case when == returns false for memo
Paul Berry 2014/07/02 00:37:15 Good point. I'll add those.
277 }); 299 });
278 300
279 group('getChild', () { 301 group('getChild', () {
280 test('does not exist', () { 302 test('does not exist', () {
281 File file = folder.getChild('file.txt'); 303 File file = folder.getChild('file.txt');
282 expect(file, isNotNull); 304 expect(file, isNotNull);
283 expect(file.exists, isFalse); 305 expect(file.exists, isFalse);
284 }); 306 });
285 307
286 test('file', () { 308 test('file', () {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 expect(source, isNull); 517 expect(source, isNull);
496 }); 518 });
497 519
498 test('not a file URI', () { 520 test('not a file URI', () {
499 var uri = new Uri(scheme: 'https', path: '127.0.0.1/test.dart'); 521 var uri = new Uri(scheme: 'https', path: '127.0.0.1/test.dart');
500 Source source = resolver.resolveAbsolute(uri); 522 Source source = resolver.resolveAbsolute(uri);
501 expect(source, isNull); 523 expect(source, isNull);
502 }); 524 });
503 }); 525 });
504 } 526 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/physical_resource_provider_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698