Migrate SearchTest to PubPackageResolutionTest.

Change-Id: Ife51f8eb24bbb50e0f4bba4fa8358ec1f3a9368c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176400
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov
2020-12-16 01:05:09 +00:00
parent 6eddd878c0
commit 02edd6c182
4 changed files with 283 additions and 235 deletions
@@ -72,6 +72,30 @@ class FindElement extends _FindElementBase {
return ImportFindElement(import);
}
LabelElement label(String name) {
LabelElement result;
void updateResult(Element element) {
if (element is LabelElement && element.name == name) {
if (result != null) {
throw StateError('Not unique: $name');
}
result = element;
}
}
unit.accept(FunctionAstVisitor(
label: (node) {
updateResult(node.label.staticElement);
},
));
if (result == null) {
throw StateError('Not found: $name');
}
return result;
}
FunctionElement localFunction(String name) {
FunctionElement result;
@@ -11,6 +11,7 @@ class FunctionAstVisitor extends RecursiveAstVisitor<void> {
final void Function(FunctionDeclarationStatement)
functionDeclarationStatement;
final void Function(FunctionExpression, bool) functionExpression;
final void Function(Label) label;
final void Function(SimpleIdentifier) simpleIdentifier;
final void Function(VariableDeclaration) variableDeclaration;
@@ -18,6 +19,7 @@ class FunctionAstVisitor extends RecursiveAstVisitor<void> {
this.declaredIdentifier,
this.functionDeclarationStatement,
this.functionExpression,
this.label,
this.simpleIdentifier,
this.variableDeclaration,
});
@@ -48,6 +50,14 @@ class FunctionAstVisitor extends RecursiveAstVisitor<void> {
super.visitFunctionExpression(node);
}
@override
void visitLabel(Label node) {
if (label != null) {
label(node);
}
super.visitLabel(node);
}
@override
void visitSimpleIdentifier(SimpleIdentifier node) {
if (simpleIdentifier != null) {
File diff suppressed because it is too large Load Diff
@@ -136,6 +136,10 @@ abstract class ContextResolutionTest
Map<String, String> _declaredVariables = {};
AnalysisContextCollection _analysisContextCollection;
/// If not `null`, [resolveFile] will use the context that corresponds
/// to this path, instead of the given path.
String pathForContextSelection;
List<MockSdkLibrary> get additionalMockSdkLibraries => [];
List<String> get collectionIncludedPaths;
@@ -204,7 +208,7 @@ abstract class ContextResolutionTest
@override
Future<ResolvedUnitResult> resolveFile(String path) {
var analysisContext = contextFor(path);
var analysisContext = contextFor(pathForContextSelection ?? path);
var session = analysisContext.currentSession;
return session.getResolvedUnit(path);
}
@@ -259,6 +263,9 @@ class PubPackageResolutionTest extends ContextResolutionTest {
@override
List<String> get collectionIncludedPaths => [workspaceRootPath];
/// The path that is not in [workspaceRootPath], contains external packages.
String get packagesRootPath => '/packages';
@override
String get testFilePath => '$testPackageLibPath/test.dart';