| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer.test.src.task.dart_test; | 5 library analyzer.test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 4776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4787 '''); | 4787 '''); |
| 4788 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4788 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4789 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4789 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4790 // validate | 4790 // validate |
| 4791 _fillErrorListener(VERIFY_ERRORS); | 4791 _fillErrorListener(VERIFY_ERRORS); |
| 4792 errorListener.assertErrorsWithCodes(<ErrorCode>[ | 4792 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 4793 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 4793 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 4794 ]); | 4794 ]); |
| 4795 } | 4795 } |
| 4796 | 4796 |
| 4797 test_perform_ConstantValidator_declaredIdentifier() { |
| 4798 Source source = newSource( |
| 4799 '/test.dart', |
| 4800 ''' |
| 4801 void main() { |
| 4802 for (const foo in []) { |
| 4803 print(foo); |
| 4804 } |
| 4805 } |
| 4806 '''); |
| 4807 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4808 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4809 // validate |
| 4810 _fillErrorListener(VERIFY_ERRORS); |
| 4811 errorListener.assertNoErrors(); |
| 4812 } |
| 4813 |
| 4814 test_perform_ConstantValidator_dependencyCycle() { |
| 4815 Source source = newSource( |
| 4816 '/test.dart', |
| 4817 ''' |
| 4818 const int a = b; |
| 4819 const int b = c; |
| 4820 const int c = a; |
| 4821 '''); |
| 4822 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4823 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4824 // validate |
| 4825 _fillErrorListener(VERIFY_ERRORS); |
| 4826 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 4827 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, |
| 4828 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, |
| 4829 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT |
| 4830 ]); |
| 4831 } |
| 4832 |
| 4797 test_perform_ConstantValidator_duplicateFields() { | 4833 test_perform_ConstantValidator_duplicateFields() { |
| 4798 Source source = newSource( | 4834 Source source = newSource( |
| 4799 '/test.dart', | 4835 '/test.dart', |
| 4800 ''' | 4836 ''' |
| 4801 class Test { | 4837 class Test { |
| 4802 final int x = 1; | 4838 final int x = 1; |
| 4803 final int x = 2; | 4839 final int x = 2; |
| 4804 const Test(); | 4840 const Test(); |
| 4805 } | 4841 } |
| 4806 | 4842 |
| 4807 main() { | 4843 main() { |
| 4808 const Test(); | 4844 const Test(); |
| 4809 } | 4845 } |
| 4810 '''); | 4846 '''); |
| 4811 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4847 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4812 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4848 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4813 // validate | 4849 // validate |
| 4814 _fillErrorListener(VERIFY_ERRORS); | 4850 _fillErrorListener(VERIFY_ERRORS); |
| 4815 errorListener.assertNoErrors(); | 4851 errorListener.assertNoErrors(); |
| 4816 } | 4852 } |
| 4817 | 4853 |
| 4854 test_perform_ConstantValidator_noInitializer() { |
| 4855 Source source = newSource( |
| 4856 '/test.dart', |
| 4857 ''' |
| 4858 const x; |
| 4859 '''); |
| 4860 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4861 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4862 // validate |
| 4863 _fillErrorListener(VERIFY_ERRORS); |
| 4864 errorListener.assertErrorsWithCodes( |
| 4865 <ErrorCode>[CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
| 4866 } |
| 4867 |
| 4868 test_perform_ConstantValidator_unknownValue() { |
| 4869 Source source = newSource( |
| 4870 '/test.dart', |
| 4871 ''' |
| 4872 import 'no-such-file.dart' as p; |
| 4873 |
| 4874 const int x = p.y; |
| 4875 '''); |
| 4876 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4877 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4878 // validate |
| 4879 _fillErrorListener(VERIFY_ERRORS); |
| 4880 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 4881 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 4882 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 4883 ]); |
| 4884 } |
| 4885 |
| 4818 test_perform_directiveError() { | 4886 test_perform_directiveError() { |
| 4819 Source source = newSource( | 4887 Source source = newSource( |
| 4820 '/test.dart', | 4888 '/test.dart', |
| 4821 ''' | 4889 ''' |
| 4822 import 'no-such-file.dart'; | 4890 import 'no-such-file.dart'; |
| 4823 '''); | 4891 '''); |
| 4824 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4892 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4825 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4893 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 4826 // validate | 4894 // validate |
| 4827 _fillErrorListener(VERIFY_ERRORS); | 4895 _fillErrorListener(VERIFY_ERRORS); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4969 /** | 5037 /** |
| 4970 * Fill [errorListener] with [result] errors in the current [task]. | 5038 * Fill [errorListener] with [result] errors in the current [task]. |
| 4971 */ | 5039 */ |
| 4972 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 5040 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 4973 List<AnalysisError> errors = task.outputs[result]; | 5041 List<AnalysisError> errors = task.outputs[result]; |
| 4974 expect(errors, isNotNull, reason: result.name); | 5042 expect(errors, isNotNull, reason: result.name); |
| 4975 errorListener = new GatheringErrorListener(); | 5043 errorListener = new GatheringErrorListener(); |
| 4976 errorListener.addAll(errors); | 5044 errorListener.addAll(errors); |
| 4977 } | 5045 } |
| 4978 } | 5046 } |
| OLD | NEW |