OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 package com.google.dart.compiler; | 5 package com.google.dart.compiler; |
6 | 6 |
7 import com.google.common.collect.Lists; | 7 import com.google.common.collect.Lists; |
8 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; | 8 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; |
9 import com.google.dart.compiler.ast.DartUnit; | 9 import com.google.dart.compiler.ast.DartUnit; |
10 import com.google.dart.compiler.ast.LibraryUnit; | 10 import com.google.dart.compiler.ast.LibraryUnit; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return new DartParser(context); | 266 return new DartParser(context); |
267 } | 267 } |
268 | 268 |
269 /** | 269 /** |
270 * Override this method to provide an alternate {@link ParserContext}. | 270 * Override this method to provide an alternate {@link ParserContext}. |
271 */ | 271 */ |
272 protected ParserContext makeParserContext(Source src, String sourceCode, | 272 protected ParserContext makeParserContext(Source src, String sourceCode, |
273 DartCompilerListener listener) { | 273 DartCompilerListener listener) { |
274 return new DartScannerParserContext(src, sourceCode, listener); | 274 return new DartScannerParserContext(src, sourceCode, listener); |
275 } | 275 } |
| 276 |
| 277 protected static class ErrorExpectation { |
| 278 final ErrorCode errorCode; |
| 279 final int line; |
| 280 final int column; |
| 281 final int length; |
| 282 |
| 283 public ErrorExpectation(ErrorCode errorCode, int line, int column, int lengt
h) { |
| 284 this.errorCode = errorCode; |
| 285 this.line = line; |
| 286 this.column = column; |
| 287 this.length = length; |
| 288 } |
| 289 } |
| 290 |
| 291 protected static ErrorExpectation errEx(ErrorCode errorCode, int line, int col
umn, int length) { |
| 292 return new ErrorExpectation(errorCode, line, column, length); |
| 293 } |
| 294 |
| 295 /** |
| 296 * Asserts that given list of {@link DartCompilationError} is exactly same as
expected. |
| 297 */ |
| 298 protected static void assertErrors(List<DartCompilationError> errors, |
| 299 ErrorExpectation... expectedErrors) { |
| 300 // count of errors |
| 301 if (errors.size() != expectedErrors.length) { |
| 302 fail(String.format( |
| 303 "Expected %s errors, but got %s: %s", |
| 304 expectedErrors.length, |
| 305 errors.size(), |
| 306 errors)); |
| 307 } |
| 308 // content of errors |
| 309 for (int i = 0; i < expectedErrors.length; i++) { |
| 310 ErrorExpectation expectedError = expectedErrors[i]; |
| 311 DartCompilationError actualError = errors.get(i); |
| 312 if (actualError.getErrorCode() != expectedError.errorCode |
| 313 || actualError.getLineNumber() != expectedError.line |
| 314 || actualError.getColumnNumber() != expectedError.column |
| 315 || actualError.getLength() != expectedError.length) { |
| 316 fail(String.format( |
| 317 "Expected %s:%d:%d/%d, but got %s:%d:%d/%d", |
| 318 expectedError.errorCode, |
| 319 expectedError.line, |
| 320 expectedError.column, |
| 321 expectedError.length, |
| 322 actualError.getErrorCode(), |
| 323 actualError.getLineNumber(), |
| 324 actualError.getColumnNumber(), |
| 325 actualError.getLength())); |
| 326 } |
| 327 } |
| 328 } |
276 } | 329 } |
OLD | NEW |