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

Unified Diff: pkg/analysis_server/test/search/element_references_test.dart

Issue 560553003: Avoid false positives when searching for uses of a constructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/search/element_references_test.dart
diff --git a/pkg/analysis_server/test/search/element_references_test.dart b/pkg/analysis_server/test/search/element_references_test.dart
index 1a8037f9a1f324cdd4061b6026af7e949ddb120f..ac57c12a622f4314af0ea3a8afd45b1a61def533 100644
--- a/pkg/analysis_server/test/search/element_references_test.dart
+++ b/pkg/analysis_server/test/search/element_references_test.dart
@@ -60,7 +60,32 @@ main() {
});
}
- test_constructor_unamed() {
+ test_constructor_named_potential() {
+ // Constructors in other classes shouldn't be considered potential matches,
+ // nor should unresolved method calls, since constructor call sites are
+ // statically bound to their targets).
+ addTestFile('''
+class A {
+ A.named(p); // A
+}
+class B {
+ B.named(p);
+}
+f(x) {
+ new A.named(1);
+ new B.named(2);
+ x.named(3);
+}
+''');
+ return findElementReferences('named(p); // A', true).then((_) {
+ expect(searchElement.kind, ElementKind.CONSTRUCTOR);
+ assertHasResult(SearchResultKind.DECLARATION, '.named(p)', 6);
+ assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6);
+ expect(results, hasLength(2));
+ });
+ }
+
+ test_constructor_unnamed() {
addTestFile('''
class A {
A(p);
@@ -77,6 +102,30 @@ main() {
});
}
+ test_constructor_unnamed_potential() {
+ // Constructors in other classes shouldn't be considered potential matches,
+ // even if they are also unnamed (since constructor call sites are
+ // statically bound to their targets).
+ addTestFile('''
+class A {
+ A(p); // A
+}
+class B {
+ B(p);
+}
+main() {
+ new A(1);
+ new B(2);
scheglov 2014/09/09 20:45:17 Could you add a code that makes the test fail with
Paul Berry 2014/09/09 21:24:59 Done.
+}
+''');
+ return findElementReferences('A(p)', true).then((_) {
+ expect(searchElement.kind, ElementKind.CONSTRUCTOR);
+ assertHasResult(SearchResultKind.DECLARATION, '(p); // A', 0);
+ assertHasResult(SearchResultKind.REFERENCE, '(1)', 0);
+ expect(results, hasLength(2));
+ });
+ }
+
test_field_explicit() {
addTestFile('''
class A {

Powered by Google App Engine
This is Rietveld 408576698