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

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

Issue 1689283002: Serialize parameters visible ranges. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Changes for review comments. Created 4 years, 10 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/lib/src/summary/summarize_elements.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 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/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 5711 matching lines...) Expand 10 before | Expand all | Expand 10 after
5722 5722
5723 test_method_inferred_type_static_implicit_return() { 5723 test_method_inferred_type_static_implicit_return() {
5724 UnlinkedExecutable f = serializeClassText( 5724 UnlinkedExecutable f = serializeClassText(
5725 'class C extends D { static f() => null; }' 5725 'class C extends D { static f() => null; }'
5726 ' class D { static int f() => null; }', 5726 ' class D { static int f() => null; }',
5727 className: 'C') 5727 className: 'C')
5728 .executables[0]; 5728 .executables[0];
5729 expect(f.inferredReturnTypeSlot, 0); 5729 expect(f.inferredReturnTypeSlot, 0);
5730 } 5730 }
5731 5731
5732 test_parameter_visibleRange_abstractMethod() {
5733 UnlinkedExecutable m = findExecutable('m',
5734 executables:
5735 serializeClassText('abstract class C { m(p); }').executables,
5736 failIfAbsent: true);
5737 _assertParameterZeroVisibleRange(m.parameters[0]);
5738 }
5739
5740 test_parameter_visibleRange_function_blockBody() {
5741 String text = r'''
5742 f(x) { // 1
5743 f2(y) { // 2
5744 } // 3
5745 } // 4
5746 ''';
5747 UnlinkedExecutable f = serializeExecutableText(text);
5748 UnlinkedExecutable f2 = f.localFunctions[0];
5749 _assertParameterVisible(text, f.parameters[0], '{ // 1', '} // 4');
5750 _assertParameterVisible(text, f2.parameters[0], '{ // 2', '} // 3');
5751 }
5752
5753 test_parameter_visibleRange_function_emptyBody() {
5754 UnlinkedExecutable f = serializeExecutableText('external f(x);');
5755 _assertParameterZeroVisibleRange(f.parameters[0]);
5756 }
5757
5758 test_parameter_visibleRange_function_expressionBody() {
5759 String text = r'''
5760 f(x) => 42;
5761 ''';
5762 UnlinkedExecutable f = serializeExecutableText(text);
5763 _assertParameterVisible(text, f.parameters[0], '=>', ';');
5764 }
5765
5766 test_parameter_visibleRange_inFunctionTypedParameter() {
5767 String text = 'f(g(p)) {}';
5768 UnlinkedExecutable f = serializeExecutableText(text);
5769 UnlinkedParam g = f.parameters[0];
5770 UnlinkedParam p = g.parameters[0];
5771 expect(g.name, 'g');
5772 expect(p.name, 'p');
5773 _assertParameterVisible(text, g, '{', '}');
5774 _assertParameterZeroVisibleRange(p);
5775 }
5776
5777 test_parameter_visibleRange_typedef() {
5778 UnlinkedTypedef type = serializeTypedefText('typedef F(x);');
5779 _assertParameterZeroVisibleRange(type.parameters[0]);
5780 }
5781
5732 test_part_declaration() { 5782 test_part_declaration() {
5733 addNamedSource('/a.dart', 'part of my.lib;'); 5783 addNamedSource('/a.dart', 'part of my.lib;');
5734 String text = 'library my.lib; part "a.dart"; // <-part'; 5784 String text = 'library my.lib; part "a.dart"; // <-part';
5735 serializeLibraryText(text); 5785 serializeLibraryText(text);
5736 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1)); 5786 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1));
5737 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart'); 5787 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart');
5738 expect(unlinkedUnits[0].parts, hasLength(1)); 5788 expect(unlinkedUnits[0].parts, hasLength(1));
5739 expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf('"a.dart"')); 5789 expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf('"a.dart"'));
5740 expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part')); 5790 expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part'));
5741 } 5791 }
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
6517 6567
6518 void _assertExecutableVisible(String code, UnlinkedExecutable f, 6568 void _assertExecutableVisible(String code, UnlinkedExecutable f,
6519 String visibleBegin, String visibleEnd) { 6569 String visibleBegin, String visibleEnd) {
6520 int expectedVisibleOffset = code.indexOf(visibleBegin); 6570 int expectedVisibleOffset = code.indexOf(visibleBegin);
6521 int expectedVisibleLength = 6571 int expectedVisibleLength =
6522 code.indexOf(visibleEnd) - expectedVisibleOffset + 1; 6572 code.indexOf(visibleEnd) - expectedVisibleOffset + 1;
6523 expect(f.visibleOffset, expectedVisibleOffset); 6573 expect(f.visibleOffset, expectedVisibleOffset);
6524 expect(f.visibleLength, expectedVisibleLength); 6574 expect(f.visibleLength, expectedVisibleLength);
6525 } 6575 }
6526 6576
6577 void _assertParameterVisible(
6578 String code, UnlinkedParam p, String visibleBegin, String visibleEnd) {
6579 int expectedVisibleOffset = code.indexOf(visibleBegin);
6580 int expectedVisibleLength =
6581 code.indexOf(visibleEnd) - expectedVisibleOffset + 1;
6582 expect(p.visibleOffset, expectedVisibleOffset);
6583 expect(p.visibleLength, expectedVisibleLength);
6584 }
6585
6586 void _assertParameterZeroVisibleRange(UnlinkedParam p) {
6587 expect(p.visibleOffset, isZero);
6588 expect(p.visibleLength, isZero);
6589 }
6590
6527 void _assertUnlinkedConst(UnlinkedConst constExpr, 6591 void _assertUnlinkedConst(UnlinkedConst constExpr,
6528 {bool isInvalid: false, 6592 {bool isInvalid: false,
6529 List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[], 6593 List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[],
6530 List<int> ints: const <int>[], 6594 List<int> ints: const <int>[],
6531 List<double> doubles: const <double>[], 6595 List<double> doubles: const <double>[],
6532 List<String> strings: const <String>[], 6596 List<String> strings: const <String>[],
6533 List<_EntityRefValidator> referenceValidators: 6597 List<_EntityRefValidator> referenceValidators:
6534 const <_EntityRefValidator>[]}) { 6598 const <_EntityRefValidator>[]}) {
6535 expect(constExpr, isNotNull); 6599 expect(constExpr, isNotNull);
6536 expect(constExpr.isInvalid, isInvalid); 6600 expect(constExpr.isInvalid, isInvalid);
(...skipping 27 matching lines...) Expand all
6564 final String absoluteUri; 6628 final String absoluteUri;
6565 final String relativeUri; 6629 final String relativeUri;
6566 final int numTypeParameters; 6630 final int numTypeParameters;
6567 6631
6568 _PrefixExpectation(this.kind, this.name, 6632 _PrefixExpectation(this.kind, this.name,
6569 {this.inLibraryDefiningUnit: false, 6633 {this.inLibraryDefiningUnit: false,
6570 this.absoluteUri, 6634 this.absoluteUri,
6571 this.relativeUri, 6635 this.relativeUri,
6572 this.numTypeParameters: 0}); 6636 this.numTypeParameters: 0});
6573 } 6637 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698