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

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: 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
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 4261 matching lines...) Expand 10 before | Expand all | Expand 10 after
4272 } 4272 }
4273 4273
4274 test_executable_param_name() { 4274 test_executable_param_name() {
4275 String text = 'f(x) {}'; 4275 String text = 'f(x) {}';
4276 UnlinkedExecutable executable = serializeExecutableText(text); 4276 UnlinkedExecutable executable = serializeExecutableText(text);
4277 expect(executable.parameters, hasLength(1)); 4277 expect(executable.parameters, hasLength(1));
4278 expect(executable.parameters[0].name, 'x'); 4278 expect(executable.parameters[0].name, 'x');
4279 expect(executable.parameters[0].nameOffset, text.indexOf('x')); 4279 expect(executable.parameters[0].nameOffset, text.indexOf('x'));
4280 } 4280 }
4281 4281
4282 test_executable_param_visibleRange() {
Paul Berry 2016/02/11 21:10:39 Add tests to verify that visibleLength and visible
scheglov 2016/02/11 22:26:20 Done.
4283 String text = r'''
4284 f(x) { // 1
4285 f2(y) { // 2
4286 } // 3
4287 } // 4
4288 ''';
4289 UnlinkedExecutable f = serializeExecutableText(text);
4290 UnlinkedExecutable f2 = f.localFunctions[0];
4291 _assertParameterVisible(text, f.parameters[0], '{ // 1', '} // 4');
4292 _assertParameterVisible(text, f2.parameters[0], '{ // 2', '} // 3');
4293 }
4294
4282 test_executable_param_no_flags() { 4295 test_executable_param_no_flags() {
4283 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); 4296 UnlinkedExecutable executable = serializeExecutableText('f(x) {}');
4284 expect(executable.parameters[0].isFunctionTyped, isFalse); 4297 expect(executable.parameters[0].isFunctionTyped, isFalse);
4285 expect(executable.parameters[0].isInitializingFormal, isFalse); 4298 expect(executable.parameters[0].isInitializingFormal, isFalse);
4286 } 4299 }
4287 4300
4288 test_executable_param_non_function_typed() { 4301 test_executable_param_non_function_typed() {
4289 UnlinkedExecutable executable = serializeExecutableText('f(g) {}'); 4302 UnlinkedExecutable executable = serializeExecutableText('f(g) {}');
4290 expect(executable.parameters[0].isFunctionTyped, isFalse); 4303 expect(executable.parameters[0].isFunctionTyped, isFalse);
4291 } 4304 }
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after
6545 } 6558 }
6546 6559
6547 void _assertVariableVisible( 6560 void _assertVariableVisible(
6548 String code, UnlinkedVariable v, String visibleBegin, String visibleEnd) { 6561 String code, UnlinkedVariable v, String visibleBegin, String visibleEnd) {
6549 int expectedVisibleOffset = code.indexOf(visibleBegin); 6562 int expectedVisibleOffset = code.indexOf(visibleBegin);
6550 int expectedVisibleLength = 6563 int expectedVisibleLength =
6551 code.indexOf(visibleEnd) - expectedVisibleOffset + 1; 6564 code.indexOf(visibleEnd) - expectedVisibleOffset + 1;
6552 expect(v.visibleOffset, expectedVisibleOffset); 6565 expect(v.visibleOffset, expectedVisibleOffset);
6553 expect(v.visibleLength, expectedVisibleLength); 6566 expect(v.visibleLength, expectedVisibleLength);
6554 } 6567 }
6568
6569 void _assertParameterVisible(
6570 String code, UnlinkedParam p, String visibleBegin, String visibleEnd) {
6571 int expectedVisibleOffset = code.indexOf(visibleBegin);
6572 int expectedVisibleLength =
6573 code.indexOf(visibleEnd) - expectedVisibleOffset + 1;
6574 expect(p.visibleOffset, expectedVisibleOffset);
6575 expect(p.visibleLength, expectedVisibleLength);
6576 }
6555 } 6577 }
6556 6578
6557 /** 6579 /**
6558 * Description of expectations for a prelinked prefix reference. 6580 * Description of expectations for a prelinked prefix reference.
6559 */ 6581 */
6560 class _PrefixExpectation { 6582 class _PrefixExpectation {
6561 final ReferenceKind kind; 6583 final ReferenceKind kind;
6562 final String name; 6584 final String name;
6563 final bool inLibraryDefiningUnit; 6585 final bool inLibraryDefiningUnit;
6564 final String absoluteUri; 6586 final String absoluteUri;
6565 final String relativeUri; 6587 final String relativeUri;
6566 final int numTypeParameters; 6588 final int numTypeParameters;
6567 6589
6568 _PrefixExpectation(this.kind, this.name, 6590 _PrefixExpectation(this.kind, this.name,
6569 {this.inLibraryDefiningUnit: false, 6591 {this.inLibraryDefiningUnit: false,
6570 this.absoluteUri, 6592 this.absoluteUri,
6571 this.relativeUri, 6593 this.relativeUri,
6572 this.numTypeParameters: 0}); 6594 this.numTypeParameters: 0});
6573 } 6595 }
OLDNEW
« pkg/analyzer/lib/src/summary/idl.dart ('K') | « 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