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

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

Issue 396043003: Improve occurrences calculation - merge accessors, members. (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/lib/src/computer/computer_occurrences.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.domain.analysis.notification.occurrences; 5 library test.domain.analysis.notification.occurrences;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/computer/computer_occurrences.dart'; 10 import 'package:analysis_server/src/computer/computer_occurrences.dart';
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 * If [exists] is `false`, then fails if such [Occurrences] exists. 59 * If [exists] is `false`, then fails if such [Occurrences] exists.
60 */ 60 */
61 void findRegion(int offset, int length, [bool exists]) { 61 void findRegion(int offset, int length, [bool exists]) {
62 for (Occurrences occurrences in occurrencesList) { 62 for (Occurrences occurrences in occurrencesList) {
63 if (occurrences.length != length) { 63 if (occurrences.length != length) {
64 continue; 64 continue;
65 } 65 }
66 for (int occurrenceOffset in occurrences.offsets) { 66 for (int occurrenceOffset in occurrences.offsets) {
67 if (occurrenceOffset == offset) { 67 if (occurrenceOffset == offset) {
68 if (exists == false) { 68 if (exists == false) {
69 fail('Not expected to find (offset=$offset; length=$length) in\n' 69 fail(
70 '${occurrencesList.join('\n')}'); 70 'Not expected to find (offset=$offset; length=$length) in\n'
71 '${occurrencesList.join('\n')}');
71 } 72 }
72 testOccurences = occurrences; 73 testOccurences = occurrences;
73 return; 74 return;
74 } 75 }
75 } 76 }
76 } 77 }
77 if (exists == true) { 78 if (exists == true) {
78 fail('Expected to find (offset=$offset; length=$length) in\n' 79 fail(
79 '${occurrencesList.join('\n')}'); 80 'Expected to find (offset=$offset; length=$length) in\n'
81 '${occurrencesList.join('\n')}');
80 } 82 }
81 } 83 }
82 84
83 Future prepareOccurrences(then()) { 85 Future prepareOccurrences(then()) {
84 addAnalysisSubscription(AnalysisService.OCCURRENCES, testFile); 86 addAnalysisSubscription(AnalysisService.OCCURRENCES, testFile);
85 return waitForTasksFinished().then((_) { 87 return waitForTasksFinished().then((_) {
86 then(); 88 then();
87 }); 89 });
88 } 90 }
89 91
90 void processNotification(Notification notification) { 92 void processNotification(Notification notification) {
91 if (notification.event == ANALYSIS_OCCURRENCES) { 93 if (notification.event == ANALYSIS_OCCURRENCES) {
92 String file = notification.getParameter(FILE); 94 String file = notification.getParameter(FILE);
93 if (file == testFile) { 95 if (file == testFile) {
94 occurrencesList = <Occurrences>[]; 96 occurrencesList = <Occurrences>[];
95 List<Map<String, Object>> jsonList = notification.getParameter( 97 List<Map<String, Object>> jsonList =
96 OCCURRENCES); 98 notification.getParameter(OCCURRENCES);
97 for (Map<String, Object> json in jsonList) { 99 for (Map<String, Object> json in jsonList) {
98 occurrencesList.add(new Occurrences.fromJson(json)); 100 occurrencesList.add(new Occurrences.fromJson(json));
99 } 101 }
100 } 102 }
101 } 103 }
102 } 104 }
103 105
104 @override 106 @override
105 void setUp() { 107 void setUp() {
106 super.setUp(); 108 super.setUp();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 assertHasRegion('int a'); 140 assertHasRegion('int a');
139 expect(testOccurences.element.kind, ElementKind.CLASS); 141 expect(testOccurences.element.kind, ElementKind.CLASS);
140 expect(testOccurences.element.name, 'int'); 142 expect(testOccurences.element.name, 'int');
141 assertHasOffset('int a'); 143 assertHasOffset('int a');
142 assertHasOffset('int b'); 144 assertHasOffset('int b');
143 assertHasOffset('int c'); 145 assertHasOffset('int c');
144 assertHasOffset('int VVV'); 146 assertHasOffset('int VVV');
145 }); 147 });
146 } 148 }
147 149
150 test_field() {
151 addTestFile('''
152 class A {
153 int fff;
154 A(this.fff); // constructor
155 main() {
156 fff = 42;
157 print(fff); // print
158 }
159 }
160 ''');
161 return prepareOccurrences(() {
162 assertHasRegion('fff;');
163 expect(testOccurences.element.kind, ElementKind.FIELD);
164 assertHasOffset('fff); // constructor');
165 assertHasOffset('fff = 42;');
166 assertHasOffset('fff); // print');
167 });
168 }
169
148 test_localVariable() { 170 test_localVariable() {
149 addTestFile(''' 171 addTestFile('''
150 main() { 172 main() {
151 var vvv = 42; 173 var vvv = 42;
152 vvv += 5; 174 vvv += 5;
153 print(vvv); 175 print(vvv);
154 } 176 }
155 '''); 177 ''');
156 return prepareOccurrences(() { 178 return prepareOccurrences(() {
157 assertHasRegion('vvv ='); 179 assertHasRegion('vvv =');
158 expect(testOccurences.element.kind, ElementKind.LOCAL_VARIABLE); 180 expect(testOccurences.element.kind, ElementKind.LOCAL_VARIABLE);
159 expect(testOccurences.element.name, 'vvv'); 181 expect(testOccurences.element.name, 'vvv');
160 assertHasOffset('vvv = 42'); 182 assertHasOffset('vvv = 42');
161 assertHasOffset('vvv += 5'); 183 assertHasOffset('vvv += 5');
162 assertHasOffset('vvv);'); 184 assertHasOffset('vvv);');
163 }); 185 });
164 } 186 }
187
188 test_memberField() {
189 addTestFile('''
190 class A<T> {
191 T fff;
165 } 192 }
193 main() {
194 var a = new A<int>();
195 var b = new A<String>();
196 a.fff = 1;
197 b.fff = 2;
198 }
199 ''');
200 return prepareOccurrences(() {
201 assertHasRegion('fff;');
202 expect(testOccurences.element.kind, ElementKind.FIELD);
203 assertHasOffset('fff = 1;');
204 assertHasOffset('fff = 2;');
205 });
206 }
207
208 test_memberMethod() {
209 addTestFile('''
210 class A<T> {
211 T mmm() {}
212 }
213 main() {
214 var a = new A<int>();
215 var b = new A<String>();
216 a.mmm(); // a
217 b.mmm(); // b
218 }
219 ''');
220 return prepareOccurrences(() {
221 assertHasRegion('mmm() {}');
222 expect(testOccurences.element.kind, ElementKind.METHOD);
223 assertHasOffset('mmm(); // a');
224 assertHasOffset('mmm(); // b');
225 });
226 }
227
228 test_topLevelVariable() {
229 addTestFile('''
230 var VVV = 1;
231 main() {
232 VVV = 2;
233 print(VVV);
234 }
235 ''');
236 return prepareOccurrences(() {
237 assertHasRegion('VVV = 1;');
238 expect(testOccurences.element.kind, ElementKind.TOP_LEVEL_VARIABLE);
239 assertHasOffset('VVV = 2;');
240 assertHasOffset('VVV);');
241 });
242 }
243 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/computer/computer_occurrences.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698