Chromium Code Reviews| Index: pkg/analyzer/test/src/summary/resynthesize_test.dart |
| diff --git a/pkg/analyzer/test/src/summary/resynthesize_test.dart b/pkg/analyzer/test/src/summary/resynthesize_test.dart |
| index 9f0d1513e5a5b2069fc29cfff5b308e730c8ecaf..ba46c7e9802bee894eca57fcc94ed3bb67e5c8a5 100644 |
| --- a/pkg/analyzer/test/src/summary/resynthesize_test.dart |
| +++ b/pkg/analyzer/test/src/summary/resynthesize_test.dart |
| @@ -131,6 +131,22 @@ class ResynthTest extends ResolverTestCase { |
| } |
| } |
| + void checkPossibleLocalElements(Element resynthesized, Element original) { |
| + if (original is! LocalElement && resynthesized is! LocalElement) { |
| + return; |
| + } |
| + // TODO(scheglov) add support for parameters |
| + if (original is ParameterElement && resynthesized is ParameterElement) { |
| + return; |
| + } |
| + if (original is LocalElement && resynthesized is LocalElement) { |
| + expect(resynthesized.visibleRange, original.visibleRange); |
| + } else { |
| + fail('Incompatible local elements ' |
| + '${resynthesized.runtimeType} vs. ${original.runtimeType}'); |
| + } |
| + } |
| + |
| void checkPossibleMember( |
| Element resynthesized, Element original, String desc) { |
| Element resynthesizedNonHandle = resynthesized is ElementHandle |
| @@ -534,6 +550,24 @@ class ResynthTest extends ResolverTestCase { |
| original.typeParameters[i], |
| '$desc type parameter ${original.typeParameters[i].name}'); |
| } |
| + if (original is! Member) { |
| + List<FunctionElement> rFunctions = resynthesized.functions; |
| + List<FunctionElement> oFunctions = original.functions; |
| + expect(rFunctions, hasLength(oFunctions.length)); |
| + for (int i = 0; i < oFunctions.length; i++) { |
| + compareFunctionElements(rFunctions[i], oFunctions[i], |
| + '$desc local function ${oFunctions[i].name}'); |
| + } |
| + } |
| + if (original is! Member) { |
| + List<LocalVariableElement> rVariables = resynthesized.localVariables; |
| + List<LocalVariableElement> oVariables = original.localVariables; |
| + expect(rVariables, hasLength(oVariables.length)); |
| + for (int i = 0; i < oVariables.length; i++) { |
| + compareVariableElements(rVariables[i], oVariables[i], |
| + '$desc local variable ${oVariables[i].name}'); |
| + } |
| + } |
| } |
| void compareExportElements(ExportElementImpl resynthesized, |
| @@ -556,6 +590,7 @@ class ResynthTest extends ResolverTestCase { |
| void compareFunctionElements( |
| FunctionElement resynthesized, FunctionElement original, String desc) { |
| compareExecutableElements(resynthesized, original, desc); |
| + checkPossibleLocalElements(resynthesized, original); |
| } |
| void compareFunctionTypeAliasElements( |
| @@ -820,6 +855,7 @@ class ResynthTest extends ResolverTestCase { |
| } |
| } |
| checkPossibleMember(resynthesized, original, desc); |
| + checkPossibleLocalElements(resynthesized, original); |
| } |
| /** |
| @@ -2613,6 +2649,102 @@ library foo;'''); |
| checkLibrary('library foo.bar;'); |
| } |
| + test_localFuncctions_inMethod() { |
|
Paul Berry
2016/02/11 21:15:46
s/Funcctions/Functions/
|
| + checkLibrary(r''' |
| +class C { |
| + m() { |
| + f() {} |
| + } |
| +} |
| +'''); |
| + } |
| + |
| + test_localFunctions() { |
| + checkLibrary(r''' |
| +f() { |
| + f1() {} |
| + { |
| + f2() {} |
| + } |
| +} |
| +'''); |
| + } |
| + |
| + test_localFunctions_inConstructor() { |
| + checkLibrary(r''' |
| +class C { |
| + C() { |
| + f() {} |
| + } |
| +} |
| +'''); |
| + } |
| + |
| + test_localFunctions_inTopLevelGetter() { |
| + checkLibrary(r''' |
| +get g { |
| + f() {} |
| +} |
| +'''); |
| + } |
| + |
| + test_localVariables_inConstructor() { |
| + checkLibrary(r''' |
| +class C { |
| + C() { |
| + int v; |
| + f() {} |
| + } |
| +} |
| +'''); |
| + } |
| + |
| + test_localVariables_inLocalFunction() { |
| + checkLibrary(r''' |
| +f() { |
| + f1() { |
| + int v1 = 1; |
| + } // 2 |
| + f2() { |
| + int v1 = 1; |
| + f3() { |
| + int v2 = 1; |
| + } |
| + } |
| +} |
| +'''); |
| + } |
| + |
| + test_localVariables_inMethod() { |
| + checkLibrary(r''' |
| +class C { |
| + m() { |
| + int v; |
| + } |
| +} |
| +'''); |
| + } |
| + |
| + test_localVariables_inTopLevelFunction() { |
| + checkLibrary(r''' |
| +main() { |
| + int v1 = 1; |
| + { |
| + const String v2 = 'bbb'; |
| + } |
| + Map<int, List<double>> v3; |
| +} |
| +'''); |
| + } |
| + |
| + test_localVariables_inTopLevelGetter() { |
| + checkLibrary(r''' |
| +get g { |
| + int v; |
| +} |
| +'''); |
| + } |
| + |
| test_main_class() { |
| checkLibrary('class main {}'); |
| } |