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

Side by Side Diff: pkg/analysis_server/test/services/search/search_engine_test.dart

Issue 2409403002: Issue 27542. Guard against CompilationUnitElement is null in SearchMatch.element getter. (Closed)
Patch Set: Created 4 years, 2 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/analysis_server/lib/src/services/search/search_engine.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.services.src.search.search_engine_internal; 5 library test.services.src.search.search_engine_internal;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/search/search_engine.dart'; 10 import 'package:analysis_server/src/services/search/search_engine.dart';
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 } 610 }
611 '''); 611 ''');
612 MethodMember method = findNodeElementAtString('m(); // ref'); 612 MethodMember method = findNodeElementAtString('m(); // ref');
613 Element mainElement = findElement('main'); 613 Element mainElement = findElement('main');
614 var expected = [ 614 var expected = [
615 _expectIdQ(mainElement, MatchKind.INVOCATION, 'm(); // ref') 615 _expectIdQ(mainElement, MatchKind.INVOCATION, 'm(); // ref')
616 ]; 616 ];
617 await _verifyReferences(method, expected); 617 await _verifyReferences(method, expected);
618 } 618 }
619 619
620 test_searchReferences_null_noUnitElement() async {
621 _indexTestUnit('''
622 class A {
623 m() {}
624 }
625 main(A a) {
626 a.m();
627 }
628 ''');
629 MethodElement method = findElement('m');
630 List<SearchMatch> matches = await searchEngine.searchReferences(method);
631 expect(matches, hasLength(1));
632 // Set the source contents, so the element is invalidated.
633 context.setContents(testSource, '');
634 expect(matches.single.element, isNull);
635 }
636
620 test_searchReferences_ParameterElement_ofConstructor() async { 637 test_searchReferences_ParameterElement_ofConstructor() async {
621 _indexTestUnit(''' 638 _indexTestUnit('''
622 class C { 639 class C {
623 var f; 640 var f;
624 C({p}) : f = p + 1 { 641 C({p}) : f = p + 1 {
625 p = 2; 642 p = 2;
626 p += 3; 643 p += 3;
627 print(p); 644 print(p);
628 p(); 645 p();
629 } 646 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 List<SearchMatch> matches = await searchEngine.searchReferences(element); 945 List<SearchMatch> matches = await searchEngine.searchReferences(element);
929 _assertMatches(matches, expectedMatches); 946 _assertMatches(matches, expectedMatches);
930 expect(matches, hasLength(expectedMatches.length)); 947 expect(matches, hasLength(expectedMatches.length));
931 } 948 }
932 949
933 static void _assertMatches( 950 static void _assertMatches(
934 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { 951 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) {
935 expect(matches, unorderedEquals(expectedMatches)); 952 expect(matches, unorderedEquals(expectedMatches));
936 } 953 }
937 } 954 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/search/search_engine.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698