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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1681493005: Fix for recording 'null' as a defined element. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.test.src.task.dart_test; 5 library analyzer.test.src.task.dart_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 2222 matching lines...) Expand 10 before | Expand all | Expand 10 after
2233 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2233 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2234 computeResult(target, USED_IMPORTED_ELEMENTS, 2234 computeResult(target, USED_IMPORTED_ELEMENTS,
2235 matcher: isGatherUsedImportedElementsTask); 2235 matcher: isGatherUsedImportedElementsTask);
2236 usedElements = outputs[USED_IMPORTED_ELEMENTS]; 2236 usedElements = outputs[USED_IMPORTED_ELEMENTS];
2237 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); 2237 usedElementNames = usedElements.elements.map((e) => e.name).toSet();
2238 } 2238 }
2239 } 2239 }
2240 2240
2241 @reflectiveTest 2241 @reflectiveTest
2242 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { 2242 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest {
2243 List<Element> definedElements;
2244 Set<String> definedElementNames;
2243 UsedLocalElements usedElements; 2245 UsedLocalElements usedElements;
2244 Set<String> usedElementNames; 2246 Set<String> usedElementNames;
2245 2247
2246 test_perform_forPart_afterLibraryUpdate() { 2248 test_perform_forPart_afterLibraryUpdate() {
2247 Source libSource = newSource( 2249 Source libSource = newSource(
2248 '/my_lib.dart', 2250 '/my_lib.dart',
2249 ''' 2251 '''
2250 library my_lib; 2252 library my_lib;
2251 part 'my_part.dart'; 2253 part 'my_part.dart';
2252 foo() => null; 2254 foo() => null;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 Source source = newSource( 2299 Source source = newSource(
2298 '/test.dart', 2300 '/test.dart',
2299 r''' 2301 r'''
2300 main() { 2302 main() {
2301 var v1 = 1; 2303 var v1 = 1;
2302 var v2 = 2; 2304 var v2 = 2;
2303 print(v2); 2305 print(v2);
2304 }'''); 2306 }''');
2305 _computeUsedElements(source); 2307 _computeUsedElements(source);
2306 // validate 2308 // validate
2309 expect(definedElementNames, unorderedEquals(['main', 'v1', 'v2']));
2307 expect(usedElementNames, unorderedEquals(['v2'])); 2310 expect(usedElementNames, unorderedEquals(['v2']));
2308 } 2311 }
2309 2312
2310 test_perform_method() { 2313 test_perform_method() {
2311 Source source = newSource( 2314 Source source = newSource(
2312 '/test.dart', 2315 '/test.dart',
2313 r''' 2316 r'''
2314 class A { 2317 class A {
2315 _m1() {} 2318 _m1() {}
2316 _m2() {} 2319 _m2() {}
2317 } 2320 }
2318 2321
2319 main(A a, p) { 2322 main(A a, p) {
2320 a._m2(); 2323 a._m2();
2321 p._m3(); 2324 p._m3();
2322 } 2325 }
2323 '''); 2326 ''');
2324 _computeUsedElements(source); 2327 _computeUsedElements(source);
2325 // validate 2328 // validate
2329 expect(definedElementNames,
2330 unorderedEquals(['A', '_m1', '_m2', 'main', 'a', 'p']));
2326 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); 2331 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2']));
2327 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); 2332 expect(usedElements.members, unorderedEquals(['_m2', '_m3']));
2328 } 2333 }
2329 2334
2335 test_perform_unresolvedImportWithPrefix() {
2336 Source source = newSource(
2337 '/test.dart',
2338 r'''
2339 import 'x' as p;
2340 ''');
2341 _computeUsedElements(source);
2342 // validate
2343 expect(definedElementNames, isEmpty);
2344 expect(usedElementNames, isEmpty);
2345 }
2346
2330 void _computeUsedElements(Source source) { 2347 void _computeUsedElements(Source source) {
2331 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2348 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2332 computeResult(target, USED_LOCAL_ELEMENTS, 2349 computeResult(target, USED_LOCAL_ELEMENTS,
2333 matcher: isGatherUsedLocalElementsTask); 2350 matcher: isGatherUsedLocalElementsTask);
2351 definedElements = outputs[DEFINED_ELEMENTS];
2352 definedElementNames = definedElements.map((e) => e.name).toSet();
2334 usedElements = outputs[USED_LOCAL_ELEMENTS]; 2353 usedElements = outputs[USED_LOCAL_ELEMENTS];
2335 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); 2354 usedElementNames = usedElements.elements.map((e) => e.name).toSet();
2336 } 2355 }
2337 } 2356 }
2338 2357
2339 @reflectiveTest 2358 @reflectiveTest
2340 class GenerateHintsTaskTest extends _AbstractDartTaskTest { 2359 class GenerateHintsTaskTest extends _AbstractDartTaskTest {
2341 test_perform_bestPractices_missingReturn() { 2360 test_perform_bestPractices_missingReturn() {
2342 Source source = newSource( 2361 Source source = newSource(
2343 '/test.dart', 2362 '/test.dart',
(...skipping 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after
4938 /** 4957 /**
4939 * Fill [errorListener] with [result] errors in the current [task]. 4958 * Fill [errorListener] with [result] errors in the current [task].
4940 */ 4959 */
4941 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 4960 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
4942 List<AnalysisError> errors = task.outputs[result]; 4961 List<AnalysisError> errors = task.outputs[result];
4943 expect(errors, isNotNull, reason: result.name); 4962 expect(errors, isNotNull, reason: result.name);
4944 errorListener = new GatheringErrorListener(); 4963 errorListener = new GatheringErrorListener();
4945 errorListener.addAll(errors); 4964 errorListener.addAll(errors);
4946 } 4965 }
4947 } 4966 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698