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

Unified Diff: packages/analyzer/test/generated/test_support.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 5 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: packages/analyzer/test/generated/test_support.dart
diff --git a/packages/analyzer/test/generated/test_support.dart b/packages/analyzer/test/generated/test_support.dart
index 20cc0e2633937cf63bf8b7beb51ac0a9090b6df7..7b3677041c7f9c8574c4cc768b5152cbf1d8996a 100644
--- a/packages/analyzer/test/generated/test_support.dart
+++ b/packages/analyzer/test/generated/test_support.dart
@@ -2,20 +2,25 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library engine.test_support;
+library analyzer.test.generated.test_support;
import 'dart:collection';
-import 'package:analyzer/src/generated/ast.dart' show AstNode, NodeLocator;
-import 'package:analyzer/src/generated/element.dart';
+import 'package:analyzer/dart/ast/ast.dart' show AstNode, SimpleIdentifier;
+import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/dart/element/type.dart';
+import 'package:analyzer/error/error.dart';
+import 'package:analyzer/error/listener.dart';
+import 'package:analyzer/exception/exception.dart';
+import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/generated/engine.dart';
-import 'package:analyzer/src/generated/error.dart';
-import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/source.dart';
+import 'package:plugin/manager.dart';
+import 'package:plugin/plugin.dart';
import 'package:unittest/unittest.dart';
-import 'resolver_test.dart';
+import 'analysis_context_factory.dart';
/**
* The class `EngineTestCase` defines utility methods for making assertions.
@@ -91,7 +96,13 @@ class EngineTestCase {
return null;
}
- void setUp() {}
+ void setUp() {
+ List<Plugin> plugins = <Plugin>[];
+ plugins.addAll(AnalysisEngine.instance.requiredPlugins);
+ plugins.add(AnalysisEngine.instance.commandLinePlugin);
+ plugins.add(AnalysisEngine.instance.optionsPlugin);
+ new ExtensionManager().processPlugins(plugins);
+ }
void tearDown() {}
@@ -119,11 +130,23 @@ class EngineTestCase {
AstNode root, String code, String prefix, Predicate<AstNode> predicate) {
int offset = code.indexOf(prefix);
if (offset == -1) {
- throw new IllegalArgumentException("Not found '$prefix'.");
+ throw new ArgumentError("Not found '$prefix'.");
}
AstNode node = new NodeLocator(offset).searchWithin(root);
return node.getAncestor(predicate);
}
+
+ /**
+ * Find the [SimpleIdentifier] with at offset of the "prefix".
+ */
+ static SimpleIdentifier findSimpleIdentifier(
+ AstNode root, String code, String prefix) {
+ int offset = code.indexOf(prefix);
+ if (offset == -1) {
+ throw new ArgumentError("Not found '$prefix'.");
+ }
+ return new NodeLocator(offset).searchWithin(root);
+ }
}
/**
@@ -393,17 +416,16 @@ class GatheringErrorListener implements AnalysisErrorListener {
}
/**
- * Return `true` if the two errors are equivalent.
- *
- * @param firstError the first error being compared
- * @param secondError the second error being compared
- * @return `true` if the two errors are equivalent
+ * Return `true` if the [actualError] matches the [expectedError].
*/
- bool _equalErrors(AnalysisError firstError, AnalysisError secondError) =>
- identical(firstError.errorCode, secondError.errorCode) &&
- firstError.offset == secondError.offset &&
- firstError.length == secondError.length &&
- _equalSources(firstError.source, secondError.source);
+ bool _equalErrors(AnalysisError expectedError, AnalysisError actualError) {
+ Source expectedSource = expectedError.source;
+ return identical(expectedError.errorCode, actualError.errorCode) &&
+ expectedError.offset == actualError.offset &&
+ expectedError.length == actualError.length &&
+ (expectedSource == null ||
+ _equalSources(expectedSource, actualError.source));
+ }
/**
* Return `true` if the two sources are equivalent.
@@ -438,23 +460,17 @@ class GatheringErrorListener implements AnalysisErrorListener {
Source source = error.source;
LineInfo lineInfo = _lineInfoMap[source];
buffer.writeln();
+ String sourceName = source == null ? '' : source.shortName;
if (lineInfo == null) {
int offset = error.offset;
- StringUtils.printf(buffer, " %s %s (%d..%d)", [
- source == null ? "" : source.shortName,
- error.errorCode,
- offset,
- offset + error.length
- ]);
+ buffer.write(' $sourceName ${error.errorCode} '
+ '($offset..${offset + error.length})');
} else {
LineInfo_Location location = lineInfo.getLocation(error.offset);
- StringUtils.printf(buffer, " %s %s (%d, %d/%d)", [
- source == null ? "" : source.shortName,
- error.errorCode,
- location.lineNumber,
- location.columnNumber,
- error.length
- ]);
+ int lineNumber = location.lineNumber;
+ int columnNumber = location.columnNumber;
+ buffer.write(' $sourceName ${error.errorCode} '
+ '($lineNumber, $columnNumber/${error.length})');
}
}
buffer.writeln();
@@ -465,25 +481,17 @@ class GatheringErrorListener implements AnalysisErrorListener {
Source source = error.source;
LineInfo lineInfo = _lineInfoMap[source];
buffer.writeln();
+ String sourceName = source == null ? '' : source.shortName;
if (lineInfo == null) {
int offset = error.offset;
- StringUtils.printf(buffer, " %s %s (%d..%d): %s", [
- source == null ? "" : source.shortName,
- error.errorCode,
- offset,
- offset + error.length,
- error.message
- ]);
+ buffer.write(' $sourceName ${error.errorCode} '
+ '($offset..${offset + error.length}): ${error.message}');
} else {
LineInfo_Location location = lineInfo.getLocation(error.offset);
- StringUtils.printf(buffer, " %s %s (%d, %d/%d): %s", [
- source == null ? "" : source.shortName,
- error.errorCode,
- location.lineNumber,
- location.columnNumber,
- error.length,
- error.message
- ]);
+ int lineNumber = location.lineNumber;
+ int columnNumber = location.columnNumber;
+ buffer.write(' $sourceName ${error.errorCode} '
+ '($lineNumber, $columnNumber/${error.length}): ${error.message}');
}
}
fail(buffer.toString());
@@ -515,33 +523,18 @@ class GatheringErrorListener implements AnalysisErrorListener {
*/
class TestLogger implements Logger {
/**
- * The number of error messages that were logged.
+ * All logged messages.
*/
- int errorCount = 0;
-
- /**
- * The number of informational messages that were logged.
- */
- int infoCount = 0;
+ List<String> log = [];
@override
void logError(String message, [CaughtException exception]) {
- errorCount++;
- }
-
- @override
- void logError2(String message, Object exception) {
- errorCount++;
+ log.add("error: $message");
}
@override
void logInformation(String message, [CaughtException exception]) {
- infoCount++;
- }
-
- @override
- void logInformation2(String message, Object exception) {
- infoCount++;
+ log.add("info: $message");
}
}
@@ -557,10 +550,6 @@ class TestSource extends Source {
*/
bool generateExceptionOnRead = false;
- @override
- int get modificationStamp =>
- generateExceptionOnRead ? -1 : _modificationStamp;
-
/**
* The number of times that the contents of this source have been requested.
*/
@@ -577,29 +566,30 @@ class TestSource extends Source {
return new TimestampedData<String>(0, _contents);
}
- String get encoding {
- throw new UnsupportedOperationException();
- }
+ String get encoding => _name;
String get fullName {
return _name;
}
int get hashCode => 0;
+
bool get isInSystemLibrary {
return false;
}
+ @override
+ int get modificationStamp =>
+ generateExceptionOnRead ? -1 : _modificationStamp;
+
String get shortName {
return _name;
}
- Uri get uri {
- throw new UnsupportedOperationException();
- }
+ Uri get uri => new Uri.file(_name);
UriKind get uriKind {
- throw new UnsupportedOperationException();
+ throw new UnsupportedError('uriKind');
}
bool operator ==(Object other) {
@@ -611,15 +601,11 @@ class TestSource extends Source {
bool exists() => exists2;
void getContentsToReceiver(Source_ContentReceiver receiver) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedError('getContentsToReceiver');
}
Source resolve(String uri) {
- throw new UnsupportedOperationException();
- }
-
- Uri resolveRelativeUri(Uri uri) {
- return new Uri(scheme: 'file', path: _name).resolveUri(uri);
+ throw new UnsupportedError('resolve');
}
void setContents(String value) {
@@ -638,6 +624,8 @@ class TestSourceWithUri extends TestSource {
TestSourceWithUri(String path, this.uri, [String content])
: super(path, content);
+ String get encoding => uri.toString();
+
UriKind get uriKind {
if (uri == null) {
return UriKind.FILE_URI;
@@ -655,8 +643,4 @@ class TestSourceWithUri extends TestSource {
}
return false;
}
-
- Uri resolveRelativeUri(Uri uri) {
- return this.uri.resolveUri(uri);
- }
}
« no previous file with comments | « packages/analyzer/test/generated/test_all.dart ('k') | packages/analyzer/test/generated/type_system_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698