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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/file_state_test.dart

Issue 2654303003: Ignore files that are hidden by generated files. (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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:convert'; 5 import 'dart:convert';
6 import 'dart:typed_data'; 6 import 'dart:typed_data';
7 7
8 import 'package:analyzer/file_system/file_system.dart'; 8 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/file_system/memory_file_system.dart'; 9 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/source/package_map_resolver.dart'; 10 import 'package:analyzer/source/package_map_resolver.dart';
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 expect(_excludeSdk(file.importedFiles), isEmpty); 268 expect(_excludeSdk(file.importedFiles), isEmpty);
269 expect(file.exportedFiles, isEmpty); 269 expect(file.exportedFiles, isEmpty);
270 expect(file.partedFiles, isEmpty); 270 expect(file.partedFiles, isEmpty);
271 expect(_excludeSdk(file.directReferencedFiles), isEmpty); 271 expect(_excludeSdk(file.directReferencedFiles), isEmpty);
272 expect(file.isPart, isFalse); 272 expect(file.isPart, isFalse);
273 expect(file.library, isNull); 273 expect(file.library, isNull);
274 expect(file.unlinked, isNotNull); 274 expect(file.unlinked, isNotNull);
275 expect(file.unlinked.classes, isEmpty); 275 expect(file.unlinked.classes, isEmpty);
276 } 276 }
277 277
278 test_getFileForPath_generatedFile() {
279 Uri uri = Uri.parse('package:aaa/foo.dart');
280 String templatePath = _p('/aaa/lib/foo.dart');
281 String generatedPath = _p('/generated/aaa/lib/foo.dart');
282
283 Source generatedSource = new _SourceMock();
284 when(generatedSource.fullName).thenReturn(generatedPath);
285 when(generatedSource.uri).thenReturn(uri);
286
287 when(generatedUriResolver.resolveAbsolute(uri, uri))
288 .thenReturn(generatedSource);
289
290 FileState generatedFile = fileSystemState.getFileForUri(uri);
291 expect(generatedFile.path, generatedPath);
292 expect(generatedFile.uri, uri);
293
294 FileState templateFile = fileSystemState.getFileForPath(templatePath);
295 expect(templateFile.path, templatePath);
296 expect(templateFile.uri, uri);
297
298 expect(fileSystemState.getFilesForPath(templatePath), [templateFile]);
299 }
300
301 test_getFileForPath_library() { 278 test_getFileForPath_library() {
302 String a1 = _p('/aaa/lib/a1.dart'); 279 String a1 = _p('/aaa/lib/a1.dart');
303 String a2 = _p('/aaa/lib/a2.dart'); 280 String a2 = _p('/aaa/lib/a2.dart');
304 String a3 = _p('/aaa/lib/a3.dart'); 281 String a3 = _p('/aaa/lib/a3.dart');
305 String a4 = _p('/aaa/lib/a4.dart'); 282 String a4 = _p('/aaa/lib/a4.dart');
306 String b1 = _p('/bbb/lib/b1.dart'); 283 String b1 = _p('/bbb/lib/b1.dart');
307 String b2 = _p('/bbb/lib/b2.dart'); 284 String b2 = _p('/bbb/lib/b2.dart');
308 String content_a1 = r''' 285 String content_a1 = r'''
309 import 'package:aaa/a2.dart'; 286 import 'package:aaa/a2.dart';
310 import 'package:bbb/b1.dart'; 287 import 'package:bbb/b1.dart';
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 expect(filePackageUri.uri, packageUri); 434 expect(filePackageUri.uri, packageUri);
458 435
459 expect(fileFileUri.path, path); 436 expect(fileFileUri.path, path);
460 expect(fileFileUri.uri, fileUri); 437 expect(fileFileUri.uri, fileUri);
461 438
462 // The file with the `package:` style URI is canonical, and is the first. 439 // The file with the `package:` style URI is canonical, and is the first.
463 var files = fileSystemState.getFilesForPath(path); 440 var files = fileSystemState.getFilesForPath(path);
464 expect(files, [filePackageUri, fileFileUri]); 441 expect(files, [filePackageUri, fileFileUri]);
465 } 442 }
466 443
444 test_hasUri() {
445 Uri uri = Uri.parse('package:aaa/foo.dart');
446 String templatePath = _p('/aaa/lib/foo.dart');
447 String generatedPath = _p('/generated/aaa/lib/foo.dart');
448
449 Source generatedSource = new _SourceMock();
450 when(generatedSource.fullName).thenReturn(generatedPath);
451 when(generatedSource.uri).thenReturn(uri);
452
453 when(generatedUriResolver.resolveAbsolute(uri, uri))
454 .thenReturn(generatedSource);
455
456 expect(fileSystemState.hasUri(templatePath), isFalse);
457 expect(fileSystemState.hasUri(generatedPath), isTrue);
458 }
459
467 test_referencedNames() { 460 test_referencedNames() {
468 String path = _p('/aaa/lib/a.dart'); 461 String path = _p('/aaa/lib/a.dart');
469 provider.newFile( 462 provider.newFile(
470 path, 463 path,
471 r''' 464 r'''
472 A foo(B p) { 465 A foo(B p) {
473 foo(null); 466 foo(null);
474 C c = new C(p); 467 C c = new C(p);
475 return c; 468 return c;
476 } 469 }
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 String _p(String path) => provider.convertPath(path); 720 String _p(String path) => provider.convertPath(path);
728 721
729 static String _md5(String content) { 722 static String _md5(String content) {
730 return hex.encode(md5.convert(UTF8.encode(content)).bytes); 723 return hex.encode(md5.convert(UTF8.encode(content)).bytes);
731 } 724 }
732 } 725 }
733 726
734 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {} 727 class _GeneratedUriResolverMock extends TypedMock implements UriResolver {}
735 728
736 class _SourceMock extends TypedMock implements Source {} 729 class _SourceMock extends TypedMock implements Source {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698