| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.resolver; | 5 package com.google.dart.compiler.resolver; |
| 6 | 6 |
| 7 import static com.google.dart.compiler.common.ErrorExpectation.errEx; | |
| 8 | |
| 9 import com.google.common.base.Joiner; | 7 import com.google.common.base.Joiner; |
| 10 import com.google.dart.compiler.DartCompilationError; | 8 import com.google.dart.compiler.DartCompilationError; |
| 11 import com.google.dart.compiler.ErrorCode; | 9 import com.google.dart.compiler.ErrorCode; |
| 12 import com.google.dart.compiler.ast.DartClass; | 10 import com.google.dart.compiler.ast.DartClass; |
| 13 import com.google.dart.compiler.common.ErrorExpectation; | 11 import com.google.dart.compiler.common.ErrorExpectation; |
| 14 import com.google.dart.compiler.type.DynamicType; | 12 import com.google.dart.compiler.type.DynamicType; |
| 15 import com.google.dart.compiler.type.InterfaceType; | 13 import com.google.dart.compiler.type.InterfaceType; |
| 16 import com.google.dart.compiler.type.Type; | 14 import com.google.dart.compiler.type.Type; |
| 17 import com.google.dart.compiler.type.Types; | 15 import com.google.dart.compiler.type.Types; |
| 18 | 16 |
| 17 import static com.google.dart.compiler.common.ErrorExpectation.errEx; |
| 18 |
| 19 import junit.framework.Assert; | 19 import junit.framework.Assert; |
| 20 | 20 |
| 21 import java.util.List; | 21 import java.util.List; |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Basic tests of the resolver. | 24 * Basic tests of the resolver. |
| 25 */ | 25 */ |
| 26 public class ResolverTest extends ResolverTestCase { | 26 public class ResolverTest extends ResolverTestCase { |
| 27 private final DartClass object = makeClass("Object", null); | 27 private final DartClass object = makeClass("Object", null); |
| 28 private final DartClass array = makeClass("Array", makeType("Object"), "E"); | 28 private final DartClass array = makeClass("Array", makeType("Object"), "E"); |
| (...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 "class MyClass<E> {", | 953 "class MyClass<E> {", |
| 954 " foo() {", | 954 " foo() {", |
| 955 " a: b: while (true) { break a; } // ok", | 955 " a: b: while (true) { break a; } // ok", |
| 956 " a: b: while (true) { break b; } // ok", | 956 " a: b: while (true) { break b; } // ok", |
| 957 " a: b: while (true) { break c; } // error, no such label", | 957 " a: b: while (true) { break c; } // error, no such label", |
| 958 " }", | 958 " }", |
| 959 "}"), | 959 "}"), |
| 960 ErrorExpectation.errEx(ResolverErrorCode.CANNOT_RESOLVE_LABEL, 6, 32, 1)
); | 960 ErrorExpectation.errEx(ResolverErrorCode.CANNOT_RESOLVE_LABEL, 6, 32, 1)
); |
| 961 } | 961 } |
| 962 | 962 |
| 963 public void test_multipleLabelsSwitch() { |
| 964 resolveAndTest(Joiner.on("\n").join( |
| 965 "class Object {}", |
| 966 "foo() {", |
| 967 " switch(1) {", |
| 968 " a: case (0): break;", |
| 969 " a: case (1): break;", |
| 970 " }", |
| 971 "}"), |
| 972 ErrorExpectation.errEx(ResolverErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATE
MENT, 5, 3, 2)); |
| 973 } |
| 974 |
| 963 public void test_new_noSuchType() throws Exception { | 975 public void test_new_noSuchType() throws Exception { |
| 964 resolveAndTest(Joiner.on("\n").join( | 976 resolveAndTest(Joiner.on("\n").join( |
| 965 "class Object {}", | 977 "class Object {}", |
| 966 "class MyClass {", | 978 "class MyClass {", |
| 967 " foo() {", | 979 " foo() {", |
| 968 " new Unknown();", | 980 " new Unknown();", |
| 969 " }", | 981 " }", |
| 970 "}"), | 982 "}"), |
| 971 ResolverErrorCode.NO_SUCH_TYPE); | 983 ResolverErrorCode.NO_SUCH_TYPE); |
| 972 } | 984 } |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 "// filler filler filler filler filler filler filler filler filler f
iller", | 1352 "// filler filler filler filler filler filler filler filler filler f
iller", |
| 1341 "class Object {}", | 1353 "class Object {}", |
| 1342 "class A {", | 1354 "class A {", |
| 1343 " var x;", | 1355 " var x;", |
| 1344 " A() : x = foo() {}", | 1356 " A() : x = foo() {}", |
| 1345 " foo() {}", | 1357 " foo() {}", |
| 1346 "}", | 1358 "}", |
| 1347 ""), | 1359 ""), |
| 1348 errEx(ResolverErrorCode.INSTANCE_METHOD_FROM_INITIALIZER, 5, 13, 5)); | 1360 errEx(ResolverErrorCode.INSTANCE_METHOD_FROM_INITIALIZER, 5, 13, 5)); |
| 1349 } | 1361 } |
| 1350 | 1362 |
| 1351 /** | 1363 /** |
| 1352 * "this" is not accessible to initializers, so reference of instance method i
s error. | 1364 * "this" is not accessible to initializers, so reference of instance method i
s error. |
| 1353 * <p> | 1365 * <p> |
| 1354 * http://code.google.com/p/dart/issues/detail?id=2477 | 1366 * http://code.google.com/p/dart/issues/detail?id=2477 |
| 1355 */ | 1367 */ |
| 1356 public void test_referenceInstanceMethod_fromInitializer() throws Exception { | 1368 public void test_referenceInstanceMethod_fromInitializer() throws Exception { |
| 1357 resolveAndTest( | 1369 resolveAndTest( |
| 1358 Joiner.on("\n").join( | 1370 Joiner.on("\n").join( |
| 1359 "// filler filler filler filler filler filler filler filler filler f
iller", | 1371 "// filler filler filler filler filler filler filler filler filler f
iller", |
| 1360 "class Object {}", | 1372 "class Object {}", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1378 "class C {", | 1390 "class C {", |
| 1379 " C(arg){}", | 1391 " C(arg){}", |
| 1380 " C.named1() : this(topLevel());", // ok | 1392 " C.named1() : this(topLevel());", // ok |
| 1381 " C.named2() : this(method());", // error, not a static method | 1393 " C.named2() : this(method());", // error, not a static method |
| 1382 " C.named3() : this(new A().method());", // ok | 1394 " C.named3() : this(new A().method());", // ok |
| 1383 " method() {}", | 1395 " method() {}", |
| 1384 "}"), | 1396 "}"), |
| 1385 errEx(ResolverErrorCode.INSTANCE_METHOD_FROM_REDIRECT, 10, 21, 8)); | 1397 errEx(ResolverErrorCode.INSTANCE_METHOD_FROM_REDIRECT, 10, 21, 8)); |
| 1386 } | 1398 } |
| 1387 } | 1399 } |
| OLD | NEW |