Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1207)

Unified Diff: pkg/analyzer/test/src/summary/summary_test.dart

Issue 1577973003: Test and fix serializing a library with a missing part. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/summary/summary_test.dart
diff --git a/pkg/analyzer/test/src/summary/summary_test.dart b/pkg/analyzer/test/src/summary/summary_test.dart
index 448a92d8ce2e48fe917f03ec0a5376ddb672a5ce..5093cdcc61616bb965972cc4b9522ef2e9c7361b 100644
--- a/pkg/analyzer/test/src/summary/summary_test.dart
+++ b/pkg/analyzer/test/src/summary/summary_test.dart
@@ -192,12 +192,25 @@ class SummarizeElementsTest extends ResolverTestCase with SummaryTest {
*/
List<String> unitUris;
+ /**
+ * Map containing all source files in this test, and their corresponding file
+ * contents.
+ */
+ final Map<Source, String> _fileContents = <Source, String>{};
+
@override
bool get checkAstDerivedData => false;
@override
bool get expectAbsoluteUrisInDependencies => true;
+ @override
+ Source addNamedSource(String filePath, String contents) {
+ Source source = super.addNamedSource(filePath, contents);
+ _fileContents[source] = contents;
+ return source;
+ }
+
/**
* Serialize the library containing the given class [element], then
* deserialize it and return the summary of the class.
@@ -228,6 +241,7 @@ class SummarizeElementsTest extends ResolverTestCase with SummaryTest {
@override
void serializeLibraryText(String text, {bool allowErrors: false}) {
Source source = addSource(text);
+ _fileContents[source] = text;
LibraryElement library = resolve2(source);
if (!allowErrors) {
assertNoErrors(source);
@@ -264,12 +278,19 @@ class SummarizeElementsTest extends ResolverTestCase with SummaryTest {
void verifyPublicNamespace() {
for (int i = 0; i < unlinkedUnits.length; i++) {
Source source = analysisContext.sourceFactory.forUri(unitUris[i]);
- String text = analysisContext.getContents(source).data;
- UnlinkedPublicNamespace namespace =
- computePublicNamespaceFromText(text, source);
- expect(canonicalize(namespace),
- canonicalize(unlinkedUnits[i].publicNamespace),
- reason: 'publicNamespace(${unitUris[i]})');
+ String text = _fileContents[source];
+ if (text == null) {
+ if (!allowMissingFiles) {
+ fail('Could not find file while verifying public namespace: '
+ '${unitUris[i]}');
+ }
+ } else {
+ UnlinkedPublicNamespace namespace =
+ computePublicNamespaceFromText(text, source);
+ expect(canonicalize(namespace),
+ canonicalize(unlinkedUnits[i].publicNamespace),
+ reason: 'publicNamespace(${unitUris[i]})');
+ }
}
}
}
@@ -2415,6 +2436,17 @@ library foo;''';
expect(unlinkedUnits[0].libraryNameLength, 0);
}
+ test_library_with_missing_part() {
+ // References to other parts should still be resolved.
+ allowMissingFiles = true;
+ addNamedSource('/bar.dart', 'part of my.lib; class C {}');
+ serializeLibraryText(
+ 'library my.lib; part "foo.dart"; part "bar.dart"; C c;',
+ allowErrors: true);
+ checkTypeRef(findVariable('c').type, null, null, 'C',
+ expectedTargetUnit: 2);
+ }
+
test_local_names_take_precedence_over_imported_names() {
addNamedSource('/a.dart', 'class C {} class D {}');
serializeLibraryText('''
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698