| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.compile_time_error_code_test; | 5 library engine.compile_time_error_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/engine.dart'; | 7 import 'package:analyzer/src/generated/engine.dart'; |
| 8 import 'package:analyzer/src/generated/error.dart'; | 8 import 'package:analyzer/src/generated/error.dart'; |
| 9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 10 import 'package:analyzer/src/generated/source_io.dart'; | 10 import 'package:analyzer/src/generated/source_io.dart'; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 Source source = addSource(r''' | 194 Source source = addSource(r''' |
| 195 f() { | 195 f() { |
| 196 yield 0; | 196 yield 0; |
| 197 }'''); | 197 }'''); |
| 198 resolve(source); | 198 resolve(source); |
| 199 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); | 199 assertErrors(source, [CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR]); |
| 200 verify([source]); | 200 verify([source]); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void test_accessPrivateEnumField() { | 203 void test_accessPrivateEnumField() { |
| 204 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 204 resetWithEnum(); |
| 205 analysisOptions.enableEnum = true; | |
| 206 resetWithOptions(analysisOptions); | |
| 207 Source source = addSource(r''' | 205 Source source = addSource(r''' |
| 208 enum E { ONE } | 206 enum E { ONE } |
| 209 String name(E e) { | 207 String name(E e) { |
| 210 return e._name; | 208 return e._name; |
| 211 }'''); | 209 }'''); |
| 212 resolve(source); | 210 resolve(source); |
| 213 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); | 211 assertErrors(source, [CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD]); |
| 214 // Cannot verify because "_name" cannot be resolved. | 212 // Cannot verify because "_name" cannot be resolved. |
| 215 } | 213 } |
| 216 | 214 |
| (...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 resolve(source); | 1573 resolve(source); |
| 1576 assertErrors( | 1574 assertErrors( |
| 1577 source, | 1575 source, |
| 1578 [ | 1576 [ |
| 1579 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, | 1577 CompileTimeErrorCode.EXTENDS_DISALLOWED_CLASS, |
| 1580 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); | 1578 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); |
| 1581 verify([source]); | 1579 verify([source]); |
| 1582 } | 1580 } |
| 1583 | 1581 |
| 1584 void test_extendsEnum() { | 1582 void test_extendsEnum() { |
| 1585 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 1583 resetWithEnum(); |
| 1586 analysisOptions.enableEnum = true; | |
| 1587 resetWithOptions(analysisOptions); | |
| 1588 Source source = addSource(r''' | 1584 Source source = addSource(r''' |
| 1589 enum E { ONE } | 1585 enum E { ONE } |
| 1590 class A extends E {}'''); | 1586 class A extends E {}'''); |
| 1591 resolve(source); | 1587 resolve(source); |
| 1592 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]); | 1588 assertErrors(source, [CompileTimeErrorCode.EXTENDS_ENUM]); |
| 1593 verify([source]); | 1589 verify([source]); |
| 1594 } | 1590 } |
| 1595 | 1591 |
| 1596 void test_extendsNonClass_class() { | 1592 void test_extendsNonClass_class() { |
| 1597 Source source = addSource(r''' | 1593 Source source = addSource(r''' |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2045 } | 2041 } |
| 2046 | 2042 |
| 2047 void test_implementsDynamic() { | 2043 void test_implementsDynamic() { |
| 2048 Source source = addSource("class A implements dynamic {}"); | 2044 Source source = addSource("class A implements dynamic {}"); |
| 2049 resolve(source); | 2045 resolve(source); |
| 2050 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]); | 2046 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]); |
| 2051 verify([source]); | 2047 verify([source]); |
| 2052 } | 2048 } |
| 2053 | 2049 |
| 2054 void test_implementsEnum() { | 2050 void test_implementsEnum() { |
| 2055 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 2051 resetWithEnum(); |
| 2056 analysisOptions.enableEnum = true; | |
| 2057 resetWithOptions(analysisOptions); | |
| 2058 Source source = addSource(r''' | 2052 Source source = addSource(r''' |
| 2059 enum E { ONE } | 2053 enum E { ONE } |
| 2060 class A implements E {}'''); | 2054 class A implements E {}'''); |
| 2061 resolve(source); | 2055 resolve(source); |
| 2062 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]); | 2056 assertErrors(source, [CompileTimeErrorCode.IMPLEMENTS_ENUM]); |
| 2063 verify([source]); | 2057 verify([source]); |
| 2064 } | 2058 } |
| 2065 | 2059 |
| 2066 void test_implementsNonClass_class() { | 2060 void test_implementsNonClass_class() { |
| 2067 Source source = addSource(r''' | 2061 Source source = addSource(r''' |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 } | 2483 } |
| 2490 }'''); | 2484 }'''); |
| 2491 resolve(source); | 2485 resolve(source); |
| 2492 assertErrors( | 2486 assertErrors( |
| 2493 source, | 2487 source, |
| 2494 [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); | 2488 [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]); |
| 2495 verify([source]); | 2489 verify([source]); |
| 2496 } | 2490 } |
| 2497 | 2491 |
| 2498 void test_instantiateEnum_const() { | 2492 void test_instantiateEnum_const() { |
| 2499 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 2493 resetWithEnum(); |
| 2500 analysisOptions.enableEnum = true; | |
| 2501 resetWithOptions(analysisOptions); | |
| 2502 Source source = addSource(r''' | 2494 Source source = addSource(r''' |
| 2503 enum E { ONE } | 2495 enum E { ONE } |
| 2504 E e(String name) { | 2496 E e(String name) { |
| 2505 return const E(); | 2497 return const E(); |
| 2506 }'''); | 2498 }'''); |
| 2507 resolve(source); | 2499 resolve(source); |
| 2508 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); | 2500 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); |
| 2509 verify([source]); | 2501 verify([source]); |
| 2510 } | 2502 } |
| 2511 | 2503 |
| 2512 void test_instantiateEnum_new() { | 2504 void test_instantiateEnum_new() { |
| 2513 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 2505 resetWithEnum(); |
| 2514 analysisOptions.enableEnum = true; | |
| 2515 resetWithOptions(analysisOptions); | |
| 2516 Source source = addSource(r''' | 2506 Source source = addSource(r''' |
| 2517 enum E { ONE } | 2507 enum E { ONE } |
| 2518 E e(String name) { | 2508 E e(String name) { |
| 2519 return new E(); | 2509 return new E(); |
| 2520 }'''); | 2510 }'''); |
| 2521 resolve(source); | 2511 resolve(source); |
| 2522 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); | 2512 assertErrors(source, [CompileTimeErrorCode.INSTANTIATE_ENUM]); |
| 2523 verify([source]); | 2513 verify([source]); |
| 2524 } | 2514 } |
| 2525 | 2515 |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3075 x(y) {} | 3065 x(y) {} |
| 3076 }'''); | 3066 }'''); |
| 3077 resolve(source); | 3067 resolve(source); |
| 3078 assertErrors( | 3068 assertErrors( |
| 3079 source, | 3069 source, |
| 3080 [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]); | 3070 [CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME]); |
| 3081 verify([source]); | 3071 verify([source]); |
| 3082 } | 3072 } |
| 3083 | 3073 |
| 3084 void test_missingEnumConstantInSwitch() { | 3074 void test_missingEnumConstantInSwitch() { |
| 3085 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 3075 resetWithEnum(); |
| 3086 analysisOptions.enableEnum = true; | |
| 3087 resetWithOptions(analysisOptions); | |
| 3088 Source source = addSource(r''' | 3076 Source source = addSource(r''' |
| 3089 enum E { ONE, TWO, THREE, FOUR } | 3077 enum E { ONE, TWO, THREE, FOUR } |
| 3090 bool odd(E e) { | 3078 bool odd(E e) { |
| 3091 switch (e) { | 3079 switch (e) { |
| 3092 case E.ONE: | 3080 case E.ONE: |
| 3093 case E.THREE: return true; | 3081 case E.THREE: return true; |
| 3094 } | 3082 } |
| 3095 return false; | 3083 return false; |
| 3096 }'''); | 3084 }'''); |
| 3097 resolve(source); | 3085 resolve(source); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3378 resolve(source); | 3366 resolve(source); |
| 3379 assertErrors( | 3367 assertErrors( |
| 3380 source, | 3368 source, |
| 3381 [ | 3369 [ |
| 3382 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, | 3370 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS, |
| 3383 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); | 3371 CompileTimeErrorCode.MIXIN_OF_DISALLOWED_CLASS]); |
| 3384 verify([source]); | 3372 verify([source]); |
| 3385 } | 3373 } |
| 3386 | 3374 |
| 3387 void test_mixinOfEnum() { | 3375 void test_mixinOfEnum() { |
| 3388 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 3376 resetWithEnum(); |
| 3389 analysisOptions.enableEnum = true; | |
| 3390 resetWithOptions(analysisOptions); | |
| 3391 Source source = addSource(r''' | 3377 Source source = addSource(r''' |
| 3392 enum E { ONE } | 3378 enum E { ONE } |
| 3393 class A extends Object with E {}'''); | 3379 class A extends Object with E {}'''); |
| 3394 resolve(source); | 3380 resolve(source); |
| 3395 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]); | 3381 assertErrors(source, [CompileTimeErrorCode.MIXIN_OF_ENUM]); |
| 3396 verify([source]); | 3382 verify([source]); |
| 3397 } | 3383 } |
| 3398 | 3384 |
| 3399 void test_mixinOfNonClass_class() { | 3385 void test_mixinOfNonClass_class() { |
| 3400 Source source = addSource(r''' | 3386 Source source = addSource(r''' |
| (...skipping 2082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5483 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); | 5469 [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); |
| 5484 verify([source]); | 5470 verify([source]); |
| 5485 reset(); | 5471 reset(); |
| 5486 } | 5472 } |
| 5487 | 5473 |
| 5488 void _check_wrongNumberOfParametersForOperator1(String name) { | 5474 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 5489 _check_wrongNumberOfParametersForOperator(name, ""); | 5475 _check_wrongNumberOfParametersForOperator(name, ""); |
| 5490 _check_wrongNumberOfParametersForOperator(name, "a, b"); | 5476 _check_wrongNumberOfParametersForOperator(name, "a, b"); |
| 5491 } | 5477 } |
| 5492 } | 5478 } |
| OLD | NEW |