Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_engine2; | 5 library test.services.src.search.search_engine2; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/index2/index2.dart'; | 9 import 'package:analysis_server/src/services/index2/index2.dart'; |
| 10 import 'package:analysis_server/src/services/search/search_engine.dart'; | 10 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 class A { | 121 class A { |
| 122 var test; // A | 122 var test; // A |
| 123 mainA() { | 123 mainA() { |
| 124 test(); // a-inv-r-nq | 124 test(); // a-inv-r-nq |
| 125 test = 1; // a-ref-r-nq | 125 test = 1; // a-ref-r-nq |
| 126 test += 2; // a-ref-r-nq | 126 test += 2; // a-ref-r-nq |
| 127 print(test); // a-ref-r-nq | 127 print(test); // a-ref-r-nq |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 main(A a, p) { | 130 main(A a, p) { |
| 131 a.test(); // a-inv-r-q | 131 print(a.test); // r |
| 132 a.test = 1; // a-ref-r-q | 132 a.test = 1; // r |
| 133 a.test += 2; // a-ref-r-q | 133 a.test += 2; // r |
| 134 print(a.test); // a-ref-r-q | 134 a.test(); // r |
| 135 p.test(); // p-inv-ur-q | 135 print(p.test); // ur |
| 136 p.test = 1; // p-ref-ur-q | 136 p.test = 1; // ur |
| 137 p.test += 2; // p-ref-ur-q | 137 p.test += 2; // ur |
| 138 print(p.test); // p-ref-ur-q | 138 p.test(); // ur |
| 139 } | 139 } |
| 140 '''); | 140 '''); |
| 141 Element main = findElement('main'); | 141 Element main = findElement('main'); |
| 142 var expected = [ | 142 var expected = [ |
| 143 _expectIdQ(main, MatchKind.REFERENCE, 'test(); // p-inv-ur-q'), | 143 _expectIdQU(main, MatchKind.READ, 'test); // ur'), |
| 144 _expectIdQ(main, MatchKind.REFERENCE, 'test = 1; // p-ref-ur-q'), | 144 _expectIdQU(main, MatchKind.WRITE, 'test = 1; // ur'), |
| 145 _expectIdQ(main, MatchKind.REFERENCE, 'test += 2; // p-ref-ur-q'), | 145 _expectIdQU(main, MatchKind.READ_WRITE, 'test += 2; // ur'), |
| 146 _expectIdQ(main, MatchKind.REFERENCE, 'test); // p-ref-ur-q'), | 146 _expectIdQU(main, MatchKind.INVOCATION, 'test(); // ur'), |
| 147 ]; | 147 ]; |
| 148 List<SearchMatch> matches = | 148 List<SearchMatch> matches = |
| 149 await searchEngine.searchMemberReferences('test'); | 149 await searchEngine.searchMemberReferences('test'); |
| 150 _assertMatches(matches, expected); | 150 _assertMatches(matches, expected); |
| 151 } | 151 } |
| 152 | 152 |
| 153 test_searchReferences_ClassElement() async { | 153 test_searchReferences_ClassElement() async { |
| 154 _indexTestUnit(''' | 154 _indexTestUnit(''' |
| 155 class A {} | 155 class A {} |
| 156 main(A p) { | 156 main(A p) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 // setter | 238 // setter |
| 239 field = 2; // ref-nq; | 239 field = 2; // ref-nq; |
| 240 this.field = 3; // ref-q; | 240 this.field = 3; // ref-q; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 '''); | 243 '''); |
| 244 FieldElement element = findElement('field'); | 244 FieldElement element = findElement('field'); |
| 245 Element main = findElement('main'); | 245 Element main = findElement('main'); |
| 246 Element fieldParameter = findElement('field', ElementKind.PARAMETER); | 246 Element fieldParameter = findElement('field', ElementKind.PARAMETER); |
| 247 var expected = [ | 247 var expected = [ |
| 248 _expectIdQ(fieldParameter, MatchKind.REFERENCE, 'field}'), | 248 _expectIdQ(fieldParameter, MatchKind.WRITE, 'field}'), |
| 249 _expectIdQ(main, MatchKind.REFERENCE, 'field: 1'), | 249 _expectIdQ(main, MatchKind.REFERENCE, 'field: 1'), |
| 250 _expectId(main, MatchKind.READ, 'field); // ref-nq'), | 250 _expectId(main, MatchKind.READ, 'field); // ref-nq'), |
| 251 _expectIdQ(main, MatchKind.READ, 'field); // ref-q'), | 251 _expectIdQ(main, MatchKind.READ, 'field); // ref-q'), |
| 252 _expectId(main, MatchKind.INVOCATION, 'field(); // inv-nq'), | 252 _expectId(main, MatchKind.INVOCATION, 'field(); // inv-nq'), |
| 253 _expectIdQ(main, MatchKind.INVOCATION, 'field(); // inv-q'), | 253 _expectIdQ(main, MatchKind.INVOCATION, 'field(); // inv-q'), |
| 254 _expectId(main, MatchKind.WRITE, 'field = 2; // ref-nq'), | 254 _expectId(main, MatchKind.WRITE, 'field = 2; // ref-nq'), |
| 255 _expectIdQ(main, MatchKind.WRITE, 'field = 3; // ref-q'), | 255 _expectIdQ(main, MatchKind.WRITE, 'field = 3; // ref-q'), |
| 256 ]; | 256 ]; |
| 257 await _verifyReferences(element, expected); | 257 await _verifyReferences(element, expected); |
| 258 } | 258 } |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 ExpectedMatch _expectId(Element element, MatchKind kind, String search, | 732 ExpectedMatch _expectId(Element element, MatchKind kind, String search, |
| 733 {int length, bool isResolved: true, bool isQualified: false}) { | 733 {int length, bool isResolved: true, bool isQualified: false}) { |
| 734 int offset = findOffset(search); | 734 int offset = findOffset(search); |
| 735 if (length == null) { | 735 if (length == null) { |
| 736 length = getLeadingIdentifierLength(search); | 736 length = getLeadingIdentifierLength(search); |
| 737 } | 737 } |
| 738 return new ExpectedMatch(element, kind, offset, length, | 738 return new ExpectedMatch(element, kind, offset, length, |
| 739 isResolved: isResolved, isQualified: isQualified); | 739 isResolved: isResolved, isQualified: isQualified); |
| 740 } | 740 } |
| 741 | 741 |
| 742 ExpectedMatch _expectIdQ(Element element, MatchKind kind, String search, | 742 ExpectedMatch _expectIdQ(Element element, MatchKind kind, String search, |
|
Brian Wilkerson
2016/03/11 18:14:03
nit: it might be good to document what 'Q' and 'QU
| |
| 743 {int length, bool isResolved: true}) { | |
| 744 return _expectId(element, kind, search, isQualified: true, length: length); | |
| 745 } | |
| 746 | |
| 747 ExpectedMatch _expectIdQU(Element element, MatchKind kind, String search, | |
| 743 {int length}) { | 748 {int length}) { |
| 744 return _expectId(element, kind, search, isQualified: true, length: length); | 749 return _expectId(element, kind, search, |
| 750 isQualified: true, isResolved: false, length: length); | |
| 745 } | 751 } |
| 746 | 752 |
| 747 void _indexTestUnit(String code) { | 753 void _indexTestUnit(String code) { |
| 748 resolveTestUnit(code); | 754 resolveTestUnit(code); |
| 749 index.indexUnit(testUnit); | 755 index.indexUnit(testUnit); |
| 750 } | 756 } |
| 751 | 757 |
| 752 Future _verifyReferences( | 758 Future _verifyReferences( |
| 753 Element element, List<ExpectedMatch> expectedMatches) async { | 759 Element element, List<ExpectedMatch> expectedMatches) async { |
| 754 List<SearchMatch> matches = await searchEngine.searchReferences(element); | 760 List<SearchMatch> matches = await searchEngine.searchReferences(element); |
| 755 _assertMatches(matches, expectedMatches); | 761 _assertMatches(matches, expectedMatches); |
| 756 expect(matches, hasLength(expectedMatches.length)); | 762 expect(matches, hasLength(expectedMatches.length)); |
| 757 } | 763 } |
| 758 | 764 |
| 759 static void _assertMatches( | 765 static void _assertMatches( |
| 760 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { | 766 List<SearchMatch> matches, List<ExpectedMatch> expectedMatches) { |
| 761 expect(matches, unorderedEquals(expectedMatches)); | 767 expect(matches, unorderedEquals(expectedMatches)); |
| 762 } | 768 } |
| 763 } | 769 } |
| OLD | NEW |