Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 analyzer.test.src.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| (...skipping 7715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7726 serializeClassText('class C { static var v = 0; }').fields[0]; | 7726 serializeClassText('class C { static var v = 0; }').fields[0]; |
| 7727 checkInferredTypeSlot(v.inferredTypeSlot, 'dart:core', 'dart:core', 'int'); | 7727 checkInferredTypeSlot(v.inferredTypeSlot, 'dart:core', 'dart:core', 'int'); |
| 7728 } | 7728 } |
| 7729 | 7729 |
| 7730 test_field_inferred_type_static_implicit_uninitialized() { | 7730 test_field_inferred_type_static_implicit_uninitialized() { |
| 7731 UnlinkedVariable v = | 7731 UnlinkedVariable v = |
| 7732 serializeClassText('class C { static var v; }').fields[0]; | 7732 serializeClassText('class C { static var v; }').fields[0]; |
| 7733 expect(v.inferredTypeSlot, 0); | 7733 expect(v.inferredTypeSlot, 0); |
| 7734 } | 7734 } |
| 7735 | 7735 |
| 7736 test_field_propagated_type_final_immediate() { | |
| 7737 UnlinkedVariable v = | |
| 7738 serializeClassText('class C { final v = 0; }').fields[0]; | |
| 7739 checkLinkedTypeSlot(v.propagatedTypeSlot, 'dart:core', 'dart:core', 'int'); | |
| 7740 } | |
| 7741 | |
| 7742 test_field_static() { | 7736 test_field_static() { |
| 7743 UnlinkedVariable variable = | 7737 UnlinkedVariable variable = |
| 7744 serializeClassText('class C { static int i; }').fields[0]; | 7738 serializeClassText('class C { static int i; }').fields[0]; |
| 7745 expect(variable.isStatic, isTrue); | 7739 expect(variable.isStatic, isTrue); |
| 7746 expect(variable.initializer, isNull); | 7740 expect(variable.initializer, isNull); |
| 7747 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 7741 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 7748 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); | 7742 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); |
| 7749 expect(unlinkedUnits[0].publicNamespace.names[0].members, hasLength(1)); | 7743 expect(unlinkedUnits[0].publicNamespace.names[0].members, hasLength(1)); |
| 7750 expect(unlinkedUnits[0].publicNamespace.names[0].members[0].name, 'i'); | 7744 expect(unlinkedUnits[0].publicNamespace.names[0].members[0].name, 'i'); |
| 7751 expect(unlinkedUnits[0].publicNamespace.names[0].members[0].kind, | 7745 expect(unlinkedUnits[0].publicNamespace.names[0].members[0].kind, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 7780 if (!checkAstDerivedData) { | 7774 if (!checkAstDerivedData) { |
| 7781 // The element model doesn't contain the initializer expressions needed | 7775 // The element model doesn't contain the initializer expressions needed |
| 7782 // for type inference. TODO(paulberry): fix. | 7776 // for type inference. TODO(paulberry): fix. |
| 7783 return; | 7777 return; |
| 7784 } | 7778 } |
| 7785 UnlinkedVariable variable = | 7779 UnlinkedVariable variable = |
| 7786 serializeClassText('class C { var x = 0; }').fields[0]; | 7780 serializeClassText('class C { var x = 0; }').fields[0]; |
| 7787 expect(variable.initializer.bodyExpr, isNotNull); | 7781 expect(variable.initializer.bodyExpr, isNotNull); |
| 7788 } | 7782 } |
| 7789 | 7783 |
| 7790 test_fully_linked_references_follow_other_references() { | |
|
Paul Berry
2016/08/29 20:52:16
Rather than delete this test we should rewrite it
scheglov
2016/08/29 22:01:47
I restored these 3 tests and changed to use 'infer
| |
| 7791 if (skipFullyLinkedData) { | |
| 7792 return; | |
| 7793 } | |
| 7794 serializeLibraryText('final x = 0; String y;'); | |
| 7795 checkLinkedTypeSlot(unlinkedUnits[0].variables[0].propagatedTypeSlot, | |
| 7796 'dart:core', 'dart:core', 'int'); | |
| 7797 checkTypeRef( | |
| 7798 unlinkedUnits[0].variables[1].type, 'dart:core', 'dart:core', 'String'); | |
| 7799 // Even though the definition of y follows the definition of x, the linked | |
| 7800 // type reference for x should use a higher numbered reference than the | |
| 7801 // unlinked type reference for y. | |
| 7802 EntityRef propagatedType = | |
| 7803 getTypeRefForSlot(unlinkedUnits[0].variables[0].propagatedTypeSlot); | |
| 7804 expect(unlinkedUnits[0].variables[1].type.reference, | |
| 7805 lessThan(propagatedType.reference)); | |
| 7806 } | |
| 7807 | |
| 7808 test_function_documented() { | 7784 test_function_documented() { |
| 7809 String text = ''' | 7785 String text = ''' |
| 7810 // Extra comment so doc comment offset != 0 | 7786 // Extra comment so doc comment offset != 0 |
| 7811 /** | 7787 /** |
| 7812 * Docs | 7788 * Docs |
| 7813 */ | 7789 */ |
| 7814 f() {}'''; | 7790 f() {}'''; |
| 7815 UnlinkedExecutable executable = serializeExecutableText(text); | 7791 UnlinkedExecutable executable = serializeExecutableText(text); |
| 7816 expect(executable.documentationComment, isNotNull); | 7792 expect(executable.documentationComment, isNotNull); |
| 7817 checkDocumentationComment(executable.documentationComment, text); | 7793 checkDocumentationComment(executable.documentationComment, text); |
| (...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8704 String text = ''' | 8680 String text = ''' |
| 8705 int foo; | 8681 int foo; |
| 8706 class Test {} | 8682 class Test {} |
| 8707 | 8683 |
| 8708 int bar;''' | 8684 int bar;''' |
| 8709 .replaceAll('\r\n', '\n'); | 8685 .replaceAll('\r\n', '\n'); |
| 8710 serializeLibraryText(text); | 8686 serializeLibraryText(text); |
| 8711 expect(unlinkedUnits[0].lineStarts, [0, 9, 23, 24]); | 8687 expect(unlinkedUnits[0].lineStarts, [0, 9, 23, 24]); |
| 8712 } | 8688 } |
| 8713 | 8689 |
| 8714 test_linked_reference_reuse() { | |
|
Paul Berry
2016/08/29 20:52:16
Ditto.
| |
| 8715 if (skipFullyLinkedData) { | |
| 8716 return; | |
| 8717 } | |
| 8718 // When the reference for a linked type is the same as an explicitly | |
| 8719 // referenced type, the explicit reference should be re-used. | |
| 8720 addNamedSource('/a.dart', 'class C {}'); | |
| 8721 addNamedSource('/b.dart', 'import "a.dart"; C f() => null;'); | |
| 8722 serializeLibraryText( | |
| 8723 'import "a.dart"; import "b.dart"; C c1; final c2 = f();'); | |
| 8724 int explicitReference = findVariable('c1').type.reference; | |
| 8725 expect(getTypeRefForSlot(findVariable('c2').propagatedTypeSlot).reference, | |
| 8726 explicitReference); | |
| 8727 } | |
| 8728 | |
| 8729 test_linked_type_dependency_reuse() { | |
|
Paul Berry
2016/08/29 20:52:16
Ditto.
| |
| 8730 if (skipFullyLinkedData) { | |
| 8731 return; | |
| 8732 } | |
| 8733 // When the dependency for a linked type is the same as an explicit | |
| 8734 // dependency, the explicit dependency should be re-used. | |
| 8735 addNamedSource('/a.dart', 'class C {} class D {}'); | |
| 8736 addNamedSource('/b.dart', 'import "a.dart"; D f() => null;'); | |
| 8737 serializeLibraryText( | |
| 8738 'import "a.dart"; import "b.dart"; C c; final d = f();'); | |
| 8739 int cReference = findVariable('c').type.reference; | |
| 8740 int explicitDependency = linked.units[0].references[cReference].dependency; | |
| 8741 int dReference = | |
| 8742 getTypeRefForSlot(findVariable('d').propagatedTypeSlot).reference; | |
| 8743 expect( | |
| 8744 linked.units[0].references[dReference].dependency, explicitDependency); | |
| 8745 } | |
| 8746 | |
| 8747 test_local_names_take_precedence_over_imported_names() { | 8690 test_local_names_take_precedence_over_imported_names() { |
| 8748 addNamedSource('/a.dart', 'class C {} class D {}'); | 8691 addNamedSource('/a.dart', 'class C {} class D {}'); |
| 8749 serializeLibraryText(''' | 8692 serializeLibraryText(''' |
| 8750 import 'a.dart'; | 8693 import 'a.dart'; |
| 8751 class C {} | 8694 class C {} |
| 8752 C c; | 8695 C c; |
| 8753 D d;'''); | 8696 D d;'''); |
| 8754 checkTypeRef(findVariable('c').type, null, null, 'C'); | 8697 checkTypeRef(findVariable('c').type, null, null, 'C'); |
| 8755 checkTypeRef(findVariable('d').type, absUri('/a.dart'), 'a.dart', 'D'); | 8698 checkTypeRef(findVariable('d').type, absUri('/a.dart'), 'a.dart', 'D'); |
| 8756 } | 8699 } |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9585 } | 9528 } |
| 9586 ''').localVariables[0]; | 9529 ''').localVariables[0]; |
| 9587 EntityRef inferredType = | 9530 EntityRef inferredType = |
| 9588 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); | 9531 getTypeRefForSlot(variable.initializer.inferredReturnTypeSlot); |
| 9589 checkLinkedTypeRef( | 9532 checkLinkedTypeRef( |
| 9590 inferredType.syntheticReturnType, 'dart:core', 'dart:core', 'int'); | 9533 inferredType.syntheticReturnType, 'dart:core', 'dart:core', 'int'); |
| 9591 checkParamTypeRef(inferredType.syntheticParams[0].type, 2); | 9534 checkParamTypeRef(inferredType.syntheticParams[0].type, 2); |
| 9592 checkParamTypeRef(inferredType.syntheticParams[1].type, 1); | 9535 checkParamTypeRef(inferredType.syntheticParams[1].type, 1); |
| 9593 } | 9536 } |
| 9594 | 9537 |
| 9595 test_syntheticFunctionType_noArguments() { | |
| 9596 if (skipFullyLinkedData) { | |
| 9597 return; | |
| 9598 } | |
| 9599 UnlinkedVariable variable = serializeVariableText(''' | |
| 9600 final v = f() ? () => 0 : () => 1; | |
| 9601 bool f() => true; | |
| 9602 '''); | |
| 9603 EntityRef propagatedType = getTypeRefForSlot(variable.propagatedTypeSlot); | |
| 9604 checkLinkedTypeRef( | |
| 9605 propagatedType.syntheticReturnType, 'dart:core', 'dart:core', 'int'); | |
| 9606 expect(propagatedType.syntheticParams, isEmpty); | |
| 9607 } | |
| 9608 | |
| 9609 test_syntheticFunctionType_withArguments() { | |
| 9610 if (skipFullyLinkedData) { | |
| 9611 return; | |
| 9612 } | |
| 9613 UnlinkedVariable variable = serializeVariableText(''' | |
| 9614 final v = f() ? (int x, String y) => 0 : (int x, String y) => 1; | |
| 9615 bool f() => true; | |
| 9616 '''); | |
| 9617 EntityRef propagatedType = getTypeRefForSlot(variable.propagatedTypeSlot); | |
| 9618 checkTypeRef( | |
| 9619 propagatedType.syntheticReturnType, 'dart:core', 'dart:core', 'int'); | |
| 9620 expect(propagatedType.syntheticParams, hasLength(2)); | |
| 9621 checkTypeRef(propagatedType.syntheticParams[0].type, 'dart:core', | |
| 9622 'dart:core', 'int'); | |
| 9623 checkTypeRef(propagatedType.syntheticParams[1].type, 'dart:core', | |
| 9624 'dart:core', 'String'); | |
| 9625 } | |
| 9626 | |
| 9627 test_type_arguments_explicit() { | 9538 test_type_arguments_explicit() { |
| 9628 EntityRef typeRef = serializeTypeText('List<int>'); | 9539 EntityRef typeRef = serializeTypeText('List<int>'); |
| 9629 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', | 9540 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', |
| 9630 numTypeParameters: 1, numTypeArguments: 1); | 9541 numTypeParameters: 1, numTypeArguments: 1); |
| 9631 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); | 9542 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); |
| 9632 } | 9543 } |
| 9633 | 9544 |
| 9634 test_type_arguments_explicit_dynamic() { | 9545 test_type_arguments_explicit_dynamic() { |
| 9635 EntityRef typeRef = serializeTypeText('List<dynamic>'); | 9546 EntityRef typeRef = serializeTypeText('List<dynamic>'); |
| 9636 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', | 9547 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10328 UnlinkedVariable variable = | 10239 UnlinkedVariable variable = |
| 10329 serializeVariableText('int i;', variableName: 'i'); | 10240 serializeVariableText('int i;', variableName: 'i'); |
| 10330 expect(variable.isStatic, isFalse); | 10241 expect(variable.isStatic, isFalse); |
| 10331 } | 10242 } |
| 10332 | 10243 |
| 10333 test_variable_private() { | 10244 test_variable_private() { |
| 10334 serializeVariableText('int _i;', variableName: '_i'); | 10245 serializeVariableText('int _i;', variableName: '_i'); |
| 10335 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 10246 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 10336 } | 10247 } |
| 10337 | 10248 |
| 10338 test_variable_propagated_type_final_immediate() { | |
| 10339 UnlinkedVariable v = serializeVariableText('final v = 0;'); | |
| 10340 checkLinkedTypeSlot(v.propagatedTypeSlot, 'dart:core', 'dart:core', 'int'); | |
| 10341 } | |
| 10342 | |
| 10343 test_variable_propagated_type_new_reference() { | |
| 10344 if (skipFullyLinkedData) { | |
| 10345 return; | |
| 10346 } | |
| 10347 UnlinkedVariable v = serializeVariableText('final v = 0;'); | |
| 10348 // Since the propagated type of `v` is `int`, and there are no references | |
| 10349 // to `int` elsewhere in the source file, a new linked reference should | |
| 10350 // have been created for it, with no associated unlinked reference. | |
| 10351 expect(v.propagatedTypeSlot, isNot(0)); | |
| 10352 EntityRef type = getTypeRefForSlot(v.propagatedTypeSlot); | |
| 10353 expect(type, isNotNull); | |
| 10354 expect(type.reference, | |
| 10355 greaterThanOrEqualTo(unlinkedUnits[0].references.length)); | |
| 10356 } | |
| 10357 | |
| 10358 test_variable_propagated_type_omit_dynamic() { | |
| 10359 if (skipFullyLinkedData) { | |
| 10360 return; | |
| 10361 } | |
| 10362 UnlinkedVariable v = serializeVariableText('final v = <int, dynamic>{};'); | |
| 10363 EntityRef type = getTypeRefForSlot(v.propagatedTypeSlot); | |
| 10364 checkLinkedTypeRef(type, 'dart:core', 'dart:core', 'Map', | |
| 10365 numTypeParameters: 2, numTypeArguments: 2); | |
| 10366 checkLinkedTypeRef(type.typeArguments[0], 'dart:core', 'dart:core', 'int'); | |
| 10367 checkLinkedDynamicTypeRef(type.typeArguments[1]); | |
| 10368 } | |
| 10369 | |
| 10370 test_variable_propagatedTypeSlot_const() { | |
| 10371 // Const variables are propagable so they have a nonzero | |
| 10372 // propagatedTypeSlot. | |
| 10373 UnlinkedVariable variable = serializeVariableText('const v = 0;'); | |
| 10374 expect(variable.propagatedTypeSlot, isNot(0)); | |
| 10375 } | |
| 10376 | |
| 10377 test_variable_propagatedTypeSlot_final() { | |
| 10378 // Final variables are propagable so they have a nonzero | |
| 10379 // propagatedTypeSlot. | |
| 10380 UnlinkedVariable variable = serializeVariableText('final v = 0;'); | |
| 10381 expect(variable.propagatedTypeSlot, isNot(0)); | |
| 10382 } | |
| 10383 | |
| 10384 test_variable_propagatedTypeSlot_non_propagable() { | |
| 10385 // Non-final non-const variables aren't propagable so they don't have a | |
| 10386 // propagatedTypeSlot. | |
| 10387 UnlinkedVariable variable = serializeVariableText('var v;'); | |
| 10388 expect(variable.propagatedTypeSlot, 0); | |
| 10389 } | |
| 10390 | |
| 10391 test_variable_static() { | 10249 test_variable_static() { |
| 10392 UnlinkedVariable variable = | 10250 UnlinkedVariable variable = |
| 10393 serializeClassText('class C { static int i; }').fields[0]; | 10251 serializeClassText('class C { static int i; }').fields[0]; |
| 10394 expect(variable.isStatic, isTrue); | 10252 expect(variable.isStatic, isTrue); |
| 10395 } | 10253 } |
| 10396 | 10254 |
| 10397 test_variable_type() { | 10255 test_variable_type() { |
| 10398 UnlinkedVariable variable = | 10256 UnlinkedVariable variable = |
| 10399 serializeVariableText('int i;', variableName: 'i'); | 10257 serializeVariableText('int i;', variableName: 'i'); |
| 10400 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 10258 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10578 class _PrefixExpectation { | 10436 class _PrefixExpectation { |
| 10579 final ReferenceKind kind; | 10437 final ReferenceKind kind; |
| 10580 final String name; | 10438 final String name; |
| 10581 final String absoluteUri; | 10439 final String absoluteUri; |
| 10582 final String relativeUri; | 10440 final String relativeUri; |
| 10583 final int numTypeParameters; | 10441 final int numTypeParameters; |
| 10584 | 10442 |
| 10585 _PrefixExpectation(this.kind, this.name, | 10443 _PrefixExpectation(this.kind, this.name, |
| 10586 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); | 10444 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); |
| 10587 } | 10445 } |
| OLD | NEW |