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

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

Issue 1827293002: Use AbstractSingleUnitTest, so MockSdk in resynthesize tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « pkg/analyzer/test/src/context/mock_sdk.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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';
11 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
12 import 'package:analyzer/dart/element/type.dart'; 12 import 'package:analyzer/dart/element/type.dart';
13 import 'package:analyzer/src/dart/ast/ast.dart'; 13 import 'package:analyzer/src/dart/ast/ast.dart';
14 import 'package:analyzer/src/dart/element/element.dart'; 14 import 'package:analyzer/src/dart/element/element.dart';
15 import 'package:analyzer/src/dart/element/handle.dart'; 15 import 'package:analyzer/src/dart/element/handle.dart';
16 import 'package:analyzer/src/dart/element/member.dart'; 16 import 'package:analyzer/src/dart/element/member.dart';
17 import 'package:analyzer/src/dart/element/type.dart'; 17 import 'package:analyzer/src/dart/element/type.dart';
18 import 'package:analyzer/src/generated/engine.dart'; 18 import 'package:analyzer/src/generated/engine.dart';
19 import 'package:analyzer/src/generated/error.dart';
19 import 'package:analyzer/src/generated/resolver.dart' 20 import 'package:analyzer/src/generated/resolver.dart'
20 show Namespace, TypeProvider; 21 show Namespace, TypeProvider;
21 import 'package:analyzer/src/generated/source.dart'; 22 import 'package:analyzer/src/generated/source.dart';
22 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 23 import 'package:analyzer/src/generated/testing/ast_factory.dart';
23 import 'package:analyzer/src/summary/idl.dart'; 24 import 'package:analyzer/src/summary/idl.dart';
24 import 'package:analyzer/src/summary/resynthesize.dart'; 25 import 'package:analyzer/src/summary/resynthesize.dart';
25 import 'package:analyzer/src/summary/summarize_elements.dart'; 26 import 'package:analyzer/src/summary/summarize_elements.dart';
26 import 'package:unittest/unittest.dart'; 27 import 'package:unittest/unittest.dart';
27 28
28 import '../../generated/resolver_test_case.dart'; 29 import '../../generated/test_support.dart';
29 import '../../reflective_tests.dart'; 30 import '../../reflective_tests.dart';
31 import '../abstract_single_unit.dart';
30 import 'summary_common.dart' show canonicalize; 32 import 'summary_common.dart' show canonicalize;
31 33
32 main() { 34 main() {
33 groupSep = ' | '; 35 groupSep = ' | ';
34 runReflectiveTests(ResynthTest); 36 runReflectiveTests(ResynthTest);
35 } 37 }
36 38
37 @reflectiveTest 39 @reflectiveTest
38 class ResynthTest extends ResolverTestCase { 40 class ResynthTest extends AbstractSingleUnitTest {
39 Set<Source> otherLibrarySources = new Set<Source>(); 41 Set<Source> otherLibrarySources = new Set<Source>();
40 bool constantInitializersAreInvalid = false; 42 bool constantInitializersAreInvalid = false;
41 43
42 void addLibrary(String uri) { 44 void addLibrary(String uri) {
43 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri)); 45 otherLibrarySources.add(context.sourceFactory.forUri(uri));
44 } 46 }
45 47
46 void addLibrarySource(String filePath, String contents) { 48 void addLibrarySource(String filePath, String contents) {
47 otherLibrarySources.add(addNamedSource(filePath, contents)); 49 otherLibrarySources.add(addSource(filePath, contents));
50 }
51
52 void assertNoErrors(Source source) {
53 GatheringErrorListener errorListener = new GatheringErrorListener();
54 for (AnalysisError error in context.computeErrors(source)) {
55 expect(error.source, source);
56 ErrorCode errorCode = error.errorCode;
57 if (errorCode == HintCode.UNUSED_ELEMENT ||
58 errorCode == HintCode.UNUSED_FIELD) {
59 continue;
60 }
61 if (errorCode == HintCode.UNUSED_CATCH_CLAUSE ||
62 errorCode == HintCode.UNUSED_CATCH_STACK ||
63 errorCode == HintCode.UNUSED_LOCAL_VARIABLE) {
64 continue;
65 }
66 errorListener.onError(error);
67 }
68 errorListener.assertNoErrors();
48 } 69 }
49 70
50 /** 71 /**
51 * Verify that the given prefix is safe to elide from a resynthesized AST. 72 * Verify that the given prefix is safe to elide from a resynthesized AST.
52 */ 73 */
53 void checkElidablePrefix(SimpleIdentifier prefix) { 74 void checkElidablePrefix(SimpleIdentifier prefix) {
54 if (prefix.staticElement is! PrefixElement && 75 if (prefix.staticElement is! PrefixElement &&
55 prefix.staticElement is! ClassElement) { 76 prefix.staticElement is! ClassElement) {
56 fail('Prefix of type ${prefix.staticElement.runtimeType}' 77 fail('Prefix of type ${prefix.staticElement.runtimeType}'
57 ' should not have been elided'); 78 ' should not have been elided');
58 } 79 }
59 } 80 }
60 81
61 void checkLibrary(String text, 82 void checkLibrary(String text,
62 {bool allowErrors: false, bool dumpSummaries: false}) { 83 {bool allowErrors: false, bool dumpSummaries: false}) {
63 Source source = addSource(text); 84 Source source = addTestSource(text);
64 LibraryElementImpl original = resolve2(source); 85 LibraryElementImpl original = context.computeLibraryElement(source);
65 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 86 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
66 encodeLibrary(original, 87 encodeLibrary(original,
67 allowErrors: allowErrors, dumpSummaries: dumpSummaries), 88 allowErrors: allowErrors, dumpSummaries: dumpSummaries),
68 source.uri.toString(), 89 source.uri.toString(),
69 original); 90 original);
70 checkLibraryElements(original, resynthesized); 91 checkLibraryElements(original, resynthesized);
71 } 92 }
72 93
73 void checkLibraryElements( 94 void checkLibraryElements(
74 LibraryElementImpl original, LibraryElementImpl resynthesized) { 95 LibraryElementImpl original, LibraryElementImpl resynthesized) {
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 * references it makes to `dart:core`. 1057 * references it makes to `dart:core`.
1037 * 1058 *
1038 * Errors will lead to a test failure unless [allowErrors] is `true`. 1059 * Errors will lead to a test failure unless [allowErrors] is `true`.
1039 */ 1060 */
1040 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library, 1061 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library,
1041 {bool allowErrors: false, bool dumpSummaries: false}) { 1062 {bool allowErrors: false, bool dumpSummaries: false}) {
1042 if (!allowErrors) { 1063 if (!allowErrors) {
1043 assertNoErrors(library.source); 1064 assertNoErrors(library.source);
1044 } 1065 }
1045 addLibrary('dart:core'); 1066 addLibrary('dart:core');
1067 addLibrary('dart:async');
1068 addLibrary('dart:math');
1046 return encodeLibraryElement(library, dumpSummaries: dumpSummaries); 1069 return encodeLibraryElement(library, dumpSummaries: dumpSummaries);
1047 } 1070 }
1048 1071
1049 /** 1072 /**
1050 * Convert the library element [library] into a summary, and then create a 1073 * Convert the library element [library] into a summary, and then create a
1051 * [_TestSummaryResynthesizer] which can deserialize it. 1074 * [_TestSummaryResynthesizer] which can deserialize it.
1052 * 1075 *
1053 * Caller is responsible for checking the library for errors, and adding any 1076 * Caller is responsible for checking the library for errors, and adding any
1054 * dependent libraries using [addLibrary]. 1077 * dependent libraries using [addLibrary].
1055 */ 1078 */
1056 _TestSummaryResynthesizer encodeLibraryElement(LibraryElementImpl library, 1079 _TestSummaryResynthesizer encodeLibraryElement(LibraryElementImpl library,
1057 {bool dumpSummaries: false}) { 1080 {bool dumpSummaries: false}) {
1058 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{}; 1081 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{};
1059 LinkedLibrary getLinkedSummaryFor(LibraryElement lib) { 1082 LinkedLibrary getLinkedSummaryFor(LibraryElement lib) {
1060 LibrarySerializationResult serialized = serializeLibrary( 1083 LibrarySerializationResult serialized = serializeLibrary(
1061 lib, typeProvider, analysisContext.analysisOptions.strongMode); 1084 lib, context.typeProvider, context.analysisOptions.strongMode);
1062 for (int i = 0; i < serialized.unlinkedUnits.length; i++) { 1085 for (int i = 0; i < serialized.unlinkedUnits.length; i++) {
1063 unlinkedSummaries[serialized.unitUris[i]] = 1086 unlinkedSummaries[serialized.unitUris[i]] =
1064 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer()); 1087 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer());
1065 } 1088 }
1066 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer()); 1089 return new LinkedLibrary.fromBuffer(serialized.linked.toBuffer());
1067 } 1090 }
1068 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{ 1091 Map<String, LinkedLibrary> linkedSummaries = <String, LinkedLibrary>{
1069 library.source.uri.toString(): getLinkedSummaryFor(library) 1092 library.source.uri.toString(): getLinkedSummaryFor(library)
1070 }; 1093 };
1071 for (Source source in otherLibrarySources) { 1094 for (Source source in otherLibrarySources) {
1072 LibraryElement original = resolve2(source); 1095 LibraryElement original = context.computeLibraryElement(source);
1073 String uri = source.uri.toString(); 1096 String uri = source.uri.toString();
1074 linkedSummaries[uri] = getLinkedSummaryFor(original); 1097 linkedSummaries[uri] = getLinkedSummaryFor(original);
1075 } 1098 }
1076 if (dumpSummaries) { 1099 if (dumpSummaries) {
1077 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) { 1100 unlinkedSummaries.forEach((String path, UnlinkedUnit unit) {
1078 print('Unlinked $path: ${JSON.encode(canonicalize(unit))}'); 1101 print('Unlinked $path: ${JSON.encode(canonicalize(unit))}');
1079 }); 1102 });
1080 linkedSummaries.forEach((String path, LinkedLibrary lib) { 1103 linkedSummaries.forEach((String path, LinkedLibrary lib) {
1081 print('Linked $path: ${JSON.encode(canonicalize(lib))}'); 1104 print('Linked $path: ${JSON.encode(canonicalize(lib))}');
1082 }); 1105 });
1083 } 1106 }
1084 return new _TestSummaryResynthesizer( 1107 return new _TestSummaryResynthesizer(
1085 null, 1108 null,
1086 analysisContext, 1109 context,
1087 analysisContext.typeProvider, 1110 context.typeProvider,
1088 analysisContext.sourceFactory, 1111 context.sourceFactory,
1089 unlinkedSummaries, 1112 unlinkedSummaries,
1090 linkedSummaries, 1113 linkedSummaries,
1091 createOptions().strongMode); 1114 createOptions().strongMode);
1092 } 1115 }
1093 1116
1094 fail_library_hasExtUri() { 1117 fail_library_hasExtUri() {
1095 checkLibrary('import "dart-ext:doesNotExist.dart";'); 1118 checkLibrary('import "dart-ext:doesNotExist.dart";');
1096 } 1119 }
1097 1120
1098 ElementImpl getActualElement(Element element, String desc) { 1121 ElementImpl getActualElement(Element element, String desc) {
(...skipping 27 matching lines...) Expand all
1126 String uri, 1149 String uri,
1127 LibraryElement original) { 1150 LibraryElement original) {
1128 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri); 1151 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri);
1129 checkMinimalResynthesisWork(resynthesizer, original); 1152 checkMinimalResynthesisWork(resynthesizer, original);
1130 return resynthesized; 1153 return resynthesized;
1131 } 1154 }
1132 1155
1133 @override 1156 @override
1134 void setUp() { 1157 void setUp() {
1135 super.setUp(); 1158 super.setUp();
1136 resetWithOptions(createOptions()); 1159 prepareAnalysisContext(createOptions());
1137 } 1160 }
1138 1161
1139 test_class_abstract() { 1162 test_class_abstract() {
1140 checkLibrary('abstract class C {}'); 1163 checkLibrary('abstract class C {}');
1141 } 1164 }
1142 1165
1143 test_class_alias() { 1166 test_class_alias() {
1144 checkLibrary('class C = D with E, F; class D {} class E {} class F {}'); 1167 checkLibrary('class C = D with E, F; class D {} class E {} class F {}');
1145 } 1168 }
1146 1169
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 C() : x = new D(); 2556 C() : x = new D();
2534 } 2557 }
2535 class D { 2558 class D {
2536 final x; 2559 final x;
2537 D() : x = new C(); 2560 D() : x = new C();
2538 } 2561 }
2539 '''); 2562 ''');
2540 } 2563 }
2541 2564
2542 test_core() { 2565 test_core() {
2543 if (createOptions().strongMode) { 2566 addLibrary('dart:async');
2544 // The fake `dart:core` library is always in spec mode, so don't bother 2567 addLibrary('dart:math');
2545 // trying to check that it resynthesizes properly; it won't.
2546 return;
2547 }
2548 String uri = 'dart:core'; 2568 String uri = 'dart:core';
2549 LibraryElementImpl original = 2569 LibraryElementImpl original =
2550 resolve2(analysisContext2.sourceFactory.forUri(uri)); 2570 context.computeLibraryElement(context.sourceFactory.forUri(uri));
2551 LibraryElementImpl resynthesized = resynthesizeLibraryElement( 2571 LibraryElementImpl resynthesized = resynthesizeLibraryElement(
2552 encodeLibraryElement(original), uri, original); 2572 encodeLibraryElement(original), uri, original);
2553 checkLibraryElements(original, resynthesized); 2573 checkLibraryElements(original, resynthesized);
2554 } 2574 }
2555 2575
2556 test_enum_documented() { 2576 test_enum_documented() {
2557 checkLibrary(''' 2577 checkLibrary('''
2558 // Extra comment so doc comment offset != 0 2578 // Extra comment so doc comment offset != 0
2559 /** 2579 /**
2560 * Docs 2580 * Docs
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2696 test_field_propagatedType_final_dep_inLib() { 2716 test_field_propagatedType_final_dep_inLib() {
2697 addLibrarySource('/a.dart', 'final a = 1;'); 2717 addLibrarySource('/a.dart', 'final a = 1;');
2698 checkLibrary(''' 2718 checkLibrary('''
2699 import "a.dart"; 2719 import "a.dart";
2700 class C { 2720 class C {
2701 final b = a / 2; 2721 final b = a / 2;
2702 }'''); 2722 }''');
2703 } 2723 }
2704 2724
2705 test_field_propagatedType_final_dep_inPart() { 2725 test_field_propagatedType_final_dep_inPart() {
2706 addNamedSource('/a.dart', 'part of lib; final a = 1;'); 2726 addSource('/a.dart', 'part of lib; final a = 1;');
2707 checkLibrary(''' 2727 checkLibrary('''
2708 library lib; 2728 library lib;
2709 part "a.dart"; 2729 part "a.dart";
2710 class C { 2730 class C {
2711 final b = a / 2; 2731 final b = a / 2;
2712 }'''); 2732 }''');
2713 } 2733 }
2714 2734
2715 test_field_propagatedType_final_noDep_instance() { 2735 test_field_propagatedType_final_noDep_instance() {
2716 checkLibrary(''' 2736 checkLibrary('''
(...skipping 26 matching lines...) Expand all
2743 addLibrarySource('/a.dart', 'library a; main() {}'); 2763 addLibrarySource('/a.dart', 'library a; main() {}');
2744 checkLibrary('export "a.dart";'); 2764 checkLibrary('export "a.dart";');
2745 } 2765 }
2746 2766
2747 test_function_entry_point_in_export_hidden() { 2767 test_function_entry_point_in_export_hidden() {
2748 addLibrarySource('/a.dart', 'library a; main() {}'); 2768 addLibrarySource('/a.dart', 'library a; main() {}');
2749 checkLibrary('export "a.dart" hide main;'); 2769 checkLibrary('export "a.dart" hide main;');
2750 } 2770 }
2751 2771
2752 test_function_entry_point_in_part() { 2772 test_function_entry_point_in_part() {
2753 addNamedSource('/a.dart', 'part of my.lib; main() {}'); 2773 addSource('/a.dart', 'part of my.lib; main() {}');
2754 checkLibrary('library my.lib; part "a.dart";'); 2774 checkLibrary('library my.lib; part "a.dart";');
2755 } 2775 }
2756 2776
2757 test_function_external() { 2777 test_function_external() {
2758 checkLibrary('external f();'); 2778 checkLibrary('external f();');
2759 } 2779 }
2760 2780
2761 test_function_parameter_kind_named() { 2781 test_function_parameter_kind_named() {
2762 checkLibrary('f({x}) {}'); 2782 checkLibrary('f({x}) {}');
2763 } 2783 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2796 2816
2797 test_function_return_type_implicit() { 2817 test_function_return_type_implicit() {
2798 checkLibrary('f() => null;'); 2818 checkLibrary('f() => null;');
2799 } 2819 }
2800 2820
2801 test_function_return_type_void() { 2821 test_function_return_type_void() {
2802 checkLibrary('void f() {}'); 2822 checkLibrary('void f() {}');
2803 } 2823 }
2804 2824
2805 test_function_type_parameter() { 2825 test_function_type_parameter() {
2806 resetWithOptions(createOptions()..enableGenericMethods = true); 2826 prepareAnalysisContext(createOptions()..enableGenericMethods = true);
2807 checkLibrary('T f<T, U>(U u) => null;'); 2827 checkLibrary('T f<T, U>(U u) => null;');
2808 } 2828 }
2809 2829
2810 test_function_type_parameter_with_function_typed_parameter() { 2830 test_function_type_parameter_with_function_typed_parameter() {
2811 resetWithOptions(createOptions()..enableGenericMethods = true); 2831 prepareAnalysisContext(createOptions()..enableGenericMethods = true);
2812 checkLibrary('void f<T, U>(T x(U u)) {}'); 2832 checkLibrary('void f<T, U>(T x(U u)) {}');
2813 } 2833 }
2814 2834
2815 test_functions() { 2835 test_functions() {
2816 checkLibrary('f() {} g() {}'); 2836 checkLibrary('f() {} g() {}');
2817 } 2837 }
2818 2838
2819 test_generic_gClass_gMethodStatic() { 2839 test_generic_gClass_gMethodStatic() {
2820 resetWithOptions(createOptions()..enableGenericMethods = true); 2840 prepareAnalysisContext(createOptions()..enableGenericMethods = true);
2821 checkLibrary(''' 2841 checkLibrary('''
2822 class C<T, U> { 2842 class C<T, U> {
2823 static void m<V, W>(V v, W w) { 2843 static void m<V, W>(V v, W w) {
2824 void f<X, Y>(V v, W w, X x, Y y) { 2844 void f<X, Y>(V v, W w, X x, Y y) {
2825 } 2845 }
2826 } 2846 }
2827 } 2847 }
2828 '''); 2848 ''');
2829 } 2849 }
2830 2850
2831 test_getElement_constructor_named() { 2851 test_getElement_constructor_named() {
2832 ConstructorElement original = resolve2(addSource('class C { C.named(); }')) 2852 ConstructorElement original = context
2853 .computeLibraryElement(addTestSource('class C { C.named(); }'))
2833 .getType('C') 2854 .getType('C')
2834 .getNamedConstructor('named'); 2855 .getNamedConstructor('named');
2835 expect(original, isNotNull); 2856 expect(original, isNotNull);
2836 ConstructorElement resynthesized = validateGetElement(original); 2857 ConstructorElement resynthesized = validateGetElement(original);
2837 compareConstructorElements(resynthesized, original, 'C.constructor named'); 2858 compareConstructorElements(resynthesized, original, 'C.constructor named');
2838 } 2859 }
2839 2860
2840 test_getElement_constructor_unnamed() { 2861 test_getElement_constructor_unnamed() {
2841 ConstructorElement original = 2862 ConstructorElement original = context
2842 resolve2(addSource('class C { C(); }')).getType('C').unnamedConstructor; 2863 .computeLibraryElement(addTestSource('class C { C(); }'))
2864 .getType('C')
2865 .unnamedConstructor;
2843 expect(original, isNotNull); 2866 expect(original, isNotNull);
2844 ConstructorElement resynthesized = validateGetElement(original); 2867 ConstructorElement resynthesized = validateGetElement(original);
2845 compareConstructorElements(resynthesized, original, 'C.constructor'); 2868 compareConstructorElements(resynthesized, original, 'C.constructor');
2846 } 2869 }
2847 2870
2848 test_getElement_field() { 2871 test_getElement_field() {
2849 FieldElement original = 2872 FieldElement original = context
2850 resolve2(addSource('class C { var f; }')).getType('C').getField('f'); 2873 .computeLibraryElement(addTestSource('class C { var f; }'))
2874 .getType('C')
2875 .getField('f');
2851 expect(original, isNotNull); 2876 expect(original, isNotNull);
2852 FieldElement resynthesized = validateGetElement(original); 2877 FieldElement resynthesized = validateGetElement(original);
2853 compareFieldElements(resynthesized, original, 'C.field f'); 2878 compareFieldElements(resynthesized, original, 'C.field f');
2854 } 2879 }
2855 2880
2856 test_getElement_getter() { 2881 test_getElement_getter() {
2857 PropertyAccessorElement original = 2882 PropertyAccessorElement original = context
2858 resolve2(addSource('class C { get f => null; }')) 2883 .computeLibraryElement(addTestSource('class C { get f => null; }'))
2859 .getType('C') 2884 .getType('C')
2860 .getGetter('f'); 2885 .getGetter('f');
2861 expect(original, isNotNull); 2886 expect(original, isNotNull);
2862 PropertyAccessorElement resynthesized = validateGetElement(original); 2887 PropertyAccessorElement resynthesized = validateGetElement(original);
2863 comparePropertyAccessorElements(resynthesized, original, 'C.getter f'); 2888 comparePropertyAccessorElements(resynthesized, original, 'C.getter f');
2864 } 2889 }
2865 2890
2866 test_getElement_method() { 2891 test_getElement_method() {
2867 MethodElement original = 2892 MethodElement original = context
2868 resolve2(addSource('class C { f() {} }')).getType('C').getMethod('f'); 2893 .computeLibraryElement(addTestSource('class C { f() {} }'))
2894 .getType('C')
2895 .getMethod('f');
2869 expect(original, isNotNull); 2896 expect(original, isNotNull);
2870 MethodElement resynthesized = validateGetElement(original); 2897 MethodElement resynthesized = validateGetElement(original);
2871 compareMethodElements(resynthesized, original, 'C.method f'); 2898 compareMethodElements(resynthesized, original, 'C.method f');
2872 } 2899 }
2873 2900
2874 test_getElement_operator() { 2901 test_getElement_operator() {
2875 MethodElement original = 2902 MethodElement original = context
2876 resolve2(addSource('class C { operator+(x) => null; }')) 2903 .computeLibraryElement(
2877 .getType('C') 2904 addTestSource('class C { operator+(x) => null; }'))
2878 .getMethod('+'); 2905 .getType('C')
2906 .getMethod('+');
2879 expect(original, isNotNull); 2907 expect(original, isNotNull);
2880 MethodElement resynthesized = validateGetElement(original); 2908 MethodElement resynthesized = validateGetElement(original);
2881 compareMethodElements(resynthesized, original, 'C.operator+'); 2909 compareMethodElements(resynthesized, original, 'C.operator+');
2882 } 2910 }
2883 2911
2884 test_getElement_setter() { 2912 test_getElement_setter() {
2885 PropertyAccessorElement original = 2913 PropertyAccessorElement original = context
2886 resolve2(addSource('class C { void set f(value) {} }')) 2914 .computeLibraryElement(
2887 .getType('C') 2915 addTestSource('class C { void set f(value) {} }'))
2888 .getSetter('f'); 2916 .getType('C')
2917 .getSetter('f');
2889 expect(original, isNotNull); 2918 expect(original, isNotNull);
2890 PropertyAccessorElement resynthesized = validateGetElement(original); 2919 PropertyAccessorElement resynthesized = validateGetElement(original);
2891 comparePropertyAccessorElements(resynthesized, original, 'C.setter f'); 2920 comparePropertyAccessorElements(resynthesized, original, 'C.setter f');
2892 } 2921 }
2893 2922
2894 test_getElement_unit() { 2923 test_getElement_unit() {
2895 Source source = addSource('class C { f() {} }'); 2924 Source source = addTestSource('class C { f() {} }');
2896 CompilationUnitElement original = resolve2(source).definingCompilationUnit; 2925 CompilationUnitElement original =
2926 context.computeLibraryElement(source).definingCompilationUnit;
2897 expect(original, isNotNull); 2927 expect(original, isNotNull);
2898 CompilationUnitElement resynthesized = validateGetElement(original); 2928 CompilationUnitElement resynthesized = validateGetElement(original);
2899 compareCompilationUnitElements(resynthesized, original); 2929 compareCompilationUnitElements(resynthesized, original);
2900 } 2930 }
2901 2931
2902 test_getter_documented() { 2932 test_getter_documented() {
2903 checkLibrary(''' 2933 checkLibrary('''
2904 // Extra comment so doc comment offset != 0 2934 // Extra comment so doc comment offset != 0
2905 /** 2935 /**
2906 * Docs 2936 * Docs
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 3440
3411 test_metadata_methodDeclaration_method() { 3441 test_metadata_methodDeclaration_method() {
3412 checkLibrary('const a = null; class C { @a m() {} }'); 3442 checkLibrary('const a = null; class C { @a m() {} }');
3413 } 3443 }
3414 3444
3415 test_metadata_methodDeclaration_setter() { 3445 test_metadata_methodDeclaration_setter() {
3416 checkLibrary('const a = null; class C { @a set m(value) {} }'); 3446 checkLibrary('const a = null; class C { @a set m(value) {} }');
3417 } 3447 }
3418 3448
3419 test_metadata_partDirective() { 3449 test_metadata_partDirective() {
3420 addNamedSource('/foo.dart', 'part of L;'); 3450 addSource('/foo.dart', 'part of L;');
3421 checkLibrary('library L; @a part "foo.dart"; const a = null;'); 3451 checkLibrary('library L; @a part "foo.dart"; const a = null;');
3422 } 3452 }
3423 3453
3424 test_metadata_prefixed_variable() { 3454 test_metadata_prefixed_variable() {
3425 addLibrarySource('/a.dart', 'const b = null;'); 3455 addLibrarySource('/a.dart', 'const b = null;');
3426 checkLibrary('import "a.dart" as a; @a.b class C {}'); 3456 checkLibrary('import "a.dart" as a; @a.b class C {}');
3427 } 3457 }
3428 3458
3429 test_metadata_simpleFormalParameter() { 3459 test_metadata_simpleFormalParameter() {
3430 checkLibrary('const a = null; f(@a x) {}'); 3460 checkLibrary('const a = null; f(@a x) {}');
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3485 3515
3486 test_method_parameter_return_type() { 3516 test_method_parameter_return_type() {
3487 checkLibrary('class C { f(int g()) {} }'); 3517 checkLibrary('class C { f(int g()) {} }');
3488 } 3518 }
3489 3519
3490 test_method_parameter_return_type_void() { 3520 test_method_parameter_return_type_void() {
3491 checkLibrary('class C { f(void g()) {} }'); 3521 checkLibrary('class C { f(void g()) {} }');
3492 } 3522 }
3493 3523
3494 test_method_type_parameter() { 3524 test_method_type_parameter() {
3495 resetWithOptions(createOptions()..enableGenericMethods = true); 3525 prepareAnalysisContext(createOptions()..enableGenericMethods = true);
3496 checkLibrary('class C { T f<T, U>(U u) => null; }'); 3526 checkLibrary('class C { T f<T, U>(U u) => null; }');
3497 } 3527 }
3498 3528
3499 test_method_type_parameter_in_generic_class() { 3529 test_method_type_parameter_in_generic_class() {
3500 resetWithOptions(createOptions()..enableGenericMethods = true); 3530 prepareAnalysisContext(createOptions()..enableGenericMethods = true);
3501 checkLibrary('class C<T, U> { V f<V, W>(T t, U u, W w) => null; }'); 3531 checkLibrary('class C<T, U> { V f<V, W>(T t, U u, W w) => null; }');
3502 } 3532 }
3503 3533
3504 test_method_type_parameter_with_function_typed_parameter() { 3534 test_method_type_parameter_with_function_typed_parameter() {
3505 resetWithOptions(createOptions()..enableGenericMethods = true); 3535 prepareAnalysisContext(createOptions()..enableGenericMethods = true);
3506 checkLibrary('class C { void f<T, U>(T x(U u)) {} }'); 3536 checkLibrary('class C { void f<T, U>(T x(U u)) {} }');
3507 } 3537 }
3508 3538
3509 test_nested_generic_functions_in_generic_class_with_function_typed_params() { 3539 test_nested_generic_functions_in_generic_class_with_function_typed_params() {
3510 checkLibrary(''' 3540 checkLibrary('''
3511 class C<T, U> { 3541 class C<T, U> {
3512 void g<V, W>() { 3542 void g<V, W>() {
3513 void h<X, Y>(void p(T t, U u, V v, W w, X x, Y y)) { 3543 void h<X, Y>(void p(T t, U u, V v, W w, X x, Y y)) {
3514 } 3544 }
3515 } 3545 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
3628 // Strong mode doesn't do type inference on parameters of top level 3658 // Strong mode doesn't do type inference on parameters of top level
3629 // functions, so it's ok that we don't store inferred type info for them in 3659 // functions, so it's ok that we don't store inferred type info for them in
3630 // summaries. 3660 // summaries.
3631 checkLibrary(''' 3661 checkLibrary('''
3632 void positional([x = 1]) {} 3662 void positional([x = 1]) {}
3633 void named({x: 1}) {} 3663 void named({x: 1}) {}
3634 '''); 3664 ''');
3635 } 3665 }
3636 3666
3637 test_parts() { 3667 test_parts() {
3638 addNamedSource('/a.dart', 'part of my.lib;'); 3668 addSource('/a.dart', 'part of my.lib;');
3639 addNamedSource('/b.dart', 'part of my.lib;'); 3669 addSource('/b.dart', 'part of my.lib;');
3640 checkLibrary('library my.lib; part "a.dart"; part "b.dart";'); 3670 checkLibrary('library my.lib; part "a.dart"; part "b.dart";');
3641 } 3671 }
3642 3672
3643 test_propagated_type_refers_to_closure() { 3673 test_propagated_type_refers_to_closure() {
3644 checkLibrary(''' 3674 checkLibrary('''
3645 void f() { 3675 void f() {
3646 var x = () => 0; 3676 var x = () => 0;
3647 var y = x; 3677 var y = x;
3648 } 3678 }
3649 '''); 3679 ''');
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
3765 3795
3766 test_type_dynamic() { 3796 test_type_dynamic() {
3767 checkLibrary('dynamic d;'); 3797 checkLibrary('dynamic d;');
3768 } 3798 }
3769 3799
3770 test_type_reference_lib_to_lib() { 3800 test_type_reference_lib_to_lib() {
3771 checkLibrary('class C {} enum E { v } typedef F(); C c; E e; F f;'); 3801 checkLibrary('class C {} enum E { v } typedef F(); C c; E e; F f;');
3772 } 3802 }
3773 3803
3774 test_type_reference_lib_to_part() { 3804 test_type_reference_lib_to_part() {
3775 addNamedSource( 3805 addSource('/a.dart', 'part of l; class C {} enum E { v } typedef F();');
3776 '/a.dart', 'part of l; class C {} enum E { v } typedef F();');
3777 checkLibrary('library l; part "a.dart"; C c; E e; F f;'); 3806 checkLibrary('library l; part "a.dart"; C c; E e; F f;');
3778 } 3807 }
3779 3808
3780 test_type_reference_part_to_lib() { 3809 test_type_reference_part_to_lib() {
3781 addNamedSource('/a.dart', 'part of l; C c; E e; F f;'); 3810 addSource('/a.dart', 'part of l; C c; E e; F f;');
3782 checkLibrary( 3811 checkLibrary(
3783 'library l; part "a.dart"; class C {} enum E { v } typedef F();'); 3812 'library l; part "a.dart"; class C {} enum E { v } typedef F();');
3784 } 3813 }
3785 3814
3786 test_type_reference_part_to_other_part() { 3815 test_type_reference_part_to_other_part() {
3787 addNamedSource( 3816 addSource('/a.dart', 'part of l; class C {} enum E { v } typedef F();');
3788 '/a.dart', 'part of l; class C {} enum E { v } typedef F();'); 3817 addSource('/b.dart', 'part of l; C c; E e; F f;');
3789 addNamedSource('/b.dart', 'part of l; C c; E e; F f;');
3790 checkLibrary('library l; part "a.dart"; part "b.dart";'); 3818 checkLibrary('library l; part "a.dart"; part "b.dart";');
3791 } 3819 }
3792 3820
3793 test_type_reference_part_to_part() { 3821 test_type_reference_part_to_part() {
3794 addNamedSource('/a.dart', 3822 addSource('/a.dart',
3795 'part of l; class C {} enum E { v } typedef F(); C c; E e; F f;'); 3823 'part of l; class C {} enum E { v } typedef F(); C c; E e; F f;');
3796 checkLibrary('library l; part "a.dart";'); 3824 checkLibrary('library l; part "a.dart";');
3797 } 3825 }
3798 3826
3799 test_type_reference_to_class() { 3827 test_type_reference_to_class() {
3800 checkLibrary('class C {} C c;'); 3828 checkLibrary('class C {} C c;');
3801 } 3829 }
3802 3830
3803 test_type_reference_to_class_with_type_arguments() { 3831 test_type_reference_to_class_with_type_arguments() {
3804 checkLibrary('class C<T, U> {} C<int, String> c;'); 3832 checkLibrary('class C<T, U> {} C<int, String> c;');
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3838 } 3866 }
3839 3867
3840 test_type_reference_to_import_export_in_subdirs() { 3868 test_type_reference_to_import_export_in_subdirs() {
3841 addLibrarySource('/a/a.dart', 'export "b/b.dart";'); 3869 addLibrarySource('/a/a.dart', 'export "b/b.dart";');
3842 addLibrarySource('/a/b/b.dart', 'class C {} enum E { v } typedef F();'); 3870 addLibrarySource('/a/b/b.dart', 'class C {} enum E { v } typedef F();');
3843 checkLibrary('import "a/a.dart"; C c; E e; F f;'); 3871 checkLibrary('import "a/a.dart"; C c; E e; F f;');
3844 } 3872 }
3845 3873
3846 test_type_reference_to_import_part() { 3874 test_type_reference_to_import_part() {
3847 addLibrarySource('/a.dart', 'library l; part "b.dart";'); 3875 addLibrarySource('/a.dart', 'library l; part "b.dart";');
3848 addNamedSource( 3876 addSource('/b.dart', 'part of l; class C {} enum E { v } typedef F();');
3849 '/b.dart', 'part of l; class C {} enum E { v } typedef F();');
3850 checkLibrary('import "a.dart"; C c; E e; F f;'); 3877 checkLibrary('import "a.dart"; C c; E e; F f;');
3851 } 3878 }
3852 3879
3853 test_type_reference_to_import_part2() { 3880 test_type_reference_to_import_part2() {
3854 addLibrarySource('/a.dart', 'library l; part "p1.dart"; part "p2.dart";'); 3881 addLibrarySource('/a.dart', 'library l; part "p1.dart"; part "p2.dart";');
3855 addNamedSource('/p1.dart', 'part of l; class C1 {}'); 3882 addSource('/p1.dart', 'part of l; class C1 {}');
3856 addNamedSource('/p2.dart', 'part of l; class C2 {}'); 3883 addSource('/p2.dart', 'part of l; class C2 {}');
3857 checkLibrary('import "a.dart"; C1 c1; C2 c2;'); 3884 checkLibrary('import "a.dart"; C1 c1; C2 c2;');
3858 } 3885 }
3859 3886
3860 test_type_reference_to_import_part_in_subdir() { 3887 test_type_reference_to_import_part_in_subdir() {
3861 addLibrarySource('/a/b.dart', 'library l; part "c.dart";'); 3888 addLibrarySource('/a/b.dart', 'library l; part "c.dart";');
3862 addNamedSource( 3889 addSource('/a/c.dart', 'part of l; class C {} enum E { v } typedef F();');
3863 '/a/c.dart', 'part of l; class C {} enum E { v } typedef F();');
3864 checkLibrary('import "a/b.dart"; C c; E e; F f;'); 3890 checkLibrary('import "a/b.dart"; C c; E e; F f;');
3865 } 3891 }
3866 3892
3867 test_type_reference_to_import_relative() { 3893 test_type_reference_to_import_relative() {
3868 addLibrarySource('/a.dart', 'class C {} enum E { v } typedef F();'); 3894 addLibrarySource('/a.dart', 'class C {} enum E { v } typedef F();');
3869 checkLibrary('import "a.dart"; C c; E e; F f;'); 3895 checkLibrary('import "a.dart"; C c; E e; F f;');
3870 } 3896 }
3871 3897
3872 test_type_reference_to_typedef() { 3898 test_type_reference_to_typedef() {
3873 checkLibrary('typedef F(); F f;'); 3899 checkLibrary('typedef F(); F f;');
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
3969 * Docs 3995 * Docs
3970 */ 3996 */
3971 var x;'''); 3997 var x;''');
3972 } 3998 }
3973 3999
3974 test_variable_final() { 4000 test_variable_final() {
3975 checkLibrary('final int x = 0;'); 4001 checkLibrary('final int x = 0;');
3976 } 4002 }
3977 4003
3978 test_variable_getterInLib_setterInPart() { 4004 test_variable_getterInLib_setterInPart() {
3979 addNamedSource('/a.dart', 'part of my.lib; void set x(int _) {}'); 4005 addSource('/a.dart', 'part of my.lib; void set x(int _) {}');
3980 checkLibrary('library my.lib; part "a.dart"; int get x => 42;'); 4006 checkLibrary('library my.lib; part "a.dart"; int get x => 42;');
3981 } 4007 }
3982 4008
3983 test_variable_getterInPart_setterInLib() { 4009 test_variable_getterInPart_setterInLib() {
3984 addNamedSource('/a.dart', 'part of my.lib; int get x => 42;'); 4010 addSource('/a.dart', 'part of my.lib; int get x => 42;');
3985 checkLibrary('library my.lib; part "a.dart"; void set x(int _) {}'); 4011 checkLibrary('library my.lib; part "a.dart"; void set x(int _) {}');
3986 } 4012 }
3987 4013
3988 test_variable_getterInPart_setterInPart() { 4014 test_variable_getterInPart_setterInPart() {
3989 addNamedSource('/a.dart', 'part of my.lib; int get x => 42;'); 4015 addSource('/a.dart', 'part of my.lib; int get x => 42;');
3990 addNamedSource('/b.dart', 'part of my.lib; void set x(int _) {}'); 4016 addSource('/b.dart', 'part of my.lib; void set x(int _) {}');
3991 checkLibrary('library my.lib; part "a.dart"; part "b.dart";'); 4017 checkLibrary('library my.lib; part "a.dart"; part "b.dart";');
3992 } 4018 }
3993 4019
3994 test_variable_implicit_type() { 4020 test_variable_implicit_type() {
3995 checkLibrary('var x;'); 4021 checkLibrary('var x;');
3996 } 4022 }
3997 4023
3998 test_variable_inferred_type_implicit_initialized() { 4024 test_variable_inferred_type_implicit_initialized() {
3999 checkLibrary('var v = 0;'); 4025 checkLibrary('var v = 0;');
4000 } 4026 }
4001 4027
4002 test_variable_propagatedType_const_noDep() { 4028 test_variable_propagatedType_const_noDep() {
4003 checkLibrary('const i = 0;'); 4029 checkLibrary('const i = 0;');
4004 } 4030 }
4005 4031
4006 test_variable_propagatedType_final_dep_inLib() { 4032 test_variable_propagatedType_final_dep_inLib() {
4007 addLibrarySource('/a.dart', 'final a = 1;'); 4033 addLibrarySource('/a.dart', 'final a = 1;');
4008 checkLibrary('import "a.dart"; final b = a / 2;'); 4034 checkLibrary('import "a.dart"; final b = a / 2;');
4009 } 4035 }
4010 4036
4011 test_variable_propagatedType_final_dep_inPart() { 4037 test_variable_propagatedType_final_dep_inPart() {
4012 addNamedSource('/a.dart', 'part of lib; final a = 1;'); 4038 addSource('/a.dart', 'part of lib; final a = 1;');
4013 checkLibrary('library lib; part "a.dart"; final b = a / 2;'); 4039 checkLibrary('library lib; part "a.dart"; final b = a / 2;');
4014 } 4040 }
4015 4041
4016 test_variable_propagatedType_final_noDep() { 4042 test_variable_propagatedType_final_noDep() {
4017 checkLibrary('final i = 0;'); 4043 checkLibrary('final i = 0;');
4018 } 4044 }
4019 4045
4020 test_variable_propagatedType_implicit_dep() { 4046 test_variable_propagatedType_implicit_dep() {
4021 // The propagated type is defined in a library that is not imported. 4047 // The propagated type is defined in a library that is not imported.
4022 addLibrarySource('/a.dart', 'class C {}'); 4048 addLibrarySource('/a.dart', 'class C {}');
4023 addLibrarySource('/b.dart', 'import "a.dart"; C f() => null;'); 4049 addLibrarySource('/b.dart', 'import "a.dart"; C f() => null;');
4024 checkLibrary('import "b.dart"; final x = f();'); 4050 checkLibrary('import "b.dart"; final x = f();');
4025 } 4051 }
4026 4052
4027 test_variable_setterInPart_getterInPart() { 4053 test_variable_setterInPart_getterInPart() {
4028 addNamedSource('/a.dart', 'part of my.lib; void set x(int _) {}'); 4054 addSource('/a.dart', 'part of my.lib; void set x(int _) {}');
4029 addNamedSource('/b.dart', 'part of my.lib; int get x => 42;'); 4055 addSource('/b.dart', 'part of my.lib; int get x => 42;');
4030 checkLibrary('library my.lib; part "a.dart"; part "b.dart";'); 4056 checkLibrary('library my.lib; part "a.dart"; part "b.dart";');
4031 } 4057 }
4032 4058
4033 test_variables() { 4059 test_variables() {
4034 checkLibrary('int i; int j;'); 4060 checkLibrary('int i; int j;');
4035 } 4061 }
4036 4062
4037 /** 4063 /**
4038 * Encode the library containing [original] into a summary and then use 4064 * Encode the library containing [original] into a summary and then use
4039 * [_TestSummaryResynthesizer.getElement] to retrieve just the original 4065 * [_TestSummaryResynthesizer.getElement] to retrieve just the original
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
4102 fail('Unexpectedly tried to get unlinked summary for $uri'); 4128 fail('Unexpectedly tried to get unlinked summary for $uri');
4103 } 4129 }
4104 return serializedUnit; 4130 return serializedUnit;
4105 } 4131 }
4106 4132
4107 @override 4133 @override
4108 bool hasLibrarySummary(String uri) { 4134 bool hasLibrarySummary(String uri) {
4109 return true; 4135 return true;
4110 } 4136 }
4111 } 4137 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/mock_sdk.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698