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

Unified Diff: pkg/analyzer/test/services/test_utils.dart

Issue 882813007: Make source be a target (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove AbstractSource Created 5 years, 11 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
« no previous file with comments | « pkg/analyzer/test/generated/test_support.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/services/test_utils.dart
diff --git a/pkg/analyzer/test/services/test_utils.dart b/pkg/analyzer/test/services/test_utils.dart
index 4db82190a40de103333064a1c4e2159b98132541..a0fb2d1ecc1841da1d89ed5fb845b9997bea7509 100644
--- a/pkg/analyzer/test/services/test_utils.dart
+++ b/pkg/analyzer/test/services/test_utils.dart
@@ -4,14 +4,47 @@
library test_utils;
-import 'package:unittest/unittest.dart';
-
+import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/engine.dart';
-import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/error.dart';
-import 'package:analyzer/src/generated/scanner.dart';
-import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/parser.dart';
+import 'package:analyzer/src/generated/scanner.dart';
+import 'package:analyzer/src/generated/source.dart';
+import 'package:unittest/unittest.dart';
+
+
+/// Parse the given [source] as a statement and assert, if provided, that
+/// exactly a given set of [expectedErrorCodes] are encountered.
+Statement parseStatement(String source, [List<ErrorCode> expectedErrorCodes]) {
+
+ var listener = new _GatheringErrorListener();
+ var reader = new CharSequenceReader(source);
+ var scanner = new Scanner(null, reader, listener);
+ listener.setLineInfo(new _TestSource(), scanner.lineStarts);
+
+ var token = scanner.tokenize();
+ var parser = new Parser(null, listener);
+ var statement = parser.parseStatement(token);
+ expect(statement, isNotNull);
+
+ if (expectedErrorCodes != null) {
+ listener.expectErrors(expectedErrorCodes);
+ }
+
+ return statement;
+}
+
+
+Set<_MapEntry> _getMapEntrySet(Map m) {
+ var result = new Set();
+ m.forEach((k, v) {
+ result.add(new _MapEntry(k, v));
+ });
+ return result;
+}
+
+
+_unsupported() => throw new _UnsupportedOperationException();
/// Instances of the class [_GatheringErrorListener] implement an error listener
@@ -23,18 +56,6 @@ class _GatheringErrorListener implements AnalysisErrorListener {
/// A table mapping sources to the line information for the source.
final Map<Source, LineInfo> _lineInfoMap = new Map<Source, LineInfo>();
- void onError(AnalysisError error) {
- _errors.add(error);
- }
-
-
- /// Sets the line information associated with the given source to the given
- /// information.
- void setLineInfo(Source source, List<int> lineStarts) {
- _lineInfoMap[source] = new LineInfo(lineStarts);
- }
-
-
/// Asserts that the number of errors that have been gathered matches the
/// number of errors that are given and that they have the expected error
/// codes. The order in which the errors were gathered is ignored.
@@ -122,15 +143,18 @@ class _GatheringErrorListener implements AnalysisErrorListener {
}
}
-}
+ void onError(AnalysisError error) {
+ _errors.add(error);
+ }
+
+
+ /// Sets the line information associated with the given source to the given
+ /// information.
+ void setLineInfo(Source source, List<int> lineStarts) {
+ _lineInfoMap[source] = new LineInfo(lineStarts);
+ }
-Set<_MapEntry> _getMapEntrySet(Map m) {
- var result = new Set();
- m.forEach((k, v) {
- result.add(new _MapEntry(k, v));
- });
- return result;
}
@@ -142,63 +166,38 @@ class _MapEntry<K, V> {
V getValue() => _value;
}
+class _TestSource extends Source {
-class _TestSource implements Source {
-
- bool operator == (Object object) => object is _TestSource;
+ TimestampedData<String> get contents => _unsupported();
AnalysisContext get context => _unsupported();
- void getContentsToReceiver(Source_ContentReceiver receiver) => _unsupported();
+ String get encoding => _unsupported();
String get fullName => _unsupported();
- String get shortName => _unsupported();
+ bool get isInSystemLibrary => _unsupported();
- String get encoding => _unsupported();
+ int get modificationStamp => _unsupported();
+
+ String get shortName => _unsupported();
- int get modificationStamp =>_unsupported();
+ Uri get uri => _unsupported();
UriKind get uriKind => _unsupported();
- bool exists() => true;
+ bool operator ==(Object object) => object is _TestSource;
- bool get isInSystemLibrary => _unsupported();
+ bool exists() => true;
- Uri get uri => _unsupported();
+ void getContentsToReceiver(Source_ContentReceiver receiver) => _unsupported();
Source resolve(String uri) => _unsupported();
Uri resolveRelativeUri(Uri uri) => _unsupported();
-
- TimestampedData<String> get contents => _unsupported();
}
-_unsupported() => throw new _UnsupportedOperationException();
-
class _UnsupportedOperationException implements Exception {
String toString() => 'UnsupportedOperationException';
}
-
-
-/// Parse the given [source] as a statement and assert, if provided, that
-/// exactly a given set of [expectedErrorCodes] are encountered.
-Statement parseStatement(String source, [List<ErrorCode> expectedErrorCodes]) {
-
- var listener = new _GatheringErrorListener();
- var reader = new CharSequenceReader(source);
- var scanner = new Scanner(null, reader, listener);
- listener.setLineInfo(new _TestSource(), scanner.lineStarts);
-
- var token = scanner.tokenize();
- var parser = new Parser(null, listener);
- var statement = parser.parseStatement(token);
- expect(statement, isNotNull);
-
- if (expectedErrorCodes != null) {
- listener.expectErrors(expectedErrorCodes);
- }
-
- return statement;
-}
« no previous file with comments | « pkg/analyzer/test/generated/test_support.dart ('k') | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698