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

Unified Diff: pkg/analyzer/test/src/dart/analysis/search_test.dart

Issue 2529473002: Implement search for other local elements. (Closed)
Patch Set: Add tests for function/method type parameters. Created 4 years, 1 month 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
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/dart/analysis/search_test.dart
diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart
index 67ade8b5a45359988e1490ae56a7584959dd1810..28ddd9e5b7ab90e8383448866aa421b026d60941 100644
--- a/pkg/analyzer/test/src/dart/analysis/search_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart
@@ -81,7 +81,24 @@ class ExpectedResult {
class SearchTest extends BaseAnalysisDriverTest {
static const testUri = 'package:test/test.dart';
- test_searchReferences_Label() async {
+ test_searchReferences_FunctionElement_local() async {
+ addTestFile('''
+main() {
+ test() {}
+ test();
+ print(test);
+}
+''');
+ FunctionElement element = await _findElement('test');
+ List<String> main = [testUri, 'main'];
+ var expected = [
+ _expectId(main, SearchResultKind.INVOCATION, 'test();'),
+ _expectId(main, SearchResultKind.REFERENCE, 'test);')
+ ];
+ await _verifyReferences(element, expected);
+ }
+
+ test_searchReferences_LabelElement() async {
addTestFile('''
main() {
label:
@@ -93,7 +110,7 @@ label:
}
}
''');
- Element element = await _findElementAtString('label:');
+ Element element = await _findElement('label');
List<String> main = [testUri, 'main'];
var expected = [
_expectId(main, SearchResultKind.REFERENCE, 'label; // 1'),
@@ -102,7 +119,7 @@ label:
await _verifyReferences(element, expected);
}
- test_searchReferences_localVariable() async {
+ test_searchReferences_LocalVariableElement() async {
addTestFile(r'''
main() {
var v;
@@ -112,7 +129,7 @@ main() {
v();
}
''');
- Element element = await _findElementAtString('v;');
+ Element element = await _findElement('v');
List<String> main = [testUri, 'main'];
var expected = [
_expectId(main, SearchResultKind.WRITE, 'v = 1;'),
@@ -123,7 +140,7 @@ main() {
await _verifyReferences(element, expected);
}
- test_searchReferences_localVariable_inForEachLoop() async {
+ test_searchReferences_localVariableElement_inForEachLoop() async {
addTestFile('''
main() {
for (var v in []) {
@@ -145,6 +162,67 @@ main() {
await _verifyReferences(element, expected);
}
+ test_searchReferences_TypeParameterElement_ofClass() async {
+ addTestFile('''
+class A<T> {
+ foo(T a) {}
+ bar(T b) {}
+}
+''');
+ TypeParameterElement element = await _findElement('T');
+ var expected = [
+ _expectId([testUri, 'A', 'foo', 'a'], SearchResultKind.REFERENCE, 'T a'),
+ _expectId([testUri, 'A', 'bar', 'b'], SearchResultKind.REFERENCE, 'T b'),
+ ];
+ await _verifyReferences(element, expected);
+ }
+
+ test_searchReferences_TypeParameterElement_ofLocalFunction() async {
+ addTestFile('''
+main() {
+ void foo<T>(T a) {
+ void bar(T b) {}
+ }
+}
+''');
+ TypeParameterElement element = await _findElement('T');
+ var expected = [
+ _expectId(
+ [testUri, 'main', 'foo', 'a'], SearchResultKind.REFERENCE, 'T a'),
+ _expectId([testUri, 'main', 'foo', 'bar', 'b'],
+ SearchResultKind.REFERENCE, 'T b'),
+ ];
+ await _verifyReferences(element, expected);
+ }
+
+ test_searchReferences_TypeParameterElement_ofMethod() async {
+ addTestFile('''
+class A {
+ foo<T>(T p) {}
+}
+''');
+ TypeParameterElement element = await _findElement('T');
+ var expected = [
+ _expectId([testUri, 'A', 'foo', 'p'], SearchResultKind.REFERENCE, 'T p'),
+ ];
+ await _verifyReferences(element, expected);
+ }
+
+ test_searchReferences_TypeParameterElement_ofTopLevelFunction() async {
+ addTestFile('''
+foo<T>(T a) {
+ bar(T b) {}
+}
+''');
+ TypeParameterElement element = await _findElement('T');
+ var expected = [
+ _expectId([testUri, 'foo', 'a'], SearchResultKind.REFERENCE, 'T a'),
+ _expectId(
+ [testUri, 'foo', 'bar', 'b'], SearchResultKind.REFERENCE, 'T b'),
+ ];
+ await _verifyReferences(element, expected);
+ }
+
ExpectedResult _expectId(
List<String> enclosingComponents, SearchResultKind kind, String search,
{int length, bool isResolved: true, bool isQualified: false}) {
@@ -156,6 +234,11 @@ main() {
isResolved: isResolved, isQualified: isQualified);
}
+ Future<Element> _findElement(String name) async {
+ AnalysisResult result = await driver.getResult(testFile);
+ return findChildElement(result.unit.element, name);
+ }
+
Future<Element> _findElementAtString(String search) async {
AnalysisResult result = await driver.getResult(testFile);
int offset = findOffset(search);
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698