| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test_utils; | 5 library test_utils; |
| 6 | 6 |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 | 8 |
| 9 import 'package:analyzer_experimental/src/generated/java_core.dart' show CharSeq
uence; |
| 9 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo
ntext, AnalysisContextImpl; | 10 import 'package:analyzer_experimental/src/generated/engine.dart' show AnalysisCo
ntext, AnalysisContextImpl; |
| 10 import 'package:analyzer_experimental/src/generated/source.dart'; | 11 import 'package:analyzer_experimental/src/generated/source.dart'; |
| 11 import 'package:analyzer_experimental/src/generated/error.dart'; | 12 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 12 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 13 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 13 import 'package:analyzer_experimental/src/generated/ast.dart'; | 14 import 'package:analyzer_experimental/src/generated/ast.dart'; |
| 14 import 'package:analyzer_experimental/src/generated/parser.dart'; | 15 import 'package:analyzer_experimental/src/generated/parser.dart'; |
| 15 | 16 |
| 16 | 17 |
| 17 /// Instances of the class [_GatheringErrorListener] implement an error listener | 18 /// Instances of the class [_GatheringErrorListener] implement an error listener |
| 18 /// that collects all of the errors passed to it for later examination. | 19 /// that collects all of the errors passed to it for later examination. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 class _UnsupportedOperationException implements Exception { | 191 class _UnsupportedOperationException implements Exception { |
| 191 String toString() => 'UnsupportedOperationException'; | 192 String toString() => 'UnsupportedOperationException'; |
| 192 } | 193 } |
| 193 | 194 |
| 194 | 195 |
| 195 /// Parse the given [source] as a statement and assert, if provided, that | 196 /// Parse the given [source] as a statement and assert, if provided, that |
| 196 /// exactly a given set of [expectedErrorCodes] are encountered. | 197 /// exactly a given set of [expectedErrorCodes] are encountered. |
| 197 Statement parseStatement(String source, [List<ErrorCode> expectedErrorCodes]) { | 198 Statement parseStatement(String source, [List<ErrorCode> expectedErrorCodes]) { |
| 198 | 199 |
| 199 var listener = new _GatheringErrorListener(); | 200 var listener = new _GatheringErrorListener(); |
| 200 var scanner = new StringScanner(null, source, listener); | 201 var reader = new CharSequenceReader(new CharSequence(source)); |
| 202 var scanner = new Scanner(null, reader, listener); |
| 201 listener.setLineInfo(new _TestSource(), scanner.lineStarts); | 203 listener.setLineInfo(new _TestSource(), scanner.lineStarts); |
| 202 | 204 |
| 203 var token = scanner.tokenize(); | 205 var token = scanner.tokenize(); |
| 204 var parser = new Parser(null, listener); | 206 var parser = new Parser(null, listener); |
| 205 var statement = parser.parseStatement(token); | 207 var statement = parser.parseStatement(token); |
| 206 expect(statement, isNotNull); | 208 expect(statement, isNotNull); |
| 207 | 209 |
| 208 if (expectedErrorCodes != null) { | 210 if (expectedErrorCodes != null) { |
| 209 listener.expectErrors(expectedErrorCodes); | 211 listener.expectErrors(expectedErrorCodes); |
| 210 } | 212 } |
| 211 | 213 |
| 212 return statement; | 214 return statement; |
| 213 } | 215 } |
| OLD | NEW |