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

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

Issue 3009533002: Move getElement() tests from AbstractResynthesizeTest mixin into AST resynthesizer tests. (Closed)
Patch Set: Created 3 years, 4 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:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 throw new UnimplementedError( 1336 throw new UnimplementedError(
1337 'Modifier $modifier for ${element?.runtimeType}'); 1337 'Modifier $modifier for ${element?.runtimeType}');
1338 } 1338 }
1339 } 1339 }
1340 1340
1341 @reflectiveTest 1341 @reflectiveTest
1342 abstract class ResynthesizeTest extends AbstractResynthesizeTest { 1342 abstract class ResynthesizeTest extends AbstractResynthesizeTest {
1343 Future<LibraryElementImpl> checkLibrary(String text, 1343 Future<LibraryElementImpl> checkLibrary(String text,
1344 {bool allowErrors: false, bool dumpSummaries: false}); 1344 {bool allowErrors: false, bool dumpSummaries: false});
1345 1345
1346 /**
1347 * Return a [SummaryResynthesizer] to resynthesize the library with the
1348 * given [librarySource].
1349 */
1350 SummaryResynthesizer encodeDecodeLibrarySource(Source librarySource);
1351
1352 test_class_abstract() async { 1346 test_class_abstract() async {
1353 var library = await checkLibrary('abstract class C {}'); 1347 var library = await checkLibrary('abstract class C {}');
1354 checkElementText(library, r''' 1348 checkElementText(library, r'''
1355 abstract class C { 1349 abstract class C {
1356 } 1350 }
1357 '''); 1351 ''');
1358 } 1352 }
1359 1353
1360 test_class_alias() async { 1354 test_class_alias() async {
1361 var library = await checkLibrary(''' 1355 var library = await checkLibrary('''
(...skipping 4830 matching lines...) Expand 10 before | Expand all | Expand 10 after
6192 test_genericFunction_asTopLevelVariableType() async { 6186 test_genericFunction_asTopLevelVariableType() async {
6193 shouldCompareLibraryElements = false; 6187 shouldCompareLibraryElements = false;
6194 var library = await checkLibrary(r''' 6188 var library = await checkLibrary(r'''
6195 int Function(int a, String b) v; 6189 int Function(int a, String b) v;
6196 '''); 6190 ''');
6197 checkElementText(library, r''' 6191 checkElementText(library, r'''
6198 (int, String) → int v; 6192 (int, String) → int v;
6199 '''); 6193 ''');
6200 } 6194 }
6201 6195
6202 test_getElement_constructor_named() async {
6203 String text = 'class C { C.named(); }';
6204 Source source = addLibrarySource('/test.dart', text);
6205 ConstructorElement original = context
6206 .computeLibraryElement(source)
6207 .getType('C')
6208 .getNamedConstructor('named');
6209 expect(original, isNotNull);
6210 ConstructorElement resynthesized = validateGetElement(text, original);
6211 compareConstructorElements(resynthesized, original, 'C.constructor named');
6212 }
6213
6214 test_getElement_constructor_unnamed() async {
6215 String text = 'class C { C(); }';
6216 Source source = addLibrarySource('/test.dart', text);
6217 ConstructorElement original =
6218 context.computeLibraryElement(source).getType('C').unnamedConstructor;
6219 expect(original, isNotNull);
6220 ConstructorElement resynthesized = validateGetElement(text, original);
6221 compareConstructorElements(resynthesized, original, 'C.constructor');
6222 }
6223
6224 test_getElement_field() async {
6225 String text = 'class C { var f; }';
6226 Source source = addLibrarySource('/test.dart', text);
6227 FieldElement original =
6228 context.computeLibraryElement(source).getType('C').getField('f');
6229 expect(original, isNotNull);
6230 FieldElement resynthesized = validateGetElement(text, original);
6231 compareFieldElements(resynthesized, original, 'C.field f');
6232 }
6233
6234 test_getElement_getter() async {
6235 String text = 'class C { get f => null; }';
6236 Source source = addLibrarySource('/test.dart', text);
6237 PropertyAccessorElement original =
6238 context.computeLibraryElement(source).getType('C').getGetter('f');
6239 expect(original, isNotNull);
6240 PropertyAccessorElement resynthesized = validateGetElement(text, original);
6241 comparePropertyAccessorElements(resynthesized, original, 'C.getter f');
6242 }
6243
6244 test_getElement_method() async {
6245 String text = 'class C { f() {} }';
6246 Source source = addLibrarySource('/test.dart', text);
6247 MethodElement original =
6248 context.computeLibraryElement(source).getType('C').getMethod('f');
6249 expect(original, isNotNull);
6250 MethodElement resynthesized = validateGetElement(text, original);
6251 compareMethodElements(resynthesized, original, 'C.method f');
6252 }
6253
6254 test_getElement_operator() async {
6255 String text = 'class C { operator+(x) => null; }';
6256 Source source = addLibrarySource('/test.dart', text);
6257 MethodElement original =
6258 context.computeLibraryElement(source).getType('C').getMethod('+');
6259 expect(original, isNotNull);
6260 MethodElement resynthesized = validateGetElement(text, original);
6261 compareMethodElements(resynthesized, original, 'C.operator+');
6262 }
6263
6264 test_getElement_setter() async {
6265 String text = 'class C { void set f(value) {} }';
6266 Source source = addLibrarySource('/test.dart', text);
6267 PropertyAccessorElement original =
6268 context.computeLibraryElement(source).getType('C').getSetter('f');
6269 expect(original, isNotNull);
6270 PropertyAccessorElement resynthesized = validateGetElement(text, original);
6271 comparePropertyAccessorElements(resynthesized, original, 'C.setter f');
6272 }
6273
6274 test_getElement_unit() async {
6275 String text = 'class C { f() {} }';
6276 Source source = addLibrarySource('/test.dart', text);
6277 CompilationUnitElement original =
6278 context.computeLibraryElement(source).definingCompilationUnit;
6279 expect(original, isNotNull);
6280 CompilationUnitElement resynthesized = validateGetElement(text, original);
6281 compareCompilationUnitElements(resynthesized, original);
6282 }
6283
6284 test_getter_documented() async { 6196 test_getter_documented() async {
6285 var library = await checkLibrary(''' 6197 var library = await checkLibrary('''
6286 // Extra comment so doc comment offset != 0 6198 // Extra comment so doc comment offset != 0
6287 /** 6199 /**
6288 * Docs 6200 * Docs
6289 */ 6201 */
6290 get x => null;'''); 6202 get x => null;''');
6291 checkElementText(library, r''' 6203 checkElementText(library, r'''
6292 /** 6204 /**
6293 * Docs 6205 * Docs
(...skipping 3715 matching lines...) Expand 10 before | Expand all | Expand 10 after
10009 '''); 9921 ''');
10010 } 9922 }
10011 9923
10012 test_variables() async { 9924 test_variables() async {
10013 var library = await checkLibrary('int i; int j;'); 9925 var library = await checkLibrary('int i; int j;');
10014 checkElementText(library, r''' 9926 checkElementText(library, r'''
10015 int i; 9927 int i;
10016 int j; 9928 int j;
10017 '''); 9929 ''');
10018 } 9930 }
10019
10020 /**
10021 * Encode the library containing [original] into a summary and then use
10022 * [TestSummaryResynthesizer.getElement] to retrieve just the original
10023 * element from the resynthesized summary.
10024 */
10025 Element validateGetElement(String text, Element original) {
10026 SummaryResynthesizer resynthesizer =
10027 encodeDecodeLibrarySource(original.library.source);
10028 ElementLocationImpl location = original.location;
10029 Element result = resynthesizer.getElement(location);
10030 checkMinimalResynthesisWork(resynthesizer, original.library);
10031 // Check that no other summaries needed to be resynthesized to resynthesize
10032 // the library element.
10033 expect(resynthesizer.resynthesisCount, 3);
10034 expect(result.location, location);
10035 return result;
10036 }
10037 } 9931 }
10038 9932
10039 class TestSummaryResynthesizer extends SummaryResynthesizer { 9933 class TestSummaryResynthesizer extends SummaryResynthesizer {
10040 final Map<String, UnlinkedUnit> unlinkedSummaries; 9934 final Map<String, UnlinkedUnit> unlinkedSummaries;
10041 final Map<String, LinkedLibrary> linkedSummaries; 9935 final Map<String, LinkedLibrary> linkedSummaries;
10042 final bool allowMissingFiles; 9936 final bool allowMissingFiles;
10043 9937
10044 /** 9938 /**
10045 * The set of uris for which unlinked summaries have been requested using 9939 * The set of uris for which unlinked summaries have been requested using
10046 * [getUnlinkedSummary]. 9940 * [getUnlinkedSummary].
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
10080 fail('Unexpectedly tried to get unlinked summary for $uri'); 9974 fail('Unexpectedly tried to get unlinked summary for $uri');
10081 } 9975 }
10082 return serializedUnit; 9976 return serializedUnit;
10083 } 9977 }
10084 9978
10085 @override 9979 @override
10086 bool hasLibrarySummary(String uri) { 9980 bool hasLibrarySummary(String uri) {
10087 return true; 9981 return true;
10088 } 9982 }
10089 } 9983 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_ast_test.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698