Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 test.search.element_references; | 5 library test.search.element_references; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import '../reflective_tests.dart'; | 10 import '../reflective_tests.dart'; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 new A.named(2); | 53 new A.named(2); |
| 54 } | 54 } |
| 55 '''); | 55 '''); |
| 56 return findElementReferences('named(p)', false).then((_) { | 56 return findElementReferences('named(p)', false).then((_) { |
| 57 expect(searchElement.kind, ElementKind.CONSTRUCTOR); | 57 expect(searchElement.kind, ElementKind.CONSTRUCTOR); |
| 58 assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6); | 58 assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6); |
| 59 assertHasResult(SearchResultKind.REFERENCE, '.named(2)', 6); | 59 assertHasResult(SearchResultKind.REFERENCE, '.named(2)', 6); |
| 60 }); | 60 }); |
| 61 } | 61 } |
| 62 | 62 |
| 63 test_constructor_unamed() { | 63 test_constructor_named_potential() { |
| 64 // Constructors in other classes shouldn't be considered potential matches, | |
| 65 // nor should unresolved method calls, since constructor call sites are | |
| 66 // statically bound to their targets). | |
| 67 addTestFile(''' | |
| 68 class A { | |
| 69 A.named(p); // A | |
| 70 } | |
| 71 class B { | |
| 72 B.named(p); | |
| 73 } | |
| 74 f(x) { | |
| 75 new A.named(1); | |
| 76 new B.named(2); | |
| 77 x.named(3); | |
| 78 } | |
| 79 '''); | |
| 80 return findElementReferences('named(p); // A', true).then((_) { | |
| 81 expect(searchElement.kind, ElementKind.CONSTRUCTOR); | |
| 82 assertHasResult(SearchResultKind.DECLARATION, '.named(p)', 6); | |
| 83 assertHasResult(SearchResultKind.REFERENCE, '.named(1)', 6); | |
| 84 expect(results, hasLength(2)); | |
| 85 }); | |
| 86 } | |
| 87 | |
| 88 test_constructor_unnamed() { | |
| 64 addTestFile(''' | 89 addTestFile(''' |
| 65 class A { | 90 class A { |
| 66 A(p); | 91 A(p); |
| 67 } | 92 } |
| 68 main() { | 93 main() { |
| 69 new A(1); | 94 new A(1); |
| 70 new A(2); | 95 new A(2); |
| 71 } | 96 } |
| 72 '''); | 97 '''); |
| 73 return findElementReferences('A(p)', false).then((_) { | 98 return findElementReferences('A(p)', false).then((_) { |
| 74 expect(searchElement.kind, ElementKind.CONSTRUCTOR); | 99 expect(searchElement.kind, ElementKind.CONSTRUCTOR); |
| 75 assertHasResult(SearchResultKind.REFERENCE, '(1)', 0); | 100 assertHasResult(SearchResultKind.REFERENCE, '(1)', 0); |
| 76 assertHasResult(SearchResultKind.REFERENCE, '(2)', 0); | 101 assertHasResult(SearchResultKind.REFERENCE, '(2)', 0); |
| 77 }); | 102 }); |
| 78 } | 103 } |
| 79 | 104 |
| 105 test_constructor_unnamed_potential() { | |
| 106 // Constructors in other classes shouldn't be considered potential matches, | |
| 107 // even if they are also unnamed (since constructor call sites are | |
| 108 // statically bound to their targets). | |
| 109 addTestFile(''' | |
| 110 class A { | |
| 111 A(p); // A | |
| 112 } | |
| 113 class B { | |
| 114 B(p); | |
| 115 } | |
| 116 main() { | |
| 117 new A(1); | |
| 118 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.
| |
| 119 } | |
| 120 '''); | |
| 121 return findElementReferences('A(p)', true).then((_) { | |
| 122 expect(searchElement.kind, ElementKind.CONSTRUCTOR); | |
| 123 assertHasResult(SearchResultKind.DECLARATION, '(p); // A', 0); | |
| 124 assertHasResult(SearchResultKind.REFERENCE, '(1)', 0); | |
| 125 expect(results, hasLength(2)); | |
| 126 }); | |
| 127 } | |
| 128 | |
| 80 test_field_explicit() { | 129 test_field_explicit() { |
| 81 addTestFile(''' | 130 addTestFile(''' |
| 82 class A { | 131 class A { |
| 83 var fff; // declaration | 132 var fff; // declaration |
| 84 A(this.fff); // in constructor | 133 A(this.fff); // in constructor |
| 85 m() { | 134 m() { |
| 86 fff = 2; | 135 fff = 2; |
| 87 fff += 3; | 136 fff += 3; |
| 88 print(fff); // in m() | 137 print(fff); // in m() |
| 89 fff(); // in m() | 138 fff(); // in m() |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 } | 639 } |
| 591 '''); | 640 '''); |
| 592 return findElementReferences('T> {', false).then((_) { | 641 return findElementReferences('T> {', false).then((_) { |
| 593 expect(searchElement.kind, ElementKind.TYPE_PARAMETER); | 642 expect(searchElement.kind, ElementKind.TYPE_PARAMETER); |
| 594 expect(results, hasLength(2)); | 643 expect(results, hasLength(2)); |
| 595 assertHasResult(SearchResultKind.REFERENCE, 'T f;'); | 644 assertHasResult(SearchResultKind.REFERENCE, 'T f;'); |
| 596 assertHasResult(SearchResultKind.REFERENCE, 'T m()'); | 645 assertHasResult(SearchResultKind.REFERENCE, 'T m()'); |
| 597 }); | 646 }); |
| 598 } | 647 } |
| 599 } | 648 } |
| OLD | NEW |