Skip to content

Commit

Permalink
[wildcards] find reference tests
Browse files Browse the repository at this point in the history
See: #55681

Change-Id: Ia1f8cc08d7a79fe66fce9ac108543cb2a6aebd34
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381943
Commit-Queue: Phil Quitslund <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
pq authored and Commit Queue committed Aug 23, 2024
1 parent b551690 commit 2df7d1a
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions pkg/analysis_server/test/services/search/search_engine_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,46 @@ class B extends A {
);
}

Future<void> test_searchReferences_parameter_topLevelShadow_wildcard() async {
var code = '''
int _ = 0;
int f(int _) => _;
''';
await resolveTestCode(code);

var parameter = findElement.parameter('_');
var parameterMatches = await searchEngine.searchReferences(parameter);
expect(parameterMatches, isEmpty);

var topLevelVariable = findElement.topVar('_');
var topLevelVariableMatches =
await searchEngine.searchReferences(topLevelVariable);
expect(
topLevelVariableMatches,
unorderedEquals([
predicate((SearchMatch m) {
return m.kind == MatchKind.READ &&
identical(m.element, findElement.topFunction('f')) &&
m.sourceRange.offset == code.indexOf('_;') &&
m.sourceRange.length == '_'.length;
}),
]),
);
}

Future<void> test_searchReferences_parameter_wildcard() async {
var code = '''
f(int _) {}
''';
await resolveTestCode(code);

var element = findElement.parameter('_');
var matches = await searchEngine.searchReferences(element);

// No crashes.
expect(matches, isEmpty);
}

Future<void>
test_searchReferences_topFunction_parameter_optionalNamed_anywhere() async {
var code = '''
Expand All @@ -603,6 +643,54 @@ void g() {
);
}

Future<void> test_searchReferences_underscoreField() async {
var code = '''
class A {
final _ = 1;
int a() => _;
}
''';
await resolveTestCode(code);

var element = findElement.field('_');
var matches = await searchEngine.searchReferences(element);

expect(
matches,
unorderedEquals([
predicate((SearchMatch m) {
return m.kind == MatchKind.READ &&
identical(m.element, findElement.method('a')) &&
m.sourceRange.offset == code.indexOf('_;') &&
m.sourceRange.length == '_'.length;
}),
]),
);
}

Future<void> test_searchReferences_underscoreTopLevelVariable() async {
var code = '''
final _ = 1;
int f() => _;
''';
await resolveTestCode(code);

var element = findElement.topVar('_');
var matches = await searchEngine.searchReferences(element);

expect(
matches,
unorderedEquals([
predicate((SearchMatch m) {
return m.kind == MatchKind.READ &&
identical(m.element, findElement.topFunction('f')) &&
m.sourceRange.offset == code.indexOf('_;') &&
m.sourceRange.length == '_'.length;
}),
]),
);
}

Future<void> test_searchTopLevelDeclarations() async {
newFile('$testPackageLibPath/a.dart', '''
class A {}
Expand Down

0 comments on commit 2df7d1a

Please sign in to comment.