| 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/src/analysis_server.dart'; |
| 7 import 'package:analysis_server/src/constants.dart'; | 8 import 'package:analysis_server/src/constants.dart'; |
| 8 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 9 import 'package:analysis_server/src/services/index/index.dart'; | 10 import 'package:analysis_server/src/services/index/index.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 import 'package:typed_mock/typed_mock.dart'; | 16 import 'package:typed_mock/typed_mock.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 17 import 'package:unittest/unittest.dart'; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 expect(sources, hasLength(1)); | 171 expect(sources, hasLength(1)); |
| 171 expect(sources[0].fullName, filePath); | 172 expect(sources[0].fullName, filePath); |
| 172 } | 173 } |
| 173 expect(_getUserSources(context2), isEmpty); | 174 expect(_getUserSources(context2), isEmpty); |
| 174 // remove the overlay - no sources | 175 // remove the overlay - no sources |
| 175 server.updateContent('2', {filePath: new RemoveContentOverlay()}); | 176 server.updateContent('2', {filePath: new RemoveContentOverlay()}); |
| 176 expect(_getUserSources(context1), isEmpty); | 177 expect(_getUserSources(context1), isEmpty); |
| 177 expect(_getUserSources(context2), isEmpty); | 178 expect(_getUserSources(context2), isEmpty); |
| 178 } | 179 } |
| 179 | 180 |
| 181 test_removeOverlay_incrementalChange() async { |
| 182 createProject(); |
| 183 addTestFile('main() { print(1); }'); |
| 184 await server.onAnalysisComplete; |
| 185 CompilationUnit unit = _getTestUnit(); |
| 186 // add an overlay |
| 187 server.updateContent( |
| 188 '1', {testFile: new AddContentOverlay('main() { print(2); }')}); |
| 189 // it was an incremental change |
| 190 await server.onAnalysisComplete; |
| 191 expect(_getTestUnit(), same(unit)); |
| 192 // remove overlay |
| 193 server.updateContent('2', {testFile: new RemoveContentOverlay()}); |
| 194 // it was an incremental change |
| 195 await server.onAnalysisComplete; |
| 196 expect(_getTestUnit(), same(unit)); |
| 197 } |
| 198 |
| 180 test_sendNoticesAfterNopChange() async { | 199 test_sendNoticesAfterNopChange() async { |
| 181 createProject(); | 200 createProject(); |
| 182 addTestFile(''); | 201 addTestFile(''); |
| 183 await server.onAnalysisComplete; | 202 await server.onAnalysisComplete; |
| 184 // add an overlay | 203 // add an overlay |
| 185 server.updateContent( | 204 server.updateContent( |
| 186 '1', {testFile: new AddContentOverlay('main() {} main() {}')}); | 205 '1', {testFile: new AddContentOverlay('main() {} main() {}')}); |
| 187 await server.onAnalysisComplete; | 206 await server.onAnalysisComplete; |
| 188 // clear errors and make a no-op change | 207 // clear errors and make a no-op change |
| 189 filesErrors.clear(); | 208 filesErrors.clear(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 207 filesErrors.clear(); | 226 filesErrors.clear(); |
| 208 server.test_flushAstStructures(testFile); | 227 server.test_flushAstStructures(testFile); |
| 209 server.updateContent('2', { | 228 server.updateContent('2', { |
| 210 testFile: new ChangeContentOverlay([new SourceEdit(0, 4, 'main')]) | 229 testFile: new ChangeContentOverlay([new SourceEdit(0, 4, 'main')]) |
| 211 }); | 230 }); |
| 212 await server.onAnalysisComplete; | 231 await server.onAnalysisComplete; |
| 213 // errors should have been resent | 232 // errors should have been resent |
| 214 expect(filesErrors, isNotEmpty); | 233 expect(filesErrors, isNotEmpty); |
| 215 } | 234 } |
| 216 | 235 |
| 236 CompilationUnit _getTestUnit() { |
| 237 ContextSourcePair pair = server.getContextSourcePair(testFile); |
| 238 AnalysisContext context = pair.context; |
| 239 Source source = pair.source; |
| 240 return context.getResolvedCompilationUnit2(source, source); |
| 241 } |
| 242 |
| 217 List<Source> _getUserSources(AnalysisContext context) { | 243 List<Source> _getUserSources(AnalysisContext context) { |
| 218 List<Source> sources = <Source>[]; | 244 List<Source> sources = <Source>[]; |
| 219 context.sources.forEach((source) { | 245 context.sources.forEach((source) { |
| 220 if (source.fullName.startsWith('/User/')) { | 246 if (source.fullName.startsWith('/User/')) { |
| 221 sources.add(source); | 247 sources.add(source); |
| 222 } | 248 } |
| 223 }); | 249 }); |
| 224 return sources; | 250 return sources; |
| 225 } | 251 } |
| 226 } | 252 } |
| 227 | 253 |
| 228 class _ArgumentMatcher_CompilationUnit extends ArgumentMatcher { | 254 class _ArgumentMatcher_CompilationUnit extends ArgumentMatcher { |
| 229 final String file; | 255 final String file; |
| 230 | 256 |
| 231 _ArgumentMatcher_CompilationUnit(this.file); | 257 _ArgumentMatcher_CompilationUnit(this.file); |
| 232 | 258 |
| 233 @override | 259 @override |
| 234 bool matches(arg) { | 260 bool matches(arg) { |
| 235 return arg is CompilationUnit && arg.element.source.fullName == file; | 261 return arg is CompilationUnit && arg.element.source.fullName == file; |
| 236 } | 262 } |
| 237 } | 263 } |
| 238 | 264 |
| 239 class _MockIndex extends TypedMock implements Index { | 265 class _MockIndex extends TypedMock implements Index { |
| 240 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 266 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 241 } | 267 } |
| OLD | NEW |