| Index: compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
|
| diff --git a/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java b/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
|
| index 6b31dc3026c3a1368db4f71d48c6dc626a3c0f7e..1e4ff5af89bd4f40f8fcf35c2cfa6a077de18924 100644
|
| --- a/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
|
| +++ b/compiler/javatests/com/google/dart/compiler/resolver/NegativeResolverTest.java
|
| @@ -6,8 +6,7 @@ package com.google.dart.compiler.resolver;
|
|
|
| import com.google.dart.compiler.CompilerTestCase;
|
| import com.google.dart.compiler.DartCompilationError;
|
| -import com.google.dart.compiler.ErrorSeverity;
|
| -import com.google.dart.compiler.SubSystem;
|
| +import com.google.dart.compiler.ErrorCode;
|
| import com.google.dart.compiler.ast.DartUnit;
|
| import com.google.dart.compiler.testing.TestCompilerContext;
|
|
|
| @@ -19,17 +18,75 @@ public class NegativeResolverTest extends CompilerTestCase {
|
| List<DartCompilationError> errors = new ArrayList<DartCompilationError>();
|
| List<DartCompilationError> typeErrors = new ArrayList<DartCompilationError>();
|
|
|
| + private static class ErrorExpectation {
|
| + final ErrorCode errorCode;
|
| + final int line;
|
| + final int column;
|
| + public ErrorExpectation(ErrorCode errorCode, int line, int column) {
|
| + this.errorCode = errorCode;
|
| + this.line = line;
|
| + this.column = column;
|
| + }
|
| +
|
| + }
|
| +
|
| + private static ErrorExpectation errEx(ErrorCode errorCode, int line, int column) {
|
| + return new ErrorExpectation(errorCode, line, column);
|
| +
|
| + }
|
| +
|
| public void checkNumErrors(String fileName, int expectedErrorCount) {
|
| DartUnit unit = parseUnit(fileName);
|
| - unit.addTopLevelNode(ResolverTestCase.makeClass("Object", null));
|
| - unit.addTopLevelNode(ResolverTestCase.makeClass("Function", null));
|
| - ResolverTestCase.resolve(unit, getContext());
|
| + resolve(unit);
|
| assertEquals(new ArrayList<DartCompilationError>(), typeErrors);
|
| if (errors.size() != expectedErrorCount) {
|
| fail(String.format("Expected %s errors, but got %s: %s",
|
| expectedErrorCount, errors.size(), errors));
|
| }
|
| }
|
| +
|
| + private void resolve(DartUnit unit) {
|
| + unit.addTopLevelNode(ResolverTestCase.makeClass("int", null));
|
| + unit.addTopLevelNode(ResolverTestCase.makeClass("Object", null));
|
| + unit.addTopLevelNode(ResolverTestCase.makeClass("String", null));
|
| + unit.addTopLevelNode(ResolverTestCase.makeClass("Function", null));
|
| + unit.addTopLevelNode(ResolverTestCase.makeClass("List", null, "T"));
|
| + unit.addTopLevelNode(ResolverTestCase.makeClass("Map", null, "K", "V"));
|
| + ResolverTestCase.resolve(unit, getContext());
|
| + }
|
| +
|
| + /**
|
| + * Parses given Dart source, runs {@link Resolver} and checks that expected errors were generated.
|
| + */
|
| + public void checkErrors(String source, ErrorExpectation ...expectedErrors) {
|
| + DartUnit unit = parseUnit("Test.dart", source);
|
| + resolve(unit);
|
| + // count of errors
|
| + if (errors.size() != expectedErrors.length) {
|
| + fail(String.format(
|
| + "Expected %s errors, but got %s: %s",
|
| + expectedErrors.length,
|
| + errors.size(),
|
| + errors));
|
| + }
|
| + // content of errors
|
| + for (int i = 0; i < expectedErrors.length; i++) {
|
| + ErrorExpectation expectedError = expectedErrors[i];
|
| + DartCompilationError actualError = errors.get(i);
|
| + if (actualError.getErrorCode() != expectedError.errorCode
|
| + || actualError.getLineNumber() != expectedError.line
|
| + || actualError.getColumnNumber() != expectedError.column) {
|
| + fail(String.format(
|
| + "Expected %s:%s:%s, but got %s:%s:%s",
|
| + expectedError.errorCode,
|
| + expectedError.line,
|
| + expectedError.column,
|
| + actualError.getErrorCode(),
|
| + actualError.getLineNumber(),
|
| + actualError.getColumnNumber()));
|
| + }
|
| + }
|
| + }
|
|
|
| public void testInitializer1() {
|
| checkNumErrors("Initializer1NegativeTest.dart", 1);
|
| @@ -56,11 +113,25 @@ public class NegativeResolverTest extends CompilerTestCase {
|
| }
|
|
|
| public void testArrayLiteralNegativeTest() {
|
| - checkNumErrors("ArrayLiteralNegativeTest.dart", 1);
|
| + checkErrors(
|
| + makeCode(
|
| + "class A {",
|
| + " main() {",
|
| + " List<int, int> ints = [1];",
|
| + " }",
|
| + "}"),
|
| + errEx(TypeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS, 3, 5));
|
| }
|
|
|
| public void testMapLiteralNegativeTest() {
|
| - checkNumErrors("MapLiteralNegativeTest.dart", 1);
|
| + checkErrors(
|
| + makeCode(
|
| + "class A {",
|
| + " main() {",
|
| + " Map<String, int, int> map = {'foo':1};",
|
| + " }",
|
| + "}"),
|
| + errEx(TypeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS, 3, 5));
|
| }
|
|
|
| public void testCall1() {
|
| @@ -187,12 +258,7 @@ public class NegativeResolverTest extends CompilerTestCase {
|
| return new TestCompilerContext() {
|
| @Override
|
| public void onError(DartCompilationError event) {
|
| - if (event.getErrorCode().getSubSystem() == SubSystem.STATIC_TYPE) {
|
| - typeErrors.add(event);
|
| - }
|
| - if (event.getErrorCode().getErrorSeverity() == ErrorSeverity.ERROR) {
|
| - errors.add(event);
|
| - }
|
| + errors.add(event);
|
| }
|
| };
|
| }
|
|
|