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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1910343002: Fix summary resynthesis in the event of a self-import. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/constant/value.dart'; 10 import 'package:analyzer/dart/constant/value.dart';
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 void _assertUnresolvedIdentifier(Expression initializer, String desc) { 1205 void _assertUnresolvedIdentifier(Expression initializer, String desc) {
1206 expect(initializer, new isInstanceOf<SimpleIdentifier>(), reason: desc); 1206 expect(initializer, new isInstanceOf<SimpleIdentifier>(), reason: desc);
1207 SimpleIdentifier identifier = initializer; 1207 SimpleIdentifier identifier = initializer;
1208 expect(identifier.staticElement, isNull, reason: desc); 1208 expect(identifier.staticElement, isNull, reason: desc);
1209 } 1209 }
1210 } 1210 }
1211 1211
1212 @reflectiveTest 1212 @reflectiveTest
1213 class ResynthesizeElementTest extends ResynthesizeTest { 1213 class ResynthesizeElementTest extends ResynthesizeTest {
1214 @override 1214 @override
1215 void checkLibrary(String text, 1215 LibraryElementImpl checkLibrary(String text,
1216 {bool allowErrors: false, bool dumpSummaries: false}) { 1216 {bool allowErrors: false, bool dumpSummaries: false}) {
1217 Source source = addTestSource(text); 1217 Source source = addTestSource(text);
1218 LibraryElementImpl original = context.computeLibraryElement(source); 1218 LibraryElementImpl original = context.computeLibraryElement(source);
1219 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 1219 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
1220 encodeLibrary(original, 1220 encodeLibrary(original,
1221 allowErrors: allowErrors, dumpSummaries: dumpSummaries), 1221 allowErrors: allowErrors, dumpSummaries: dumpSummaries),
1222 source.uri.toString(), 1222 source.uri.toString(),
1223 original); 1223 original);
1224 checkLibraryElements(original, resynthesized); 1224 checkLibraryElements(original, resynthesized);
1225 return resynthesized;
1225 } 1226 }
1226 1227
1227 @override 1228 @override
1228 SummaryResynthesizer encodeDecodeLibrarySource(Source librarySource) { 1229 SummaryResynthesizer encodeDecodeLibrarySource(Source librarySource) {
1229 LibraryElement libraryElement = 1230 LibraryElement libraryElement =
1230 context.computeLibraryElement(librarySource); 1231 context.computeLibraryElement(librarySource);
1231 return encodeLibrary(libraryElement); 1232 return encodeLibrary(libraryElement);
1232 } 1233 }
1233 1234
1234 /** 1235 /**
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 LibraryElementImpl original = 1311 LibraryElementImpl original =
1311 context.computeLibraryElement(context.sourceFactory.forUri(uri)); 1312 context.computeLibraryElement(context.sourceFactory.forUri(uri));
1312 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 1313 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
1313 encodeLibraryElement(original), uri, original); 1314 encodeLibraryElement(original), uri, original);
1314 checkLibraryElements(original, resynthesized); 1315 checkLibraryElements(original, resynthesized);
1315 } 1316 }
1316 } 1317 }
1317 1318
1318 @reflectiveTest 1319 @reflectiveTest
1319 abstract class ResynthesizeTest extends AbstractResynthesizeTest { 1320 abstract class ResynthesizeTest extends AbstractResynthesizeTest {
1320 void checkLibrary(String text, 1321 LibraryElementImpl checkLibrary(String text,
1321 {bool allowErrors: false, bool dumpSummaries: false}); 1322 {bool allowErrors: false, bool dumpSummaries: false});
1322 1323
1323 /** 1324 /**
1324 * Return a [SummaryResynthesizer] to resynthesize the library with the 1325 * Return a [SummaryResynthesizer] to resynthesize the library with the
1325 * given [librarySource]. 1326 * given [librarySource].
1326 */ 1327 */
1327 SummaryResynthesizer encodeDecodeLibrarySource(Source librarySource); 1328 SummaryResynthesizer encodeDecodeLibrarySource(Source librarySource);
1328 1329
1329 fail_library_hasExtUri() { 1330 fail_library_hasExtUri() {
1330 checkLibrary('import "dart-ext:doesNotExist.dart";'); 1331 checkLibrary('import "dart-ext:doesNotExist.dart";');
(...skipping 1827 matching lines...) Expand 10 before | Expand all | Expand 10 after
3158 test_import_multiple_combinators() { 3159 test_import_multiple_combinators() {
3159 addLibrary('dart:async'); 3160 addLibrary('dart:async');
3160 checkLibrary('import "dart:async" hide Stream show Future; Future f;'); 3161 checkLibrary('import "dart:async" hide Stream show Future; Future f;');
3161 } 3162 }
3162 3163
3163 test_import_prefixed() { 3164 test_import_prefixed() {
3164 addLibrarySource('/a.dart', 'library a; class C {}'); 3165 addLibrarySource('/a.dart', 'library a; class C {}');
3165 checkLibrary('import "a.dart" as a; a.C c;'); 3166 checkLibrary('import "a.dart" as a; a.C c;');
3166 } 3167 }
3167 3168
3169 test_import_self() {
3170 LibraryElementImpl resynthesized = checkLibrary('''
3171 import 'test.dart' as p;
3172 class C {}
3173 class D extends p.C {} // Prevent "unused import" warning
3174 ''');
3175 expect(resynthesized.imports, hasLength(2));
3176 expect(resynthesized.imports[0].importedLibrary.location,
3177 resynthesized.location);
3178 expect(resynthesized.imports[1].importedLibrary.isDartCore, true);
3179 }
3180
3168 test_import_show() { 3181 test_import_show() {
3169 addLibrary('dart:async'); 3182 addLibrary('dart:async');
3170 checkLibrary(''' 3183 checkLibrary('''
3171 import "dart:async" show Future, Stream; 3184 import "dart:async" show Future, Stream;
3172 Future f; 3185 Future f;
3173 Stream s; 3186 Stream s;
3174 '''); 3187 ''');
3175 } 3188 }
3176 3189
3177 test_imports() { 3190 test_imports() {
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
4322 fail('Unexpectedly tried to get unlinked summary for $uri'); 4335 fail('Unexpectedly tried to get unlinked summary for $uri');
4323 } 4336 }
4324 return serializedUnit; 4337 return serializedUnit;
4325 } 4338 }
4326 4339
4327 @override 4340 @override
4328 bool hasLibrarySummary(String uri) { 4341 bool hasLibrarySummary(String uri) {
4329 return true; 4342 return true;
4330 } 4343 }
4331 } 4344 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_ast_test.dart ('k') | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698