Chromium Code Reviews| Index: pkg/analyzer/test/src/summary/summary_common.dart |
| diff --git a/pkg/analyzer/test/src/summary/summary_common.dart b/pkg/analyzer/test/src/summary/summary_common.dart |
| index 364a2328a2c52721f40fdf06c2108ae1d7423407..9973121a190fa16d02cee6fc9c0c1de7502f1f5c 100644 |
| --- a/pkg/analyzer/test/src/summary/summary_common.dart |
| +++ b/pkg/analyzer/test/src/summary/summary_common.dart |
| @@ -2749,6 +2749,8 @@ class C<T> { |
| expect(executable.isRedirectedConstructor, isFalse); |
| expect(executable.redirectedConstructor, isNull); |
| expect(executable.redirectedConstructorName, isEmpty); |
| + expect(executable.visibleOffset, 0); |
| + expect(executable.visibleLength, 0); |
| } |
| test_constructor_anonymous() { |
| @@ -3511,6 +3513,8 @@ enum E { v }'''; |
| expect(executable.returnType, isNull); |
| expect(executable.isExternal, isFalse); |
| expect(executable.nameOffset, text.indexOf('f')); |
| + expect(executable.visibleOffset, 0); |
| + expect(executable.visibleLength, 0); |
| expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| ReferenceKind.topLevelFunction); |
| @@ -3572,12 +3576,145 @@ enum E { v }'''; |
| expect(executable.parameters, isEmpty); |
| } |
| + test_executable_localFunctions() { |
|
Paul Berry
2016/02/11 15:29:19
Also test local variables and local functions insi
scheglov
2016/02/11 15:50:08
Done.
|
| + String code = r''' |
| +f() { // 1 |
| + f1() {} |
| + { // 2 |
| + f2() {} |
| + } // 3 |
| +} // 4 |
| +'''; |
| + UnlinkedExecutable executable = serializeExecutableText(code); |
| + List<UnlinkedExecutable> functions = executable.executables; |
| + expect(functions, hasLength(2)); |
| + { |
| + UnlinkedExecutable f1 = functions.singleWhere((v) => v.name == 'f1'); |
| + _assertExecutableVisible(code, f1, '{ // 1', '} // 4'); |
| + } |
| + { |
| + UnlinkedExecutable f2 = functions.singleWhere((v) => v.name == 'f2'); |
| + _assertExecutableVisible(code, f2, '{ // 2', '} // 3'); |
| + } |
| + } |
| + |
| + test_executable_localVariables_empty() { |
| + UnlinkedExecutable executable = serializeExecutableText(r''' |
| +f() { |
| +} |
| +'''); |
| + expect(executable.variables, isEmpty); |
| + } |
| + |
| + test_executable_localVariables_inConstructor() { |
| + String code = r''' |
| +class C { |
| + C() { // 1 |
| + int v; |
| + } // 2 |
| +} |
| +'''; |
| + UnlinkedExecutable executable = |
| + findExecutable('', executables: serializeClassText(code).executables); |
| + List<UnlinkedVariable> variables = executable.variables; |
| + expect(variables, hasLength(1)); |
| + { |
| + UnlinkedVariable v = variables.singleWhere((v) => v.name == 'v'); |
| + _assertVariableVisible(code, v, '{ // 1', '} // 2'); |
| + checkTypeRef(v.type, 'dart:core', 'dart:core', 'int'); |
| + } |
| + } |
| + |
| + test_executable_localVariables_inLocalFunctions() { |
| + String code = r''' |
| +f() { |
| + f1() { // 1 |
| + int v1 = 1; |
| + } // 2 |
| + f2() { // 3 |
| + int v1 = 1; |
| + f3() { // 4 |
| + int v2 = 1; |
| + } // 5 |
| + } // 6 |
| +} // 7 |
| +'''; |
| + UnlinkedExecutable executable = serializeExecutableText(code); |
| + List<UnlinkedExecutable> functions = executable.executables; |
| + expect(functions, hasLength(2)); |
| + // f - f1 |
| + { |
| + UnlinkedExecutable f1 = functions.singleWhere((v) => v.name == 'f1'); |
| + List<UnlinkedVariable> variables = f1.variables; |
| + expect(variables, hasLength(1)); |
| + // f1 - v1 |
| + UnlinkedVariable v1 = variables.singleWhere((v) => v.name == 'v1'); |
| + _assertVariableVisible(code, v1, '{ // 1', '} // 2'); |
| + checkTypeRef(v1.type, 'dart:core', 'dart:core', 'int'); |
| + } |
| + // f - f2 |
| + { |
| + UnlinkedExecutable f2 = functions.singleWhere((v) => v.name == 'f2'); |
| + List<UnlinkedVariable> variables2 = f2.variables; |
| + List<UnlinkedExecutable> functions2 = f2.executables; |
| + expect(variables2, hasLength(1)); |
| + expect(functions2, hasLength(1)); |
| + // f - f2 - v1 |
| + UnlinkedVariable v1 = variables2.singleWhere((v) => v.name == 'v1'); |
| + _assertVariableVisible(code, v1, '{ // 3', '} // 6'); |
| + checkTypeRef(v1.type, 'dart:core', 'dart:core', 'int'); |
| + // f - f2 - f3 |
| + UnlinkedExecutable f3 = functions2.singleWhere((v) => v.name == 'f3'); |
| + _assertExecutableVisible(code, f3, '{ // 3', '} // 6'); |
| + List<UnlinkedVariable> variables3 = f3.variables; |
| + List<UnlinkedExecutable> functions3 = f3.executables; |
| + expect(variables3, hasLength(1)); |
| + expect(functions3, hasLength(0)); |
| + // f - f3 - v2 |
| + UnlinkedVariable v2 = variables3.singleWhere((v) => v.name == 'v2'); |
| + _assertVariableVisible(code, v2, '{ // 4', '} // 5'); |
| + checkTypeRef(v2.type, 'dart:core', 'dart:core', 'int'); |
| + } |
| + } |
| + |
| + test_executable_localVariables_inTopLevelFunction() { |
| + String code = r''' |
| +f() { // 1 |
| + int v1 = 1; |
| + { // 2 |
| + int v2 = 2; |
| + } // 3 |
| + var v3 = 3; |
| +} // 4 |
| +'''; |
| + UnlinkedExecutable executable = serializeExecutableText(code); |
| + List<UnlinkedVariable> variables = executable.variables; |
| + expect(variables, hasLength(3)); |
| + { |
| + UnlinkedVariable v1 = variables.singleWhere((v) => v.name == 'v1'); |
| + _assertVariableVisible(code, v1, '{ // 1', '} // 4'); |
| + checkTypeRef(v1.type, 'dart:core', 'dart:core', 'int'); |
| + } |
| + { |
| + UnlinkedVariable v2 = variables.singleWhere((v) => v.name == 'v2'); |
| + _assertVariableVisible(code, v2, '{ // 2', '} // 3'); |
| + checkTypeRef(v2.type, 'dart:core', 'dart:core', 'int'); |
| + } |
| + { |
| + UnlinkedVariable v3 = variables.singleWhere((v) => v.name == 'v3'); |
| + _assertVariableVisible(code, v3, '{ // 1', '} // 4'); |
| + expect(v3.type, isNull); |
| + } |
| + } |
| + |
| test_executable_member_function() { |
| UnlinkedExecutable executable = findExecutable('f', |
| executables: serializeClassText('class C { f() {} }').executables); |
| expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); |
| expect(executable.returnType, isNull); |
| expect(executable.isExternal, isFalse); |
| + expect(executable.visibleOffset, 0); |
| + expect(executable.visibleLength, 0); |
| } |
| test_executable_member_function_explicit_return() { |
| @@ -6094,6 +6231,15 @@ var v;'''; |
| } |
| } |
| + void _assertExecutableVisible(String code, UnlinkedExecutable f, |
| + String visibleBegin, String visibleEnd) { |
| + int expectedVisibleOffset = code.indexOf(visibleBegin); |
| + int expectedVisibleLength = |
| + code.indexOf(visibleEnd) - expectedVisibleOffset + 1; |
| + expect(f.visibleOffset, expectedVisibleOffset); |
| + expect(f.visibleLength, expectedVisibleLength); |
| + } |
| + |
| void _assertUnlinkedConst(UnlinkedConst constExpr, |
| {bool isInvalid: false, |
| List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[], |
| @@ -6113,6 +6259,15 @@ var v;'''; |
| referenceValidators[i](constExpr.references[i]); |
| } |
| } |
| + |
| + void _assertVariableVisible( |
| + String code, UnlinkedVariable v, String visibleBegin, String visibleEnd) { |
| + int expectedVisibleOffset = code.indexOf(visibleBegin); |
| + int expectedVisibleLength = |
| + code.indexOf(visibleEnd) - expectedVisibleOffset + 1; |
| + expect(v.visibleOffset, expectedVisibleOffset); |
| + expect(v.visibleLength, expectedVisibleLength); |
| + } |
| } |
| /** |