| 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'; |
| 11 import 'package:analyzer/dart/ast/ast.dart'; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
| 12 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 12 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; | 13 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
| 16 import 'package:test/test.dart'; | 17 import 'package:test/test.dart'; |
| 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 18 import 'package:typed_mock/typed_mock.dart'; | 19 import 'package:typed_mock/typed_mock.dart'; |
| 19 | 20 |
| 20 import '../analysis_abstract.dart'; | 21 import '../analysis_abstract.dart'; |
| 21 | 22 |
| 22 main() { | 23 main() { |
| 23 defineReflectiveSuite(() { | 24 defineReflectiveSuite(() { |
| 24 defineReflectiveTests(UpdateContentTest); | 25 defineReflectiveTests(UpdateContentTest); |
| 25 }); | 26 }); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 filesErrors.clear(); | 263 filesErrors.clear(); |
| 263 server.test_flushAstStructures(testFile); | 264 server.test_flushAstStructures(testFile); |
| 264 server.updateContent('2', { | 265 server.updateContent('2', { |
| 265 testFile: new ChangeContentOverlay([new SourceEdit(0, 4, 'main')]) | 266 testFile: new ChangeContentOverlay([new SourceEdit(0, 4, 'main')]) |
| 266 }); | 267 }); |
| 267 await server.onAnalysisComplete; | 268 await server.onAnalysisComplete; |
| 268 // errors should have been resent | 269 // errors should have been resent |
| 269 expect(filesErrors, isNotEmpty); | 270 expect(filesErrors, isNotEmpty); |
| 270 } | 271 } |
| 271 | 272 |
| 273 test_sentToPlugins() { |
| 274 String filePath = '/project/target.dart'; |
| 275 String fileContent = 'import "none.dart";'; |
| 276 // |
| 277 // Add |
| 278 // |
| 279 handleSuccessfulRequest(new AnalysisUpdateContentParams( |
| 280 <String, dynamic>{filePath: new AddContentOverlay(fileContent)}) |
| 281 .toRequest('0')); |
| 282 plugin.AnalysisUpdateContentParams params = |
| 283 pluginManager.analysisUpdateContentParams; |
| 284 expect(params, isNotNull); |
| 285 Map<String, dynamic> files = params.files; |
| 286 expect(files, hasLength(1)); |
| 287 Object overlay = files[filePath]; |
| 288 expect(overlay, new isInstanceOf<plugin.AddContentOverlay>()); |
| 289 plugin.AddContentOverlay addOverlay = overlay; |
| 290 expect(addOverlay.content, fileContent); |
| 291 // |
| 292 // Change |
| 293 // |
| 294 pluginManager.analysisUpdateContentParams = null; |
| 295 handleSuccessfulRequest(new AnalysisUpdateContentParams(<String, dynamic>{ |
| 296 filePath: new ChangeContentOverlay( |
| 297 <SourceEdit>[new SourceEdit(8, 1, "'"), new SourceEdit(18, 1, "'")]) |
| 298 }).toRequest('1')); |
| 299 params = pluginManager.analysisUpdateContentParams; |
| 300 expect(params, isNotNull); |
| 301 files = params.files; |
| 302 expect(files, hasLength(1)); |
| 303 overlay = files[filePath]; |
| 304 expect(overlay, new isInstanceOf<plugin.ChangeContentOverlay>()); |
| 305 plugin.ChangeContentOverlay changeOverlay = overlay; |
| 306 expect(changeOverlay.edits, hasLength(2)); |
| 307 // |
| 308 // Remove |
| 309 // |
| 310 pluginManager.analysisUpdateContentParams = null; |
| 311 handleSuccessfulRequest(new AnalysisUpdateContentParams( |
| 312 <String, dynamic>{filePath: new RemoveContentOverlay()}) |
| 313 .toRequest('2')); |
| 314 params = pluginManager.analysisUpdateContentParams; |
| 315 expect(params, isNotNull); |
| 316 files = params.files; |
| 317 expect(files, hasLength(1)); |
| 318 overlay = files[filePath]; |
| 319 expect(overlay, new isInstanceOf<plugin.RemoveContentOverlay>()); |
| 320 } |
| 321 |
| 272 CompilationUnit _getTestUnit() { | 322 CompilationUnit _getTestUnit() { |
| 273 ContextSourcePair pair = server.getContextSourcePair(testFile); | 323 ContextSourcePair pair = server.getContextSourcePair(testFile); |
| 274 AnalysisContext context = pair.context; | 324 AnalysisContext context = pair.context; |
| 275 Source source = pair.source; | 325 Source source = pair.source; |
| 276 return context.getResolvedCompilationUnit2(source, source); | 326 return context.getResolvedCompilationUnit2(source, source); |
| 277 } | 327 } |
| 278 | 328 |
| 279 List<Source> _getUserSources(AnalysisContext context) { | 329 List<Source> _getUserSources(AnalysisContext context) { |
| 280 List<Source> sources = <Source>[]; | 330 List<Source> sources = <Source>[]; |
| 281 context.sources.forEach((source) { | 331 context.sources.forEach((source) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 294 | 344 |
| 295 @override | 345 @override |
| 296 bool matches(arg) { | 346 bool matches(arg) { |
| 297 return arg is CompilationUnit && | 347 return arg is CompilationUnit && |
| 298 resolutionMap.elementDeclaredByCompilationUnit(arg).source.fullName == | 348 resolutionMap.elementDeclaredByCompilationUnit(arg).source.fullName == |
| 299 file; | 349 file; |
| 300 } | 350 } |
| 301 } | 351 } |
| 302 | 352 |
| 303 class _MockIndex extends TypedMock implements Index {} | 353 class _MockIndex extends TypedMock implements Index {} |
| OLD | NEW |