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

Unified Diff: pkg/analyzer/test/src/summary/resynthesize_ast_test.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
diff --git a/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart b/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
index b1cdf8edbfb841c6ff57f09321400eb3772576ab..28689c56aa08b87ec6b2bf1e760167ddef2660f2 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_ast_test.dart
@@ -271,8 +271,111 @@ abstract class _ResynthesizeAstTest extends ResynthesizeTest
AnalysisOptionsImpl createOptions() =>
super.createOptions()..strongMode = isStrongMode;
- @override
- TestSummaryResynthesizer encodeDecodeLibrarySource(Source source) {
+ test_getElement_constructor_named() async {
+ String text = 'class C { C.named(); }';
+ Source source = addLibrarySource('/test.dart', text);
+ ConstructorElement original = context
+ .computeLibraryElement(source)
+ .getType('C')
+ .getNamedConstructor('named');
+ expect(original, isNotNull);
+ ConstructorElement resynthesized = _validateGetElement(text, original);
+ compareConstructorElements(resynthesized, original, 'C.constructor named');
+ }
+
+ test_getElement_constructor_unnamed() async {
+ String text = 'class C { C(); }';
+ Source source = addLibrarySource('/test.dart', text);
+ ConstructorElement original =
+ context.computeLibraryElement(source).getType('C').unnamedConstructor;
+ expect(original, isNotNull);
+ ConstructorElement resynthesized = _validateGetElement(text, original);
+ compareConstructorElements(resynthesized, original, 'C.constructor');
+ }
+
+ test_getElement_field() async {
+ String text = 'class C { var f; }';
+ Source source = addLibrarySource('/test.dart', text);
+ FieldElement original =
+ context.computeLibraryElement(source).getType('C').getField('f');
+ expect(original, isNotNull);
+ FieldElement resynthesized = _validateGetElement(text, original);
+ compareFieldElements(resynthesized, original, 'C.field f');
+ }
+
+ test_getElement_getter() async {
+ String text = 'class C { get f => null; }';
+ Source source = addLibrarySource('/test.dart', text);
+ PropertyAccessorElement original =
+ context.computeLibraryElement(source).getType('C').getGetter('f');
+ expect(original, isNotNull);
+ PropertyAccessorElement resynthesized = _validateGetElement(text, original);
+ comparePropertyAccessorElements(resynthesized, original, 'C.getter f');
+ }
+
+ test_getElement_method() async {
+ String text = 'class C { f() {} }';
+ Source source = addLibrarySource('/test.dart', text);
+ MethodElement original =
+ context.computeLibraryElement(source).getType('C').getMethod('f');
+ expect(original, isNotNull);
+ MethodElement resynthesized = _validateGetElement(text, original);
+ compareMethodElements(resynthesized, original, 'C.method f');
+ }
+
+ test_getElement_operator() async {
+ String text = 'class C { operator+(x) => null; }';
+ Source source = addLibrarySource('/test.dart', text);
+ MethodElement original =
+ context.computeLibraryElement(source).getType('C').getMethod('+');
+ expect(original, isNotNull);
+ MethodElement resynthesized = _validateGetElement(text, original);
+ compareMethodElements(resynthesized, original, 'C.operator+');
+ }
+
+ test_getElement_setter() async {
+ String text = 'class C { void set f(value) {} }';
+ Source source = addLibrarySource('/test.dart', text);
+ PropertyAccessorElement original =
+ context.computeLibraryElement(source).getType('C').getSetter('f');
+ expect(original, isNotNull);
+ PropertyAccessorElement resynthesized = _validateGetElement(text, original);
+ comparePropertyAccessorElements(resynthesized, original, 'C.setter f');
+ }
+
+ test_getElement_unit() async {
+ String text = 'class C { f() {} }';
+ Source source = addLibrarySource('/test.dart', text);
+ CompilationUnitElement original =
+ context.computeLibraryElement(source).definingCompilationUnit;
+ expect(original, isNotNull);
+ CompilationUnitElement resynthesized = _validateGetElement(text, original);
+ compareCompilationUnitElements(resynthesized, original);
+ }
+
+ /**
+ * Return a [SummaryResynthesizer] to resynthesize the library with the
+ * given [Source].
+ */
+ TestSummaryResynthesizer _encodeDecodeLibrarySource(Source source) {
return _encodeLibrary(source);
}
+
+ /**
+ * Encode the library containing [original] into a summary and then use
+ * [TestSummaryResynthesizer.getElement] to retrieve just the original
+ * element from the resynthesized summary.
+ */
+ Element _validateGetElement(String text, Element original) {
+ SummaryResynthesizer resynthesizer =
+ _encodeDecodeLibrarySource(original.library.source);
+ ElementLocationImpl location = original.location;
+ Element result = resynthesizer.getElement(location);
+ checkMinimalResynthesisWork(resynthesizer, original.library);
+ // Check that no other summaries needed to be resynthesized to resynthesize
+ // the library element.
+ expect(resynthesizer.resynthesisCount, 3);
+ expect(result.location, location);
+ return result;
+ }
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698