| OLD | NEW |
| 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.src.context.context_test; | 5 library test.src.context.context_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | |
| 9 | 8 |
| 10 import 'package:analyzer/src/cancelable_future.dart'; | 9 import 'package:analyzer/src/cancelable_future.dart'; |
| 11 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
| 12 import 'package:analyzer/src/context/context.dart'; | 11 import 'package:analyzer/src/context/context.dart'; |
| 13 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart' | 14 import 'package:analyzer/src/generated/engine.dart' |
| 16 show | 15 show |
| 17 AnalysisContext, | 16 AnalysisContext, |
| 18 AnalysisContextStatistics, | 17 AnalysisContextStatistics, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 31 import 'package:analyzer/src/generated/error.dart'; | 30 import 'package:analyzer/src/generated/error.dart'; |
| 32 import 'package:analyzer/src/generated/html.dart' as ht; | 31 import 'package:analyzer/src/generated/html.dart' as ht; |
| 33 import 'package:analyzer/src/generated/java_engine.dart'; | 32 import 'package:analyzer/src/generated/java_engine.dart'; |
| 34 import 'package:analyzer/src/generated/java_engine_io.dart'; | 33 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 35 import 'package:analyzer/src/generated/resolver.dart'; | 34 import 'package:analyzer/src/generated/resolver.dart'; |
| 36 import 'package:analyzer/src/generated/scanner.dart'; | 35 import 'package:analyzer/src/generated/scanner.dart'; |
| 37 import 'package:analyzer/src/generated/sdk.dart'; | 36 import 'package:analyzer/src/generated/sdk.dart'; |
| 38 import 'package:analyzer/src/generated/sdk_io.dart'; | 37 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 39 import 'package:analyzer/src/generated/source.dart'; | 38 import 'package:analyzer/src/generated/source.dart'; |
| 40 import 'package:analyzer/src/generated/source_io.dart'; | 39 import 'package:analyzer/src/generated/source_io.dart'; |
| 41 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | |
| 42 import 'package:analyzer/src/generated/testing/element_factory.dart'; | |
| 43 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | |
| 44 import 'package:analyzer/src/generated/utilities_dart.dart'; | |
| 45 import 'package:analyzer/src/plugin/engine_plugin.dart'; | 40 import 'package:analyzer/src/plugin/engine_plugin.dart'; |
| 46 import 'package:analyzer/task/dart.dart'; | |
| 47 import 'package:plugin/manager.dart'; | 41 import 'package:plugin/manager.dart'; |
| 48 import 'package:unittest/unittest.dart'; | 42 import 'package:unittest/unittest.dart'; |
| 49 import 'package:watcher/src/utils.dart'; | 43 import 'package:watcher/src/utils.dart'; |
| 50 | 44 |
| 51 import '../../generated/engine_test.dart'; | 45 import '../../generated/engine_test.dart'; |
| 52 import '../../generated/test_support.dart'; | 46 import '../../generated/test_support.dart'; |
| 53 import '../../reflective_tests.dart'; | 47 import '../../reflective_tests.dart'; |
| 54 import '../mock_sdk.dart'; | 48 import '../mock_sdk.dart'; |
| 55 | 49 |
| 56 main() { | 50 main() { |
| 57 groupSep = ' | '; | 51 groupSep = ' | '; |
| 58 runReflectiveTests(AnalysisContextImplTest); | 52 runReflectiveTests(AnalysisContextImplTest); |
| 59 } | 53 } |
| 60 | 54 |
| 61 contextWithCore() { | 55 contextWithCore() { |
| 62 return new AnalysisContextForTests(); | 56 return new AnalysisContextForTests(); |
| 63 } | 57 } |
| 64 | 58 |
| 65 /** | 59 /** |
| 66 * An analysis context that has a fake SDK that is much smaller and faster for | 60 * An analysis context that has a fake SDK that is much smaller and faster for |
| 67 * testing purposes. | 61 * testing purposes. |
| 68 */ | 62 */ |
| 69 class AnalysisContextForTests extends AnalysisContextImpl { | 63 class AnalysisContextForTests extends AnalysisContextImpl { |
| 70 AnalysisContextForTests() { | 64 AnalysisContextForTests() { |
| 71 DartSdk sdk = new MockSdk(); | 65 DartSdk sdk = new MockSdk(); |
| 72 SourceFactory sourceFactory = | 66 SourceFactory sourceFactory = |
| 73 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); | 67 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]); |
| 74 this.sourceFactory = sourceFactory; | 68 this.sourceFactory = sourceFactory; |
| 75 // initWithCore(); | |
| 76 } | 69 } |
| 77 | 70 |
| 78 @override | 71 @override |
| 79 void set analysisOptions(AnalysisOptions options) { | 72 void set analysisOptions(AnalysisOptions options) { |
| 80 AnalysisOptions currentOptions = analysisOptions; | 73 AnalysisOptions currentOptions = analysisOptions; |
| 81 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate != | 74 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate != |
| 82 options.analyzeFunctionBodiesPredicate || | 75 options.analyzeFunctionBodiesPredicate || |
| 83 currentOptions.generateImplicitErrors != | 76 currentOptions.generateImplicitErrors != |
| 84 options.generateImplicitErrors || | 77 options.generateImplicitErrors || |
| 85 currentOptions.generateSdkErrors != options.generateSdkErrors || | 78 currentOptions.generateSdkErrors != options.generateSdkErrors || |
| (...skipping 26 matching lines...) Expand all Loading... |
| 112 } | 105 } |
| 113 | 106 |
| 114 @override | 107 @override |
| 115 int getModificationStamp(Source source) { | 108 int getModificationStamp(Source source) { |
| 116 if (source.isInSystemLibrary) { | 109 if (source.isInSystemLibrary) { |
| 117 return sourceFactory.dartSdk.context.getModificationStamp(source); | 110 return sourceFactory.dartSdk.context.getModificationStamp(source); |
| 118 } | 111 } |
| 119 return super.getModificationStamp(source); | 112 return super.getModificationStamp(source); |
| 120 } | 113 } |
| 121 | 114 |
| 122 /** | 115 // /** |
| 123 * Initialize the given analysis context with a fake core library already reso
lved. | 116 // * Set the analysis options, even if they would force re-analysis. This meth
od should only be |
| 124 * | 117 // * invoked before the fake SDK is initialized. |
| 125 * @param context the context to be initialized (not `null`) | 118 // * |
| 126 * @return the analysis context that was created | 119 // * @param options the analysis options to be set |
| 127 */ | 120 // */ |
| 128 void initWithCore() { | 121 // void _internalSetAnalysisOptions(AnalysisOptions options) { |
| 129 AnalysisContext coreContext = sourceFactory.dartSdk.context; | 122 // super.analysisOptions = options; |
| 130 // | 123 // } |
| 131 // dart:core | |
| 132 // | |
| 133 TestTypeProvider provider = new TestTypeProvider(); | |
| 134 typeProvider = provider; | |
| 135 CompilationUnitElementImpl coreUnit = | |
| 136 new CompilationUnitElementImpl("core.dart"); | |
| 137 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE); | |
| 138 coreContext.setContents(coreSource, ""); | |
| 139 coreUnit.source = coreSource; | |
| 140 ClassElementImpl proxyClassElement = ElementFactory.classElement2("_Proxy"); | |
| 141 coreUnit.types = <ClassElement>[ | |
| 142 provider.boolType.element, | |
| 143 provider.deprecatedType.element, | |
| 144 provider.doubleType.element, | |
| 145 provider.functionType.element, | |
| 146 provider.intType.element, | |
| 147 provider.iterableType.element, | |
| 148 provider.iteratorType.element, | |
| 149 provider.listType.element, | |
| 150 provider.mapType.element, | |
| 151 provider.nullType.element, | |
| 152 provider.numType.element, | |
| 153 provider.objectType.element, | |
| 154 proxyClassElement, | |
| 155 provider.stackTraceType.element, | |
| 156 provider.stringType.element, | |
| 157 provider.symbolType.element, | |
| 158 provider.typeType.element | |
| 159 ]; | |
| 160 coreUnit.functions = <FunctionElement>[ | |
| 161 ElementFactory.functionElement3("identical", provider.boolType.element, | |
| 162 <ClassElement>[ | |
| 163 provider.objectType.element, | |
| 164 provider.objectType.element | |
| 165 ], null), | |
| 166 ElementFactory.functionElement3("print", VoidTypeImpl.instance.element, | |
| 167 <ClassElement>[provider.objectType.element], null) | |
| 168 ]; | |
| 169 TopLevelVariableElement proxyTopLevelVariableElt = ElementFactory | |
| 170 .topLevelVariableElement3("proxy", true, false, proxyClassElement.type); | |
| 171 TopLevelVariableElement deprecatedTopLevelVariableElt = ElementFactory | |
| 172 .topLevelVariableElement3( | |
| 173 "deprecated", true, false, provider.deprecatedType); | |
| 174 coreUnit.accessors = <PropertyAccessorElement>[ | |
| 175 proxyTopLevelVariableElt.getter, | |
| 176 deprecatedTopLevelVariableElt.getter | |
| 177 ]; | |
| 178 coreUnit.topLevelVariables = <TopLevelVariableElement>[ | |
| 179 proxyTopLevelVariableElt, | |
| 180 deprecatedTopLevelVariableElt | |
| 181 ]; | |
| 182 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode( | |
| 183 coreContext, AstFactory.libraryIdentifier2(["dart", "core"])); | |
| 184 coreLibrary.definingCompilationUnit = coreUnit; | |
| 185 // | |
| 186 // dart:async | |
| 187 // | |
| 188 CompilationUnitElementImpl asyncUnit = | |
| 189 new CompilationUnitElementImpl("async.dart"); | |
| 190 Source asyncSource = sourceFactory.forUri(DartSdk.DART_ASYNC); | |
| 191 coreContext.setContents(asyncSource, ""); | |
| 192 asyncUnit.source = asyncSource; | |
| 193 // Future | |
| 194 ClassElementImpl futureElement = | |
| 195 ElementFactory.classElement2("Future", ["T"]); | |
| 196 InterfaceType futureType = futureElement.type; | |
| 197 // factory Future.value([value]) | |
| 198 ConstructorElementImpl futureConstructor = | |
| 199 ElementFactory.constructorElement2(futureElement, "value"); | |
| 200 futureConstructor.parameters = <ParameterElement>[ | |
| 201 ElementFactory.positionalParameter2("value", provider.dynamicType) | |
| 202 ]; | |
| 203 futureConstructor.factory = true; | |
| 204 (futureConstructor.type as FunctionTypeImpl).typeArguments = | |
| 205 futureElement.type.typeArguments; | |
| 206 futureElement.constructors = <ConstructorElement>[futureConstructor]; | |
| 207 // Future then(onValue(T value), { Function onError }); | |
| 208 List<ParameterElement> parameters = <ParameterElement>[ | |
| 209 ElementFactory.requiredParameter2( | |
| 210 "value", futureElement.typeParameters[0].type) | |
| 211 ]; | |
| 212 FunctionTypeAliasElementImpl aliasElement = | |
| 213 new FunctionTypeAliasElementImpl.forNode(null); | |
| 214 aliasElement.synthetic = true; | |
| 215 aliasElement.parameters = parameters; | |
| 216 aliasElement.returnType = provider.dynamicType; | |
| 217 aliasElement.enclosingElement = asyncUnit; | |
| 218 FunctionTypeImpl aliasType = new FunctionTypeImpl.con2(aliasElement); | |
| 219 aliasElement.shareTypeParameters(futureElement.typeParameters); | |
| 220 aliasType.typeArguments = futureElement.type.typeArguments; | |
| 221 MethodElement thenMethod = ElementFactory.methodElementWithParameters( | |
| 222 "then", futureElement.type.typeArguments, futureType, [ | |
| 223 ElementFactory.requiredParameter2("onValue", aliasType), | |
| 224 ElementFactory.namedParameter2("onError", provider.functionType) | |
| 225 ]); | |
| 226 futureElement.methods = <MethodElement>[thenMethod]; | |
| 227 // Completer | |
| 228 ClassElementImpl completerElement = | |
| 229 ElementFactory.classElement2("Completer", ["T"]); | |
| 230 ConstructorElementImpl completerConstructor = | |
| 231 ElementFactory.constructorElement2(completerElement, null); | |
| 232 (completerConstructor.type as FunctionTypeImpl).typeArguments = | |
| 233 completerElement.type.typeArguments; | |
| 234 completerElement.constructors = <ConstructorElement>[completerConstructor]; | |
| 235 asyncUnit.types = <ClassElement>[ | |
| 236 completerElement, | |
| 237 futureElement, | |
| 238 ElementFactory.classElement2("Stream", ["T"]) | |
| 239 ]; | |
| 240 LibraryElementImpl asyncLibrary = new LibraryElementImpl.forNode( | |
| 241 coreContext, AstFactory.libraryIdentifier2(["dart", "async"])); | |
| 242 asyncLibrary.definingCompilationUnit = asyncUnit; | |
| 243 // | |
| 244 // dart:html | |
| 245 // | |
| 246 CompilationUnitElementImpl htmlUnit = | |
| 247 new CompilationUnitElementImpl("html_dartium.dart"); | |
| 248 Source htmlSource = sourceFactory.forUri(DartSdk.DART_HTML); | |
| 249 coreContext.setContents(htmlSource, ""); | |
| 250 htmlUnit.source = htmlSource; | |
| 251 ClassElementImpl elementElement = ElementFactory.classElement2("Element"); | |
| 252 InterfaceType elementType = elementElement.type; | |
| 253 ClassElementImpl canvasElement = | |
| 254 ElementFactory.classElement("CanvasElement", elementType); | |
| 255 ClassElementImpl contextElement = | |
| 256 ElementFactory.classElement2("CanvasRenderingContext"); | |
| 257 InterfaceType contextElementType = contextElement.type; | |
| 258 ClassElementImpl context2dElement = ElementFactory.classElement( | |
| 259 "CanvasRenderingContext2D", contextElementType); | |
| 260 canvasElement.methods = <MethodElement>[ | |
| 261 ElementFactory.methodElement( | |
| 262 "getContext", contextElementType, [provider.stringType]) | |
| 263 ]; | |
| 264 canvasElement.accessors = <PropertyAccessorElement>[ | |
| 265 ElementFactory.getterElement("context2D", false, context2dElement.type) | |
| 266 ]; | |
| 267 canvasElement.fields = canvasElement.accessors | |
| 268 .map((PropertyAccessorElement accessor) => accessor.variable) | |
| 269 .toList(); | |
| 270 ClassElementImpl documentElement = | |
| 271 ElementFactory.classElement("Document", elementType); | |
| 272 ClassElementImpl htmlDocumentElement = | |
| 273 ElementFactory.classElement("HtmlDocument", documentElement.type); | |
| 274 htmlDocumentElement.methods = <MethodElement>[ | |
| 275 ElementFactory.methodElement( | |
| 276 "query", elementType, <DartType>[provider.stringType]) | |
| 277 ]; | |
| 278 htmlUnit.types = <ClassElement>[ | |
| 279 ElementFactory.classElement("AnchorElement", elementType), | |
| 280 ElementFactory.classElement("BodyElement", elementType), | |
| 281 ElementFactory.classElement("ButtonElement", elementType), | |
| 282 canvasElement, | |
| 283 contextElement, | |
| 284 context2dElement, | |
| 285 ElementFactory.classElement("DivElement", elementType), | |
| 286 documentElement, | |
| 287 elementElement, | |
| 288 htmlDocumentElement, | |
| 289 ElementFactory.classElement("InputElement", elementType), | |
| 290 ElementFactory.classElement("SelectElement", elementType) | |
| 291 ]; | |
| 292 htmlUnit.functions = <FunctionElement>[ | |
| 293 ElementFactory.functionElement3("query", elementElement, | |
| 294 <ClassElement>[provider.stringType.element], ClassElement.EMPTY_LIST) | |
| 295 ]; | |
| 296 TopLevelVariableElementImpl document = ElementFactory | |
| 297 .topLevelVariableElement3( | |
| 298 "document", false, true, htmlDocumentElement.type); | |
| 299 htmlUnit.topLevelVariables = <TopLevelVariableElement>[document]; | |
| 300 htmlUnit.accessors = <PropertyAccessorElement>[document.getter]; | |
| 301 LibraryElementImpl htmlLibrary = new LibraryElementImpl.forNode( | |
| 302 coreContext, AstFactory.libraryIdentifier2(["dart", "dom", "html"])); | |
| 303 htmlLibrary.definingCompilationUnit = htmlUnit; | |
| 304 // | |
| 305 // dart:math | |
| 306 // | |
| 307 CompilationUnitElementImpl mathUnit = | |
| 308 new CompilationUnitElementImpl("math.dart"); | |
| 309 Source mathSource = sourceFactory.forUri("dart:math"); | |
| 310 coreContext.setContents(mathSource, ""); | |
| 311 mathUnit.source = mathSource; | |
| 312 FunctionElement cosElement = ElementFactory.functionElement3("cos", | |
| 313 provider.doubleType.element, <ClassElement>[provider.numType.element], | |
| 314 ClassElement.EMPTY_LIST); | |
| 315 TopLevelVariableElement ln10Element = ElementFactory | |
| 316 .topLevelVariableElement3("LN10", true, false, provider.doubleType); | |
| 317 TopLevelVariableElement piElement = ElementFactory.topLevelVariableElement3( | |
| 318 "PI", true, false, provider.doubleType); | |
| 319 ClassElementImpl randomElement = ElementFactory.classElement2("Random"); | |
| 320 randomElement.abstract = true; | |
| 321 ConstructorElementImpl randomConstructor = | |
| 322 ElementFactory.constructorElement2(randomElement, null); | |
| 323 randomConstructor.factory = true; | |
| 324 ParameterElementImpl seedParam = new ParameterElementImpl("seed", 0); | |
| 325 seedParam.parameterKind = ParameterKind.POSITIONAL; | |
| 326 seedParam.type = provider.intType; | |
| 327 randomConstructor.parameters = <ParameterElement>[seedParam]; | |
| 328 randomElement.constructors = <ConstructorElement>[randomConstructor]; | |
| 329 FunctionElement sinElement = ElementFactory.functionElement3("sin", | |
| 330 provider.doubleType.element, <ClassElement>[provider.numType.element], | |
| 331 ClassElement.EMPTY_LIST); | |
| 332 FunctionElement sqrtElement = ElementFactory.functionElement3("sqrt", | |
| 333 provider.doubleType.element, <ClassElement>[provider.numType.element], | |
| 334 ClassElement.EMPTY_LIST); | |
| 335 mathUnit.accessors = <PropertyAccessorElement>[ | |
| 336 ln10Element.getter, | |
| 337 piElement.getter | |
| 338 ]; | |
| 339 mathUnit.functions = <FunctionElement>[cosElement, sinElement, sqrtElement]; | |
| 340 mathUnit.topLevelVariables = <TopLevelVariableElement>[ | |
| 341 ln10Element, | |
| 342 piElement | |
| 343 ]; | |
| 344 mathUnit.types = <ClassElement>[randomElement]; | |
| 345 LibraryElementImpl mathLibrary = new LibraryElementImpl.forNode( | |
| 346 coreContext, AstFactory.libraryIdentifier2(["dart", "math"])); | |
| 347 mathLibrary.definingCompilationUnit = mathUnit; | |
| 348 // | |
| 349 // Set empty sources for the rest of the libraries. | |
| 350 // | |
| 351 Source source = sourceFactory.forUri("dart:_interceptors"); | |
| 352 coreContext.setContents(source, ""); | |
| 353 source = sourceFactory.forUri("dart:_js_helper"); | |
| 354 coreContext.setContents(source, ""); | |
| 355 // | |
| 356 // Record the elements. | |
| 357 // | |
| 358 HashMap<Source, LibraryElement> elementMap = | |
| 359 new HashMap<Source, LibraryElement>(); | |
| 360 elementMap[coreSource] = coreLibrary; | |
| 361 elementMap[asyncSource] = asyncLibrary; | |
| 362 elementMap[htmlSource] = htmlLibrary; | |
| 363 elementMap[mathSource] = mathLibrary; | |
| 364 recordLibraryElements(elementMap); | |
| 365 elementMap.forEach((Source librarySource, LibraryElement library) { | |
| 366 CompilationUnit unit = new CompilationUnit(null, null, null, null, null); | |
| 367 unit.element = library.definingCompilationUnit; | |
| 368 CacheEntry entry = getCacheEntry(librarySource); | |
| 369 entry.setValue(PARSED_UNIT, unit, TargetedResult.EMPTY_LIST, null); | |
| 370 }); | |
| 371 } | |
| 372 | |
| 373 /** | |
| 374 * Set the analysis options, even if they would force re-analysis. This method
should only be | |
| 375 * invoked before the fake SDK is initialized. | |
| 376 * | |
| 377 * @param options the analysis options to be set | |
| 378 */ | |
| 379 void _internalSetAnalysisOptions(AnalysisOptions options) { | |
| 380 super.analysisOptions = options; | |
| 381 } | |
| 382 } | 124 } |
| 383 | 125 |
| 384 @reflectiveTest | 126 @reflectiveTest |
| 385 class AnalysisContextImplTest extends EngineTestCase { | 127 class AnalysisContextImplTest extends EngineTestCase { |
| 386 /** | 128 /** |
| 387 * An analysis context whose source factory is [sourceFactory]. | 129 * An analysis context whose source factory is [sourceFactory]. |
| 388 */ | 130 */ |
| 389 AnalysisContextImpl _context; | 131 AnalysisContextImpl _context; |
| 390 | 132 |
| 391 /** | 133 /** |
| 392 * The source factory associated with the analysis [context]. | 134 * The source factory associated with the analysis [context]. |
| 393 */ | 135 */ |
| 394 SourceFactory _sourceFactory; | 136 SourceFactory _sourceFactory; |
| 395 | 137 |
| 396 void fail_applyChanges_empty() { | 138 void fail_applyChanges_empty() { |
| 397 _context.applyChanges(new ChangeSet()); | 139 _context.applyChanges(new ChangeSet()); |
| 398 expect(_context.performAnalysisTask().changeNotices, isNull); | 140 expect(_context.performAnalysisTask().changeNotices, isNull); |
| 399 // This test appears to be flaky. If it is named "test_" it fails, if it's | 141 // This test appears to be flaky. If it is named "test_" it fails, if it's |
| 400 // named "fail_" it doesn't fail. I'm guessing that it's dependent on some | 142 // named "fail_" it doesn't fail. I'm guessing that it's dependent on |
| 401 // other test being run (or not). | 143 // whether some other test is run. |
| 402 fail('Should have failed'); | 144 fail('Should have failed'); |
| 403 } | 145 } |
| 404 | 146 |
| 405 void fail_applyChanges_overriddenSource() { | 147 void fail_applyChanges_overriddenSource() { |
| 406 // Note: addSource adds the source to the contentCache. | 148 // Note: addSource adds the source to the contentCache. |
| 407 Source source = _addSource("/test.dart", "library test;"); | 149 Source source = _addSource("/test.dart", "library test;"); |
| 408 _context.computeErrors(source); | 150 _context.computeErrors(source); |
| 409 while (!_context.sourcesNeedingProcessing.isEmpty) { | 151 while (!_context.sourcesNeedingProcessing.isEmpty) { |
| 410 _context.performAnalysisTask(); | 152 _context.performAnalysisTask(); |
| 411 } | 153 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 259 } |
| 518 | 260 |
| 519 void fail_computeHtmlElement_valid() { | 261 void fail_computeHtmlElement_valid() { |
| 520 Source source = _addSource("/test.html", "<html></html>"); | 262 Source source = _addSource("/test.html", "<html></html>"); |
| 521 HtmlElement element = _context.computeHtmlElement(source); | 263 HtmlElement element = _context.computeHtmlElement(source); |
| 522 expect(element, isNotNull); | 264 expect(element, isNotNull); |
| 523 expect(_context.computeHtmlElement(source), same(element)); | 265 expect(_context.computeHtmlElement(source), same(element)); |
| 524 } | 266 } |
| 525 | 267 |
| 526 void fail_computeImportedLibraries_none() { | 268 void fail_computeImportedLibraries_none() { |
| 269 // This is failing because computeImportedLibraries now always includes |
| 270 // dart:core, and we don't have any way of knowing whether it was explicit. |
| 527 Source source = _addSource("/test.dart", "library test;"); | 271 Source source = _addSource("/test.dart", "library test;"); |
| 528 expect(_context.computeImportedLibraries(source), hasLength(0)); | 272 expect(_context.computeImportedLibraries(source), hasLength(0)); |
| 529 } | 273 } |
| 530 | 274 |
| 531 void fail_computeImportedLibraries_some() { | 275 void fail_computeImportedLibraries_some() { |
| 276 // This is failing because computeImportedLibraries now always includes |
| 277 // dart:core, and we don't have any way of knowing whether it was explicit. |
| 532 // addSource("/lib1.dart", "library lib1;"); | 278 // addSource("/lib1.dart", "library lib1;"); |
| 533 // addSource("/lib2.dart", "library lib2;"); | 279 // addSource("/lib2.dart", "library lib2;"); |
| 534 Source source = _addSource( | 280 Source source = _addSource( |
| 535 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); | 281 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); |
| 536 expect(_context.computeImportedLibraries(source), hasLength(2)); | 282 expect(_context.computeImportedLibraries(source), hasLength(2)); |
| 537 } | 283 } |
| 538 | 284 |
| 539 void fail_computeKindOf_html() { | 285 void test_computeKindOf_html() { |
| 540 Source source = _addSource("/test.html", ""); | 286 Source source = _addSource("/test.html", ""); |
| 541 expect(_context.computeKindOf(source), same(SourceKind.HTML)); | 287 expect(_context.computeKindOf(source), same(SourceKind.HTML)); |
| 542 } | 288 } |
| 543 | 289 |
| 544 void fail_computeResolvableCompilationUnit_dart_exception() { | 290 void fail_computeResolvableCompilationUnit_dart_exception() { |
| 545 TestSource source = _addSourceWithException("/test.dart"); | 291 TestSource source = _addSourceWithException("/test.dart"); |
| 546 try { | 292 try { |
| 547 _context.computeResolvableCompilationUnit(source); | 293 _context.computeResolvableCompilationUnit(source); |
| 548 fail("Expected AnalysisException"); | 294 fail("Expected AnalysisException"); |
| 549 } on AnalysisException { | 295 } on AnalysisException { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 349 |
| 604 Future fail_computeResolvedCompilationUnitAsync_unrelatedLibrary() { | 350 Future fail_computeResolvedCompilationUnitAsync_unrelatedLibrary() { |
| 605 _context = contextWithCore(); | 351 _context = contextWithCore(); |
| 606 _sourceFactory = _context.sourceFactory; | 352 _sourceFactory = _context.sourceFactory; |
| 607 Source librarySource = _addSource("/lib.dart", "library lib;"); | 353 Source librarySource = _addSource("/lib.dart", "library lib;"); |
| 608 Source partSource = _addSource("/part.dart", "part of foo;"); | 354 Source partSource = _addSource("/part.dart", "part of foo;"); |
| 609 bool completed = false; | 355 bool completed = false; |
| 610 _context | 356 _context |
| 611 .computeResolvedCompilationUnitAsync(partSource, librarySource) | 357 .computeResolvedCompilationUnitAsync(partSource, librarySource) |
| 612 .then((_) { | 358 .then((_) { |
| 613 // TODO(brianwilkerson) Uncomment the line below (and figure out why | 359 fail('Expected resolution to fail'); |
| 614 // invoking 'fail' directly causes a failing test to fail. | |
| 615 //fail('Expected resolution to fail'); | |
| 616 }, onError: (e) { | 360 }, onError: (e) { |
| 617 expect(e, new isInstanceOf<AnalysisNotScheduledError>()); | 361 expect(e, new isInstanceOf<AnalysisNotScheduledError>()); |
| 618 completed = true; | 362 completed = true; |
| 619 }); | 363 }); |
| 620 return pumpEventQueue().then((_) { | 364 return pumpEventQueue().then((_) { |
| 621 expect(completed, isFalse); | 365 expect(completed, isFalse); |
| 622 _performPendingAnalysisTasks(); | 366 _performPendingAnalysisTasks(); |
| 623 }).then((_) => pumpEventQueue()).then((_) { | 367 }).then((_) => pumpEventQueue()).then((_) { |
| 624 expect(completed, isTrue); | 368 expect(completed, isTrue); |
| 625 }); | 369 }); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 void fail_getHtmlSources() { | 505 void fail_getHtmlSources() { |
| 762 List<Source> sources = _context.htmlSources; | 506 List<Source> sources = _context.htmlSources; |
| 763 expect(sources, hasLength(0)); | 507 expect(sources, hasLength(0)); |
| 764 Source source = _addSource("/test.html", ""); | 508 Source source = _addSource("/test.html", ""); |
| 765 _context.computeKindOf(source); | 509 _context.computeKindOf(source); |
| 766 sources = _context.htmlSources; | 510 sources = _context.htmlSources; |
| 767 expect(sources, hasLength(1)); | 511 expect(sources, hasLength(1)); |
| 768 expect(sources[0], source); | 512 expect(sources[0], source); |
| 769 } | 513 } |
| 770 | 514 |
| 771 void fail_getKindOf_html() { | 515 void test_getKindOf_html() { |
| 772 Source source = _addSource("/test.html", ""); | 516 Source source = _addSource("/test.html", ""); |
| 773 expect(_context.getKindOf(source), same(SourceKind.HTML)); | 517 expect(_context.getKindOf(source), same(SourceKind.HTML)); |
| 774 } | 518 } |
| 775 | 519 |
| 776 void fail_getLibrariesContaining() { | 520 void test_getLibrariesContaining() { |
| 777 _context = contextWithCore(); | 521 _context = contextWithCore(); |
| 778 _sourceFactory = _context.sourceFactory; | 522 _sourceFactory = _context.sourceFactory; |
| 779 Source librarySource = _addSource("/lib.dart", r''' | 523 Source librarySource = _addSource("/lib.dart", r''' |
| 780 library lib; | 524 library lib; |
| 781 part 'part.dart';'''); | 525 part 'part.dart';'''); |
| 782 Source partSource = _addSource("/part.dart", "part of lib;"); | 526 Source partSource = _addSource("/part.dart", "part of lib;"); |
| 783 _context.computeLibraryElement(librarySource); | 527 _context.computeLibraryElement(librarySource); |
| 784 List<Source> result = _context.getLibrariesContaining(librarySource); | 528 List<Source> result = _context.getLibrariesContaining(librarySource); |
| 785 expect(result, hasLength(1)); | 529 expect(result, hasLength(1)); |
| 786 expect(result[0], librarySource); | 530 expect(result[0], librarySource); |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 @override | 1120 @override |
| 1377 void tearDown() { | 1121 void tearDown() { |
| 1378 _context = null; | 1122 _context = null; |
| 1379 _sourceFactory = null; | 1123 _sourceFactory = null; |
| 1380 super.tearDown(); | 1124 super.tearDown(); |
| 1381 } | 1125 } |
| 1382 | 1126 |
| 1383 Future test_applyChanges_add() { | 1127 Future test_applyChanges_add() { |
| 1384 SourcesChangedListener listener = new SourcesChangedListener(); | 1128 SourcesChangedListener listener = new SourcesChangedListener(); |
| 1385 _context.onSourcesChanged.listen(listener.onData); | 1129 _context.onSourcesChanged.listen(listener.onData); |
| 1386 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | 1130 expect(_context.sourcesNeedingProcessing, isEmpty); |
| 1387 Source source = | 1131 Source source = |
| 1388 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); | 1132 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); |
| 1389 ChangeSet changeSet = new ChangeSet(); | 1133 ChangeSet changeSet = new ChangeSet(); |
| 1390 changeSet.addedSource(source); | 1134 changeSet.addedSource(source); |
| 1391 _context.applyChanges(changeSet); | 1135 _context.applyChanges(changeSet); |
| 1392 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | 1136 expect(_context.sourcesNeedingProcessing, contains(source)); |
| 1393 return pumpEventQueue().then((_) { | 1137 return pumpEventQueue().then((_) { |
| 1394 listener.assertEvent(wereSourcesAdded: true); | 1138 listener.assertEvent(wereSourcesAdded: true); |
| 1395 listener.assertNoMoreEvents(); | 1139 listener.assertNoMoreEvents(); |
| 1396 }); | 1140 }); |
| 1397 } | 1141 } |
| 1398 | 1142 |
| 1399 Future test_applyChanges_change() { | 1143 Future test_applyChanges_change() { |
| 1400 SourcesChangedListener listener = new SourcesChangedListener(); | 1144 SourcesChangedListener listener = new SourcesChangedListener(); |
| 1401 _context.onSourcesChanged.listen(listener.onData); | 1145 _context.onSourcesChanged.listen(listener.onData); |
| 1402 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | 1146 expect(_context.sourcesNeedingProcessing, isEmpty); |
| 1403 Source source = | 1147 Source source = |
| 1404 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); | 1148 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); |
| 1405 ChangeSet changeSet1 = new ChangeSet(); | 1149 ChangeSet changeSet1 = new ChangeSet(); |
| 1406 changeSet1.addedSource(source); | 1150 changeSet1.addedSource(source); |
| 1407 _context.applyChanges(changeSet1); | 1151 _context.applyChanges(changeSet1); |
| 1408 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | 1152 expect(_context.sourcesNeedingProcessing, contains(source)); |
| 1409 Source source2 = | 1153 Source source2 = |
| 1410 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart")); | 1154 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart")); |
| 1411 ChangeSet changeSet2 = new ChangeSet(); | 1155 ChangeSet changeSet2 = new ChangeSet(); |
| 1412 changeSet2.addedSource(source2); | 1156 changeSet2.addedSource(source2); |
| 1413 changeSet2.changedSource(source); | 1157 changeSet2.changedSource(source); |
| 1414 _context.applyChanges(changeSet2); | 1158 _context.applyChanges(changeSet2); |
| 1415 return pumpEventQueue().then((_) { | 1159 return pumpEventQueue().then((_) { |
| 1416 listener.assertEvent(wereSourcesAdded: true); | 1160 listener.assertEvent(wereSourcesAdded: true); |
| 1417 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | 1161 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
| 1418 listener.assertNoMoreEvents(); | 1162 listener.assertNoMoreEvents(); |
| 1419 }); | 1163 }); |
| 1420 } | 1164 } |
| 1421 | 1165 |
| 1422 Future test_applyChanges_change_content() { | 1166 Future test_applyChanges_change_content() { |
| 1423 SourcesChangedListener listener = new SourcesChangedListener(); | 1167 SourcesChangedListener listener = new SourcesChangedListener(); |
| 1424 _context.onSourcesChanged.listen(listener.onData); | 1168 _context.onSourcesChanged.listen(listener.onData); |
| 1425 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | 1169 expect(_context.sourcesNeedingProcessing, isEmpty); |
| 1426 Source source = | 1170 Source source = |
| 1427 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); | 1171 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); |
| 1428 ChangeSet changeSet1 = new ChangeSet(); | 1172 ChangeSet changeSet1 = new ChangeSet(); |
| 1429 changeSet1.addedSource(source); | 1173 changeSet1.addedSource(source); |
| 1430 _context.applyChanges(changeSet1); | 1174 _context.applyChanges(changeSet1); |
| 1431 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | 1175 expect(_context.sourcesNeedingProcessing, contains(source)); |
| 1432 Source source2 = | 1176 Source source2 = |
| 1433 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart")); | 1177 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart")); |
| 1434 ChangeSet changeSet2 = new ChangeSet(); | 1178 ChangeSet changeSet2 = new ChangeSet(); |
| 1435 changeSet2.addedSource(source2); | 1179 changeSet2.addedSource(source2); |
| 1436 changeSet2.changedContent(source, 'library test;'); | 1180 changeSet2.changedContent(source, 'library test;'); |
| 1437 _context.applyChanges(changeSet2); | 1181 _context.applyChanges(changeSet2); |
| 1438 return pumpEventQueue().then((_) { | 1182 return pumpEventQueue().then((_) { |
| 1439 listener.assertEvent(wereSourcesAdded: true); | 1183 listener.assertEvent(wereSourcesAdded: true); |
| 1440 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | 1184 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
| 1441 listener.assertNoMoreEvents(); | 1185 listener.assertNoMoreEvents(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1502 listener.assertEvent(changedSources: [partSource]); | 1246 listener.assertEvent(changedSources: [partSource]); |
| 1503 listener.assertEvent(changedSources: [librarySource]); | 1247 listener.assertEvent(changedSources: [librarySource]); |
| 1504 listener.assertEvent(changedSources: [partSource]); | 1248 listener.assertEvent(changedSources: [partSource]); |
| 1505 listener.assertNoMoreEvents(); | 1249 listener.assertNoMoreEvents(); |
| 1506 }); | 1250 }); |
| 1507 } | 1251 } |
| 1508 | 1252 |
| 1509 Future test_applyChanges_change_range() { | 1253 Future test_applyChanges_change_range() { |
| 1510 SourcesChangedListener listener = new SourcesChangedListener(); | 1254 SourcesChangedListener listener = new SourcesChangedListener(); |
| 1511 _context.onSourcesChanged.listen(listener.onData); | 1255 _context.onSourcesChanged.listen(listener.onData); |
| 1512 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | 1256 expect(_context.sourcesNeedingProcessing, isEmpty); |
| 1513 Source source = | 1257 Source source = |
| 1514 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); | 1258 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); |
| 1515 ChangeSet changeSet1 = new ChangeSet(); | 1259 ChangeSet changeSet1 = new ChangeSet(); |
| 1516 changeSet1.addedSource(source); | 1260 changeSet1.addedSource(source); |
| 1517 _context.applyChanges(changeSet1); | 1261 _context.applyChanges(changeSet1); |
| 1518 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | 1262 expect(_context.sourcesNeedingProcessing, contains(source)); |
| 1519 Source source2 = | 1263 Source source2 = |
| 1520 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart")); | 1264 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart")); |
| 1521 ChangeSet changeSet2 = new ChangeSet(); | 1265 ChangeSet changeSet2 = new ChangeSet(); |
| 1522 changeSet2.addedSource(source2); | 1266 changeSet2.addedSource(source2); |
| 1523 changeSet2.changedRange(source, 'library test;', 0, 0, 13); | 1267 changeSet2.changedRange(source, 'library test;', 0, 0, 13); |
| 1524 _context.applyChanges(changeSet2); | 1268 _context.applyChanges(changeSet2); |
| 1525 return pumpEventQueue().then((_) { | 1269 return pumpEventQueue().then((_) { |
| 1526 listener.assertEvent(wereSourcesAdded: true); | 1270 listener.assertEvent(wereSourcesAdded: true); |
| 1527 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | 1271 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
| 1528 listener.assertNoMoreEvents(); | 1272 listener.assertNoMoreEvents(); |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2273 } | 2017 } |
| 2274 | 2018 |
| 2275 void test_setSourceFactory() { | 2019 void test_setSourceFactory() { |
| 2276 expect(_context.sourceFactory, _sourceFactory); | 2020 expect(_context.sourceFactory, _sourceFactory); |
| 2277 SourceFactory factory = new SourceFactory([]); | 2021 SourceFactory factory = new SourceFactory([]); |
| 2278 _context.sourceFactory = factory; | 2022 _context.sourceFactory = factory; |
| 2279 expect(_context.sourceFactory, factory); | 2023 expect(_context.sourceFactory, factory); |
| 2280 } | 2024 } |
| 2281 | 2025 |
| 2282 void test_updateAnalysis() { | 2026 void test_updateAnalysis() { |
| 2283 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | 2027 expect(_context.sourcesNeedingProcessing, isEmpty); |
| 2284 Source source = | 2028 Source source = |
| 2285 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); | 2029 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); |
| 2286 AnalysisDelta delta = new AnalysisDelta(); | 2030 AnalysisDelta delta = new AnalysisDelta(); |
| 2287 delta.setAnalysisLevel(source, AnalysisLevel.ALL); | 2031 delta.setAnalysisLevel(source, AnalysisLevel.ALL); |
| 2288 _context.applyAnalysisDelta(delta); | 2032 _context.applyAnalysisDelta(delta); |
| 2289 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | 2033 expect(_context.sourcesNeedingProcessing, contains(source)); |
| 2290 delta = new AnalysisDelta(); | 2034 delta = new AnalysisDelta(); |
| 2291 delta.setAnalysisLevel(source, AnalysisLevel.NONE); | 2035 delta.setAnalysisLevel(source, AnalysisLevel.NONE); |
| 2292 _context.applyAnalysisDelta(delta); | 2036 _context.applyAnalysisDelta(delta); |
| 2293 expect(_context.sourcesNeedingProcessing.contains(source), isFalse); | 2037 expect(_context.sourcesNeedingProcessing.contains(source), isFalse); |
| 2294 } | 2038 } |
| 2295 | 2039 |
| 2296 Future xtest_computeResolvedCompilationUnitAsync() { | 2040 Future xtest_computeResolvedCompilationUnitAsync() { |
| 2297 _context = contextWithCore(); | 2041 _context = contextWithCore(); |
| 2298 _sourceFactory = _context.sourceFactory; | 2042 _sourceFactory = _context.sourceFactory; |
| 2299 Source source = _addSource("/lib.dart", "library lib;"); | 2043 Source source = _addSource("/lib.dart", "library lib;"); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 : super(name, UriKind.FILE_URI); | 2269 : super(name, UriKind.FILE_URI); |
| 2526 | 2270 |
| 2527 @override | 2271 @override |
| 2528 TimestampedData<String> get contents { | 2272 TimestampedData<String> get contents { |
| 2529 throw 'Read error'; | 2273 throw 'Read error'; |
| 2530 } | 2274 } |
| 2531 | 2275 |
| 2532 @override | 2276 @override |
| 2533 bool exists() => true; | 2277 bool exists() => true; |
| 2534 } | 2278 } |
| OLD | NEW |