OLD | NEW |
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 test.analysis.updateContent; | 5 library test.analysis.updateContent; |
6 | 6 |
7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
8 import 'package:analysis_server/src/analysis_server.dart'; | 8 import 'package:analysis_server/src/analysis_server.dart'; |
9 import 'package:analysis_server/src/constants.dart'; | 9 import 'package:analysis_server/src/constants.dart'; |
10 import 'package:analysis_server/src/services/index/index.dart'; | 10 import 'package:analysis_server/src/services/index/index.dart'; |
(...skipping 24 matching lines...) Expand all Loading... |
35 int navigationCount = 0; | 35 int navigationCount = 0; |
36 | 36 |
37 Index createIndex() { | 37 Index createIndex() { |
38 return new _MockIndex(); | 38 return new _MockIndex(); |
39 } | 39 } |
40 | 40 |
41 @override | 41 @override |
42 void processNotification(Notification notification) { | 42 void processNotification(Notification notification) { |
43 if (notification.event == ANALYSIS_ERRORS) { | 43 if (notification.event == ANALYSIS_ERRORS) { |
44 var decoded = new AnalysisErrorsParams.fromNotification(notification); | 44 var decoded = new AnalysisErrorsParams.fromNotification(notification); |
45 filesErrors[decoded.file] = decoded.errors; | 45 _format(AnalysisError e) => "${e.location.startLine}: ${e.message}"; |
| 46 filesErrors[decoded.file] = decoded.errors.map(_format).toList(); |
46 } | 47 } |
47 if (notification.event == ANALYSIS_NAVIGATION) { | 48 if (notification.event == ANALYSIS_NAVIGATION) { |
48 navigationCount++; | 49 navigationCount++; |
49 } | 50 } |
50 if (notification.event == SERVER_ERROR) { | 51 if (notification.event == SERVER_ERROR) { |
51 serverErrorCount++; | 52 serverErrorCount++; |
52 } | 53 } |
53 } | 54 } |
54 | 55 |
55 test_discardNotifications_onSourceChange() async { | 56 test_discardNotifications_onSourceChange() async { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 expect(sources, hasLength(1)); | 182 expect(sources, hasLength(1)); |
182 expect(sources[0].fullName, filePath); | 183 expect(sources[0].fullName, filePath); |
183 } | 184 } |
184 expect(_getUserSources(context2), isEmpty); | 185 expect(_getUserSources(context2), isEmpty); |
185 // remove the overlay - no sources | 186 // remove the overlay - no sources |
186 server.updateContent('2', {filePath: new RemoveContentOverlay()}); | 187 server.updateContent('2', {filePath: new RemoveContentOverlay()}); |
187 expect(_getUserSources(context1), isEmpty); | 188 expect(_getUserSources(context1), isEmpty); |
188 expect(_getUserSources(context2), isEmpty); | 189 expect(_getUserSources(context2), isEmpty); |
189 } | 190 } |
190 | 191 |
| 192 test_overlay_addPreviouslyImported() async { |
| 193 Folder project = resourceProvider.newFolder('/project'); |
| 194 handleSuccessfulRequest( |
| 195 new AnalysisSetAnalysisRootsParams([project.path], []).toRequest('0')); |
| 196 |
| 197 server.updateContent('1', |
| 198 {'/project/main.dart': new AddContentOverlay('import "target.dart";')}); |
| 199 await server.onAnalysisComplete; |
| 200 expect(filesErrors, { |
| 201 '/project/main.dart': ["1: Target of URI does not exist: 'target.dart'"], |
| 202 '/project/target.dart': [] |
| 203 }); |
| 204 |
| 205 server.updateContent('1', |
| 206 {'/project/target.dart': new AddContentOverlay('import "none.dart";')}); |
| 207 await server.onAnalysisComplete; |
| 208 expect(filesErrors, { |
| 209 '/project/main.dart': ["1: Unused import"], |
| 210 '/project/target.dart': ["1: Target of URI does not exist: 'none.dart'"], |
| 211 '/project/none.dart': [] |
| 212 }); |
| 213 } |
| 214 |
191 test_removeOverlay_incrementalChange() async { | 215 test_removeOverlay_incrementalChange() async { |
192 createProject(); | 216 createProject(); |
193 addTestFile('main() { print(1); }'); | 217 addTestFile('main() { print(1); }'); |
194 await server.onAnalysisComplete; | 218 await server.onAnalysisComplete; |
195 CompilationUnit unit = _getTestUnit(); | 219 CompilationUnit unit = _getTestUnit(); |
196 // add an overlay | 220 // add an overlay |
197 server.updateContent( | 221 server.updateContent( |
198 '1', {testFile: new AddContentOverlay('main() { print(2); }')}); | 222 '1', {testFile: new AddContentOverlay('main() { print(2); }')}); |
199 // it was an incremental change | 223 // it was an incremental change |
200 await server.onAnalysisComplete; | 224 await server.onAnalysisComplete; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 290 |
267 _ArgumentMatcher_CompilationUnit(this.file); | 291 _ArgumentMatcher_CompilationUnit(this.file); |
268 | 292 |
269 @override | 293 @override |
270 bool matches(arg) { | 294 bool matches(arg) { |
271 return arg is CompilationUnit && arg.element.source.fullName == file; | 295 return arg is CompilationUnit && arg.element.source.fullName == file; |
272 } | 296 } |
273 } | 297 } |
274 | 298 |
275 class _MockIndex extends TypedMock implements Index {} | 299 class _MockIndex extends TypedMock implements Index {} |
OLD | NEW |