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

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

Issue 1738283002: Test for duplicate referenced in index and clean up super types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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/index_unit.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:convert'; 5 import 'dart:convert';
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/summary/format.dart'; 9 import 'package:analyzer/src/summary/format.dart';
10 import 'package:analyzer/src/summary/idl.dart'; 10 import 'package:analyzer/src/summary/idl.dart';
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 '''); 515 ''');
516 Element element = findElement('A'); 516 Element element = findElement('A');
517 assertThat(element).isReferencedAt('A myVariable'); 517 assertThat(element).isReferencedAt('A myVariable');
518 } 518 }
519 519
520 /** 520 /**
521 * Asserts that [unitIndex] has an item with the expected properties. 521 * Asserts that [unitIndex] has an item with the expected properties.
522 */ 522 */
523 void _assertHasRelation( 523 void _assertHasRelation(
524 Element element, 524 Element element,
525 IndexRelationKind expectedRelationship, 525 IndexRelationKind expectedRelationKind,
526 ExpectedLocation expectedLocation) { 526 ExpectedLocation expectedLocation) {
527 int elementId = _findElementId(element); 527 int elementId = _findElementId(element);
528 int matchIndex;
528 for (int i = 0; i < unitIndex.locationOffsets.length; i++) { 529 for (int i = 0; i < unitIndex.locationOffsets.length; i++) {
529 if (unitIndex.elements[i] == elementId && 530 if (unitIndex.elements[i] == elementId &&
530 unitIndex.locationOffsets[i] == expectedLocation.offset && 531 unitIndex.locationOffsets[i] == expectedLocation.offset &&
531 unitIndex.locationLengths[i] == expectedLocation.length) { 532 unitIndex.locationLengths[i] == expectedLocation.length) {
532 // TODO(scheglov) continue looking to check that only one usage at one 533 if (matchIndex == null) {
533 // location, e.g. no both 'reference' and 'invocation'. 534 matchIndex = i;
534 return; 535 } else {
536 _failWithIndexDump('more then one ($matchIndex and $i) match found\n'
537 '$element at $expectedLocation');
538 }
535 } 539 }
536 } 540 }
541 if (matchIndex != null &&
542 unitIndex.kinds[matchIndex] == expectedRelationKind) {
543 return;
544 }
537 _failWithIndexDump( 545 _failWithIndexDump(
538 'not found\n$element $expectedRelationship at $expectedLocation'); 546 'not found\n$element $expectedRelationKind at $expectedLocation');
539 } 547 }
540 548
541 ExpectedLocation _expectedLocation(String search, 549 ExpectedLocation _expectedLocation(String search,
542 {int length, bool isQualified: false, bool isResolved: true}) { 550 {int length, bool isQualified: false, bool isResolved: true}) {
543 int offset = findOffset(search); 551 int offset = findOffset(search);
544 if (length == null) { 552 if (length == null) {
545 length = getLeadingIdentifierLength(search); 553 length = getLeadingIdentifierLength(search);
546 } 554 }
547 return new ExpectedLocation( 555 return new ExpectedLocation(
548 testUnitElement, offset, length, isQualified, isResolved); 556 testUnitElement, offset, length, isQualified, isResolved);
549 } 557 }
550 558
551 void _failWithIndexDump(String msg) { 559 void _failWithIndexDump(String msg) {
552 String packageIndexJsonString = 560 String packageIndexJsonString =
553 new JsonEncoder.withIndent(' ').convert(packageIndex.toJson()); 561 new JsonEncoder.withIndent(' ').convert(packageIndex.toJson());
554 fail('$msg in\n' + packageIndexJsonString); 562 fail('$msg in\n' + packageIndexJsonString);
555 } 563 }
556 564
557 /** 565 /**
558 * Return the [element] identifier in [packageIndex] or fail. 566 * Return the [element] identifier in [packageIndex] or fail.
559 */ 567 */
560 int _findElementId(Element element) { 568 int _findElementId(Element element) {
561 int elementUnitId = _getElementUnitId(element); 569 int elementUnitId = _getElementUnitId(element);
562 int offset = element.nameOffset; 570 int offset = element.nameOffset;
563 if (element is LibraryElement || element is CompilationUnitElement) { 571 if (element is LibraryElement || element is CompilationUnitElement) {
564 offset = 0; 572 offset = 0;
565 } 573 }
566 IndexSyntheticElementKind kind = PackageIndexAssembler.getIndexElementKind(e lement); 574 IndexSyntheticElementKind kind =
575 PackageIndexAssembler.getIndexElementKind(element);
567 for (int elementId = 0; 576 for (int elementId = 0;
568 elementId < packageIndex.elementUnits.length; 577 elementId < packageIndex.elementUnits.length;
569 elementId++) { 578 elementId++) {
570 if (packageIndex.elementUnits[elementId] == elementUnitId && 579 if (packageIndex.elementUnits[elementId] == elementUnitId &&
571 packageIndex.elementOffsets[elementId] == offset && 580 packageIndex.elementOffsets[elementId] == offset &&
572 packageIndex.elementKinds[elementId] == kind) { 581 packageIndex.elementKinds[elementId] == kind) {
573 return elementId; 582 return elementId;
574 } 583 }
575 } 584 }
576 _failWithIndexDump('Element $element is not referenced'); 585 _failWithIndexDump('Element $element is not referenced');
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 test._assertHasRelation(element, IndexRelationKind.IS_MIXED_IN_BY, 648 test._assertHasRelation(element, IndexRelationKind.IS_MIXED_IN_BY,
640 test._expectedLocation(search, length: length)); 649 test._expectedLocation(search, length: length));
641 } 650 }
642 651
643 void isReferencedAt(String search, {int length, bool qualified: false}) { 652 void isReferencedAt(String search, {int length, bool qualified: false}) {
644 // TODO(scheglov) use 'qualified' 653 // TODO(scheglov) use 'qualified'
645 test._assertHasRelation(element, IndexRelationKind.IS_REFERENCED_BY, 654 test._assertHasRelation(element, IndexRelationKind.IS_REFERENCED_BY,
646 test._expectedLocation(search, length: length)); 655 test._expectedLocation(search, length: length));
647 } 656 }
648 } 657 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/index_unit.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698