Index: pkg/analyzer/test/src/context/context_test.dart |
diff --git a/pkg/analyzer/test/src/context/context_test.dart b/pkg/analyzer/test/src/context/context_test.dart |
index 06041b7887948a3b23dd5a3ef3dbbf4b1949c5d0..674b08499b2163e06962ce7f02f8c33c7ef9c6aa 100644 |
--- a/pkg/analyzer/test/src/context/context_test.dart |
+++ b/pkg/analyzer/test/src/context/context_test.dart |
@@ -59,21 +59,6 @@ class AnalysisContextImplTest extends AbstractContextTest { |
fail('Should have failed'); |
} |
- void test_applyChanges_overriddenSource() { |
- // Note: addSource adds the source to the contentCache. |
- Source source = addSource("/test.dart", "library test;"); |
- context.computeErrors(source); |
- while (!context.sourcesNeedingProcessing.isEmpty) { |
- context.performAnalysisTask(); |
- } |
- // Adding the source as a changedSource should have no effect since |
- // it is already overridden in the content cache. |
- ChangeSet changeSet = new ChangeSet(); |
- changeSet.changedSource(source); |
- context.applyChanges(changeSet); |
- expect(context.sourcesNeedingProcessing, hasLength(0)); |
- } |
- |
Future fail_applyChanges_remove() { |
SourcesChangedListener listener = new SourcesChangedListener(); |
context.onSourcesChanged.listen(listener.onData); |
@@ -140,29 +125,6 @@ import 'libB.dart';'''; |
}); |
} |
- void test_computeErrors_dart_none() { |
- Source source = addSource("/lib.dart", "library lib;"); |
- List<AnalysisError> errors = context.computeErrors(source); |
- expect(errors, hasLength(0)); |
- } |
- |
- void test_computeErrors_dart_part() { |
- Source librarySource = |
- addSource("/lib.dart", "library lib; part 'part.dart';"); |
- Source partSource = addSource("/part.dart", "part of 'lib';"); |
- context.parseCompilationUnit(librarySource); |
- List<AnalysisError> errors = context.computeErrors(partSource); |
- expect(errors, isNotNull); |
- expect(errors.length > 0, isTrue); |
- } |
- |
- void test_computeErrors_dart_some() { |
- Source source = addSource("/lib.dart", "library 'lib';"); |
- List<AnalysisError> errors = context.computeErrors(source); |
- expect(errors, isNotNull); |
- expect(errors.length > 0, isTrue); |
- } |
- |
void fail_computeErrors_html_none() { |
Source source = addSource("/test.html", "<html></html>"); |
List<AnalysisError> errors = context.computeErrors(source); |
@@ -176,17 +138,6 @@ import 'libB.dart';'''; |
expect(context.computeHtmlElement(source), same(element)); |
} |
- void test_computeImportedLibraries_none() { |
- Source source = addSource("/test.dart", "library test;"); |
- expect(context.computeImportedLibraries(source), hasLength(0)); |
- } |
- |
- void test_computeImportedLibraries_some() { |
- Source source = addSource( |
- "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); |
- expect(context.computeImportedLibraries(source), hasLength(2)); |
- } |
- |
void fail_computeResolvableCompilationUnit_dart_exception() { |
TestSource source = _addSourceWithException("/test.dart"); |
try { |
@@ -217,6 +168,30 @@ import 'libB.dart';'''; |
expect(resolvedUnit, same(parsedUnit)); |
} |
+ Future fail_computeResolvedCompilationUnitAsync_afterDispose() { |
+ Source source = addSource("/lib.dart", "library lib;"); |
+ // Complete all pending analysis tasks and flush the AST so that it won't |
+ // be available immediately. |
+ _performPendingAnalysisTasks(); |
+ _flushAst(source); |
+ // Dispose of the context. |
+ context.dispose(); |
+ // Any attempt to start an asynchronous computation should return a future |
+ // which completes with error. |
+ CancelableFuture<CompilationUnit> future = |
+ context.computeResolvedCompilationUnitAsync(source, source); |
+ bool completed = false; |
+ future.then((CompilationUnit unit) { |
+ fail('Future should have completed with error'); |
+ }, onError: (error) { |
+ expect(error, new isInstanceOf<AnalysisNotScheduledError>()); |
+ completed = true; |
+ }); |
+ return pumpEventQueue().then((_) { |
+ expect(completed, isTrue); |
+ }); |
+ } |
+ |
Future fail_computeResolvedCompilationUnitAsync_dispose() { |
Source source = addSource("/lib.dart", "library lib;"); |
// Complete all pending analysis tasks and flush the AST so that it won't |
@@ -268,76 +243,6 @@ import 'libB.dart';'''; |
fail("Implement this"); |
} |
- void test_getElement_constructor_named() { |
- Source source = addSource("/lib.dart", r''' |
-class A { |
- A.named() {} |
-}'''); |
- _analyzeAll_assertFinished(); |
- LibraryElement library = context.computeLibraryElement(source); |
- ClassElement classA = _findClass(library.definingCompilationUnit, "A"); |
- ConstructorElement constructor = classA.constructors[0]; |
- ElementLocation location = constructor.location; |
- Element element = context.getElement(location); |
- expect(element, same(constructor)); |
- } |
- |
- void test_getElement_constructor_unnamed() { |
- Source source = addSource("/lib.dart", r''' |
-class A { |
- A() {} |
-}'''); |
- _analyzeAll_assertFinished(); |
- LibraryElement library = context.computeLibraryElement(source); |
- ClassElement classA = _findClass(library.definingCompilationUnit, "A"); |
- ConstructorElement constructor = classA.constructors[0]; |
- ElementLocation location = constructor.location; |
- Element element = context.getElement(location); |
- expect(element, same(constructor)); |
- } |
- |
- void test_getElement_enum() { |
- Source source = addSource('/test.dart', 'enum MyEnum {A, B, C}'); |
- _analyzeAll_assertFinished(); |
- LibraryElement library = context.computeLibraryElement(source); |
- ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); |
- ElementLocation location = myEnum.location; |
- Element element = context.getElement(location); |
- expect(element, same(myEnum)); |
- } |
- |
- void test_getErrors_dart_none() { |
- Source source = addSource("/lib.dart", "library lib;"); |
- var errorInfo = context.getErrors(source); |
- expect(errorInfo, isNotNull); |
- List<AnalysisError> errors = errorInfo.errors; |
- expect(errors, hasLength(0)); |
- context.computeErrors(source); |
- errors = errorInfo.errors; |
- expect(errors, hasLength(0)); |
- } |
- |
- void test_getErrors_dart_some() { |
- Source source = addSource("/lib.dart", "library 'lib';"); |
- var errorInfo = context.getErrors(source); |
- expect(errorInfo, isNotNull); |
- List<AnalysisError> errors = errorInfo.errors; |
- expect(errors, hasLength(0)); |
- errors = context.computeErrors(source); |
- expect(errors, hasLength(1)); |
- } |
- |
- void test_getErrors_html_none() { |
- Source source = addSource("/test.html", "<html></html>"); |
- AnalysisErrorInfo errorInfo = context.getErrors(source); |
- expect(errorInfo, isNotNull); |
- List<AnalysisError> errors = errorInfo.errors; |
- expect(errors, hasLength(0)); |
- context.computeErrors(source); |
- errors = errorInfo.errors; |
- expect(errors, hasLength(0)); |
- } |
- |
void fail_getErrors_html_some() { |
Source source = addSource("/test.html", r''' |
<html><head> |
@@ -418,15 +323,6 @@ class A { |
expect(result[0], librarySource); |
} |
- void test_getResolvedCompilationUnit_library() { |
- Source source = addSource("/lib.dart", "library libb;"); |
- LibraryElement library = context.computeLibraryElement(source); |
- context.computeErrors(source); // Force the resolved unit to be built. |
- expect(context.getResolvedCompilationUnit(source, library), isNotNull); |
- context.setContents(source, "library lib;"); |
- expect(context.getResolvedCompilationUnit(source, library), isNull); |
- } |
- |
void fail_getResolvedHtmlUnit() { |
Source source = addSource("/test.html", "<html></html>"); |
expect(context.getResolvedHtmlUnit(source), isNull); |
@@ -487,165 +383,6 @@ part of lib; |
expect(librariesWithPart, unorderedEquals([libSource])); |
} |
- void fail_performAnalysisTask_changeLibraryContents() { |
- Source libSource = |
- addSource("/test.dart", "library lib; part 'test-part.dart';"); |
- Source partSource = addSource("/test-part.dart", "part of lib;"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 1"); |
- expect( |
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
- reason: "part resolved 1"); |
- // update and analyze #1 |
- context.setContents(libSource, "library lib;"); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
- reason: "library changed 2"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part changed 2"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 2"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part resolved 2"); |
- // update and analyze #2 |
- context.setContents(libSource, "library lib; part 'test-part.dart';"); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
- reason: "library changed 3"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part changed 3"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 2"); |
- expect( |
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
- reason: "part resolved 3"); |
- } |
- |
- void fail_performAnalysisTask_changeLibraryThenPartContents() { |
- Source libSource = |
- addSource("/test.dart", "library lib; part 'test-part.dart';"); |
- Source partSource = addSource("/test-part.dart", "part of lib;"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 1"); |
- expect( |
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
- reason: "part resolved 1"); |
- // update and analyze #1 |
- context.setContents(libSource, "library lib;"); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
- reason: "library changed 2"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part changed 2"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 2"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part resolved 2"); |
- // update and analyze #2 |
- context.setContents(partSource, "part of lib; // 1"); |
- // Assert that changing the part's content does not effect the library |
- // now that it is no longer part of that library |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library changed 3"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part changed 3"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 3"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part resolved 3"); |
- } |
- |
- void test_performAnalysisTask_changePartContents_makeItAPart() { |
- Source libSource = addSource("/lib.dart", r''' |
-library lib; |
-part 'part.dart'; |
-void f(x) {}'''); |
- Source partSource = addSource("/part.dart", "void g() { f(null); }"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 1"); |
- expect( |
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
- reason: "part resolved 1"); |
- // update and analyze |
- context.setContents(partSource, r''' |
-part of lib; |
-void g() { f(null); }'''); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
- reason: "library changed 2"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part changed 2"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 2"); |
- expect( |
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
- reason: "part resolved 2"); |
- expect(context.getErrors(libSource).errors, hasLength(0)); |
- expect(context.getErrors(partSource).errors, hasLength(0)); |
- } |
- |
- /** |
- * https://code.google.com/p/dart/issues/detail?id=12424 |
- */ |
- void test_performAnalysisTask_changePartContents_makeItNotPart() { |
- Source libSource = addSource("/lib.dart", r''' |
-library lib; |
-part 'part.dart'; |
-void f(x) {}'''); |
- Source partSource = addSource("/part.dart", r''' |
-part of lib; |
-void g() { f(null); }'''); |
- _analyzeAll_assertFinished(); |
- expect(context.getErrors(libSource).errors, hasLength(0)); |
- expect(context.getErrors(partSource).errors, hasLength(0)); |
- // Remove 'part' directive, which should make "f(null)" an error. |
- context.setContents(partSource, r''' |
-//part of lib; |
-void g() { f(null); }'''); |
- _analyzeAll_assertFinished(); |
- expect(context.getErrors(libSource).errors.length != 0, isTrue); |
- } |
- |
- void test_performAnalysisTask_changePartContents_noSemanticChanges() { |
- Source libSource = |
- addSource("/test.dart", "library lib; part 'test-part.dart';"); |
- Source partSource = addSource("/test-part.dart", "part of lib;"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 1"); |
- expect( |
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
- reason: "part resolved 1"); |
- // update and analyze #1 |
- context.setContents(partSource, "part of lib; // 1"); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
- reason: "library changed 2"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part changed 2"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 2"); |
- expect( |
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
- reason: "part resolved 2"); |
- // update and analyze #2 |
- context.setContents(partSource, "part of lib; // 12"); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
- reason: "library changed 3"); |
- expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
- reason: "part changed 3"); |
- _analyzeAll_assertFinished(); |
- expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
- reason: "library resolved 3"); |
- expect( |
- context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
- reason: "part resolved 3"); |
- } |
- |
void fail_performAnalysisTask_getContentException_dart() { |
// add source that throw an exception on "get content" |
Source source = new _Source_getContent_throwException('test.dart'); |
@@ -1089,6 +826,21 @@ int b = aa;'''; |
}); |
} |
+ void test_applyChanges_overriddenSource() { |
+ // Note: addSource adds the source to the contentCache. |
+ Source source = addSource("/test.dart", "library test;"); |
+ context.computeErrors(source); |
+ while (!context.sourcesNeedingProcessing.isEmpty) { |
+ context.performAnalysisTask(); |
+ } |
+ // Adding the source as a changedSource should have no effect since |
+ // it is already overridden in the content cache. |
+ ChangeSet changeSet = new ChangeSet(); |
+ changeSet.changedSource(source); |
+ context.applyChanges(changeSet); |
+ expect(context.sourcesNeedingProcessing, hasLength(0)); |
+ } |
+ |
void test_computeDocumentationComment_block() { |
String comment = "/** Comment */"; |
Source source = addSource("/test.dart", """ |
@@ -1136,6 +888,29 @@ class A {}"""); |
expect(actual, "/// line 1\n/// line 2\n/// line 3"); |
} |
+ void test_computeErrors_dart_none() { |
+ Source source = addSource("/lib.dart", "library lib;"); |
+ List<AnalysisError> errors = context.computeErrors(source); |
+ expect(errors, hasLength(0)); |
+ } |
+ |
+ void test_computeErrors_dart_part() { |
+ Source librarySource = |
+ addSource("/lib.dart", "library lib; part 'part.dart';"); |
+ Source partSource = addSource("/part.dart", "part of 'lib';"); |
+ context.parseCompilationUnit(librarySource); |
+ List<AnalysisError> errors = context.computeErrors(partSource); |
+ expect(errors, isNotNull); |
+ expect(errors.length > 0, isTrue); |
+ } |
+ |
+ void test_computeErrors_dart_some() { |
+ Source source = addSource("/lib.dart", "library 'lib';"); |
+ List<AnalysisError> errors = context.computeErrors(source); |
+ expect(errors, isNotNull); |
+ expect(errors.length > 0, isTrue); |
+ } |
+ |
void test_computeExportedLibraries_none() { |
Source source = addSource("/test.dart", "library test;"); |
expect(context.computeExportedLibraries(source), hasLength(0)); |
@@ -1154,6 +929,17 @@ class A {}"""); |
expect(context.computeHtmlElement(source), isNull); |
} |
+ void test_computeImportedLibraries_none() { |
+ Source source = addSource("/test.dart", "library test;"); |
+ expect(context.computeImportedLibraries(source), hasLength(0)); |
+ } |
+ |
+ void test_computeImportedLibraries_some() { |
+ Source source = addSource( |
+ "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); |
+ expect(context.computeImportedLibraries(source), hasLength(2)); |
+ } |
+ |
void test_computeKindOf_html() { |
Source source = addSource("/test.html", ""); |
expect(context.computeKindOf(source), same(SourceKind.HTML)); |
@@ -1180,50 +966,26 @@ class A {}"""); |
expect(element, isNotNull); |
} |
- void test_computeLineInfo_dart() { |
- Source source = addSource("/test.dart", r''' |
-library lib; |
- |
-main() {}'''); |
- LineInfo info = context.computeLineInfo(source); |
- expect(info, isNotNull); |
- } |
- |
- void test_computeLineInfo_html() { |
- Source source = addSource("/test.html", r''' |
-<html> |
- <body> |
- <h1>A</h1> |
- </body> |
-</html>'''); |
- LineInfo info = context.computeLineInfo(source); |
- expect(info, isNotNull); |
- } |
- |
- Future fail_computeResolvedCompilationUnitAsync_afterDispose() { |
- Source source = addSource("/lib.dart", "library lib;"); |
- // Complete all pending analysis tasks and flush the AST so that it won't |
- // be available immediately. |
- _performPendingAnalysisTasks(); |
- _flushAst(source); |
- // Dispose of the context. |
- context.dispose(); |
- // Any attempt to start an asynchronous computation should return a future |
- // which completes with error. |
- CancelableFuture<CompilationUnit> future = |
- context.computeResolvedCompilationUnitAsync(source, source); |
- bool completed = false; |
- future.then((CompilationUnit unit) { |
- fail('Future should have completed with error'); |
- }, onError: (error) { |
- expect(error, new isInstanceOf<AnalysisNotScheduledError>()); |
- completed = true; |
- }); |
- return pumpEventQueue().then((_) { |
- expect(completed, isTrue); |
- }); |
- } |
- |
+ void test_computeLineInfo_dart() { |
+ Source source = addSource("/test.dart", r''' |
+library lib; |
+ |
+main() {}'''); |
+ LineInfo info = context.computeLineInfo(source); |
+ expect(info, isNotNull); |
+ } |
+ |
+ void test_computeLineInfo_html() { |
+ Source source = addSource("/test.html", r''' |
+<html> |
+ <body> |
+ <h1>A</h1> |
+ </body> |
+</html>'''); |
+ LineInfo info = context.computeLineInfo(source); |
+ expect(info, isNotNull); |
+ } |
+ |
void test_dispose() { |
expect(context.isDisposed, isFalse); |
context.dispose(); |
@@ -1295,6 +1057,76 @@ main() {}'''); |
expect(element, same(classObject)); |
} |
+ void test_getElement_constructor_named() { |
+ Source source = addSource("/lib.dart", r''' |
+class A { |
+ A.named() {} |
+}'''); |
+ _analyzeAll_assertFinished(); |
+ LibraryElement library = context.computeLibraryElement(source); |
+ ClassElement classA = _findClass(library.definingCompilationUnit, "A"); |
+ ConstructorElement constructor = classA.constructors[0]; |
+ ElementLocation location = constructor.location; |
+ Element element = context.getElement(location); |
+ expect(element, same(constructor)); |
+ } |
+ |
+ void test_getElement_constructor_unnamed() { |
+ Source source = addSource("/lib.dart", r''' |
+class A { |
+ A() {} |
+}'''); |
+ _analyzeAll_assertFinished(); |
+ LibraryElement library = context.computeLibraryElement(source); |
+ ClassElement classA = _findClass(library.definingCompilationUnit, "A"); |
+ ConstructorElement constructor = classA.constructors[0]; |
+ ElementLocation location = constructor.location; |
+ Element element = context.getElement(location); |
+ expect(element, same(constructor)); |
+ } |
+ |
+ void test_getElement_enum() { |
+ Source source = addSource('/test.dart', 'enum MyEnum {A, B, C}'); |
+ _analyzeAll_assertFinished(); |
+ LibraryElement library = context.computeLibraryElement(source); |
+ ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); |
+ ElementLocation location = myEnum.location; |
+ Element element = context.getElement(location); |
+ expect(element, same(myEnum)); |
+ } |
+ |
+ void test_getErrors_dart_none() { |
+ Source source = addSource("/lib.dart", "library lib;"); |
+ var errorInfo = context.getErrors(source); |
+ expect(errorInfo, isNotNull); |
+ List<AnalysisError> errors = errorInfo.errors; |
+ expect(errors, hasLength(0)); |
+ context.computeErrors(source); |
+ errors = errorInfo.errors; |
+ expect(errors, hasLength(0)); |
+ } |
+ |
+ void test_getErrors_dart_some() { |
+ Source source = addSource("/lib.dart", "library 'lib';"); |
+ var errorInfo = context.getErrors(source); |
+ expect(errorInfo, isNotNull); |
+ List<AnalysisError> errors = errorInfo.errors; |
+ expect(errors, hasLength(0)); |
+ errors = context.computeErrors(source); |
+ expect(errors, hasLength(1)); |
+ } |
+ |
+ void test_getErrors_html_none() { |
+ Source source = addSource("/test.html", "<html></html>"); |
+ AnalysisErrorInfo errorInfo = context.getErrors(source); |
+ expect(errorInfo, isNotNull); |
+ List<AnalysisError> errors = errorInfo.errors; |
+ expect(errors, hasLength(0)); |
+ context.computeErrors(source); |
+ errors = errorInfo.errors; |
+ expect(errors, hasLength(0)); |
+ } |
+ |
void test_getHtmlElement_dart() { |
Source source = addSource("/test.dart", ""); |
expect(context.getHtmlElement(source), isNull); |
@@ -1526,6 +1358,15 @@ main() {}'''); |
(obj) => obj is ClassElement, ClassElement, namespace.get("A")); |
} |
+ void test_getResolvedCompilationUnit_library() { |
+ Source source = addSource("/lib.dart", "library libb;"); |
+ LibraryElement library = context.computeLibraryElement(source); |
+ context.computeErrors(source); // Force the resolved unit to be built. |
+ expect(context.getResolvedCompilationUnit(source, library), isNotNull); |
+ context.setContents(source, "library lib;"); |
+ expect(context.getResolvedCompilationUnit(source, library), isNull); |
+ } |
+ |
void test_getResolvedCompilationUnit_library_null() { |
Source source = addSource("/lib.dart", "library lib;"); |
expect(context.getResolvedCompilationUnit(source, null), isNull); |
@@ -1658,6 +1499,165 @@ main() {}'''); |
} |
} |
+ void test_performAnalysisTask_changeLibraryContents() { |
+ Source libSource = |
+ addSource("/test.dart", "library lib; part 'test-part.dart';"); |
+ Source partSource = addSource("/test-part.dart", "part of lib;"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 1"); |
+ expect( |
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
+ reason: "part resolved 1"); |
+ // update and analyze #1 |
+ context.setContents(libSource, "library lib;"); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
+ reason: "library changed 2"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part changed 2"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 2"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part resolved 2"); |
+ // update and analyze #2 |
+ context.setContents(libSource, "library lib; part 'test-part.dart';"); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
+ reason: "library changed 3"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part changed 3"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 2"); |
+ expect( |
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
+ reason: "part resolved 3"); |
+ } |
+ |
+ void test_performAnalysisTask_changeLibraryThenPartContents() { |
+ Source libSource = |
+ addSource("/test.dart", "library lib; part 'test-part.dart';"); |
+ Source partSource = addSource("/test-part.dart", "part of lib;"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 1"); |
+ expect( |
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
+ reason: "part resolved 1"); |
+ // update and analyze #1 |
+ context.setContents(libSource, "library lib;"); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
+ reason: "library changed 2"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part changed 2"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 2"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part resolved 2"); |
+ // update and analyze #2 |
+ context.setContents(partSource, "part of lib; // 1"); |
+ // Assert that changing the part's content does not effect the library |
+ // now that it is no longer part of that library |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library changed 3"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part changed 3"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 3"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part resolved 3"); |
+ } |
+ |
+ void test_performAnalysisTask_changePartContents_makeItAPart() { |
+ Source libSource = addSource("/lib.dart", r''' |
+library lib; |
+part 'part.dart'; |
+void f(x) {}'''); |
+ Source partSource = addSource("/part.dart", "void g() { f(null); }"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 1"); |
+ expect( |
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
+ reason: "part resolved 1"); |
+ // update and analyze |
+ context.setContents(partSource, r''' |
+part of lib; |
+void g() { f(null); }'''); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
+ reason: "library changed 2"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part changed 2"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 2"); |
+ expect( |
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
+ reason: "part resolved 2"); |
+ expect(context.getErrors(libSource).errors, hasLength(0)); |
+ expect(context.getErrors(partSource).errors, hasLength(0)); |
+ } |
+ |
+ /** |
+ * https://code.google.com/p/dart/issues/detail?id=12424 |
+ */ |
+ void test_performAnalysisTask_changePartContents_makeItNotPart() { |
+ Source libSource = addSource("/lib.dart", r''' |
+library lib; |
+part 'part.dart'; |
+void f(x) {}'''); |
+ Source partSource = addSource("/part.dart", r''' |
+part of lib; |
+void g() { f(null); }'''); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getErrors(libSource).errors, hasLength(0)); |
+ expect(context.getErrors(partSource).errors, hasLength(0)); |
+ // Remove 'part' directive, which should make "f(null)" an error. |
+ context.setContents(partSource, r''' |
+//part of lib; |
+void g() { f(null); }'''); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getErrors(libSource).errors.length != 0, isTrue); |
+ } |
+ |
+ void test_performAnalysisTask_changePartContents_noSemanticChanges() { |
+ Source libSource = |
+ addSource("/test.dart", "library lib; part 'test-part.dart';"); |
+ Source partSource = addSource("/test-part.dart", "part of lib;"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 1"); |
+ expect( |
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
+ reason: "part resolved 1"); |
+ // update and analyze #1 |
+ context.setContents(partSource, "part of lib; // 1"); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
+ reason: "library changed 2"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part changed 2"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 2"); |
+ expect( |
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
+ reason: "part resolved 2"); |
+ // update and analyze #2 |
+ context.setContents(partSource, "part of lib; // 12"); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, |
+ reason: "library changed 3"); |
+ expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
+ reason: "part changed 3"); |
+ _analyzeAll_assertFinished(); |
+ expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
+ reason: "library resolved 3"); |
+ expect( |
+ context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
+ reason: "part resolved 3"); |
+ } |
+ |
// void test_resolveCompilationUnit_sourceChangeDuringResolution() { |
// _context = new _AnalysisContext_sourceChangeDuringResolution(); |
// AnalysisContextFactory.initContextWithCore(_context); |