| 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/file_system/file_system.dart'; | 12 import 'package:analyzer/file_system/file_system.dart'; |
| 12 import 'package:analyzer/src/generated/ast.dart'; | |
| 13 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 16 import 'package:typed_mock/typed_mock.dart'; | 16 import 'package:typed_mock/typed_mock.dart'; |
| 17 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| 18 | 18 |
| 19 import '../analysis_abstract.dart'; | 19 import '../analysis_abstract.dart'; |
| 20 import '../utils.dart'; | 20 import '../utils.dart'; |
| 21 | 21 |
| 22 main() { | 22 main() { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 153 } |
| 154 { | 154 { |
| 155 await server.onAnalysisComplete; | 155 await server.onAnalysisComplete; |
| 156 // The overlay should have been propagated to both contexts, causing both | 156 // The overlay should have been propagated to both contexts, causing both |
| 157 // foo.dart and bar.dart to be reanalyzed and found to be free of errors. | 157 // foo.dart and bar.dart to be reanalyzed and found to be free of errors. |
| 158 expect(filesErrors[fooPath], isEmpty); | 158 expect(filesErrors[fooPath], isEmpty); |
| 159 expect(filesErrors[barPath], isEmpty); | 159 expect(filesErrors[barPath], isEmpty); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 test_overlay_addPreviouslyImported() async { |
| 164 Folder project = resourceProvider.newFolder('/project'); |
| 165 handleSuccessfulRequest( |
| 166 new AnalysisSetAnalysisRootsParams([project.path], []).toRequest('0')); |
| 167 |
| 168 server.updateContent('1', |
| 169 {'/project/main.dart': new AddContentOverlay('import "target.dart";')}); |
| 170 await server.onAnalysisComplete; |
| 171 expect(filesErrors, { |
| 172 '/project/main.dart': ["1: Target of URI does not exist: 'target.dart'"], |
| 173 '/project/target.dart': [] |
| 174 }); |
| 175 |
| 176 server.updateContent('1', |
| 177 {'/project/target.dart': new AddContentOverlay('import "none.dart";')}); |
| 178 await server.onAnalysisComplete; |
| 179 expect(filesErrors, { |
| 180 '/project/main.dart': ["1: Unused import"], |
| 181 '/project/target.dart': ["1: Target of URI does not exist: 'none.dart'"], |
| 182 '/project/none.dart': [] |
| 183 }); |
| 184 } |
| 185 |
| 163 test_overlayOnly() async { | 186 test_overlayOnly() async { |
| 164 String filePath = '/User/project1/test.dart'; | 187 String filePath = '/User/project1/test.dart'; |
| 165 Folder folder1 = resourceProvider.newFolder('/User/project1'); | 188 Folder folder1 = resourceProvider.newFolder('/User/project1'); |
| 166 Folder folder2 = resourceProvider.newFolder('/User/project2'); | 189 Folder folder2 = resourceProvider.newFolder('/User/project2'); |
| 167 Request request = | 190 Request request = |
| 168 new AnalysisSetAnalysisRootsParams([folder1.path, folder2.path], []) | 191 new AnalysisSetAnalysisRootsParams([folder1.path, folder2.path], []) |
| 169 .toRequest('0'); | 192 .toRequest('0'); |
| 170 handleSuccessfulRequest(request); | 193 handleSuccessfulRequest(request); |
| 171 // exactly 2 contexts | 194 // exactly 2 contexts |
| 172 expect(server.folderMap, hasLength(2)); | 195 expect(server.folderMap, hasLength(2)); |
| 173 AnalysisContext context1 = server.folderMap[folder1]; | 196 AnalysisContext context1 = server.folderMap[folder1]; |
| 174 AnalysisContext context2 = server.folderMap[folder2]; | 197 AnalysisContext context2 = server.folderMap[folder2]; |
| 175 // no sources | 198 // no sources |
| 176 expect(_getUserSources(context1), isEmpty); | 199 expect(_getUserSources(context1), isEmpty); |
| 177 expect(_getUserSources(context2), isEmpty); | 200 expect(_getUserSources(context2), isEmpty); |
| 178 // add an overlay - new Source in context1 | 201 // add an overlay - new Source in context1 |
| 179 server.updateContent('1', {filePath: new AddContentOverlay('')}); | 202 server.updateContent('1', {filePath: new AddContentOverlay('')}); |
| 180 { | 203 { |
| 181 List<Source> sources = _getUserSources(context1); | 204 List<Source> sources = _getUserSources(context1); |
| 182 expect(sources, hasLength(1)); | 205 expect(sources, hasLength(1)); |
| 183 expect(sources[0].fullName, filePath); | 206 expect(sources[0].fullName, filePath); |
| 184 } | 207 } |
| 185 expect(_getUserSources(context2), isEmpty); | 208 expect(_getUserSources(context2), isEmpty); |
| 186 // remove the overlay - no sources | 209 // remove the overlay - no sources |
| 187 server.updateContent('2', {filePath: new RemoveContentOverlay()}); | 210 server.updateContent('2', {filePath: new RemoveContentOverlay()}); |
| 188 expect(_getUserSources(context1), isEmpty); | 211 expect(_getUserSources(context1), isEmpty); |
| 189 expect(_getUserSources(context2), isEmpty); | 212 expect(_getUserSources(context2), isEmpty); |
| 190 } | 213 } |
| 191 | 214 |
| 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 | |
| 215 test_removeOverlay_incrementalChange() async { | 215 test_removeOverlay_incrementalChange() async { |
| 216 createProject(); | 216 createProject(); |
| 217 addTestFile('main() { print(1); }'); | 217 addTestFile('main() { print(1); }'); |
| 218 await server.onAnalysisComplete; | 218 await server.onAnalysisComplete; |
| 219 CompilationUnit unit = _getTestUnit(); | 219 CompilationUnit unit = _getTestUnit(); |
| 220 // add an overlay | 220 // add an overlay |
| 221 server.updateContent( | 221 server.updateContent( |
| 222 '1', {testFile: new AddContentOverlay('main() { print(2); }')}); | 222 '1', {testFile: new AddContentOverlay('main() { print(2); }')}); |
| 223 // it was an incremental change | 223 // it was an incremental change |
| 224 await server.onAnalysisComplete; | 224 await server.onAnalysisComplete; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 290 |
| 291 _ArgumentMatcher_CompilationUnit(this.file); | 291 _ArgumentMatcher_CompilationUnit(this.file); |
| 292 | 292 |
| 293 @override | 293 @override |
| 294 bool matches(arg) { | 294 bool matches(arg) { |
| 295 return arg is CompilationUnit && arg.element.source.fullName == file; | 295 return arg is CompilationUnit && arg.element.source.fullName == file; |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 | 298 |
| 299 class _MockIndex extends TypedMock implements Index {} | 299 class _MockIndex extends TypedMock implements Index {} |
| OLD | NEW |