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.strong_mode_test; | 5 library analyzer.test.src.task.strong_mode_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
11 import 'package:analyzer/src/task/strong_mode.dart'; | 11 import 'package:analyzer/src/task/strong_mode.dart'; |
12 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
13 | 13 |
14 import '../../reflective_tests.dart'; | 14 import '../../reflective_tests.dart'; |
15 import '../../utils.dart'; | 15 import '../../utils.dart'; |
16 import '../context/abstract_context.dart'; | 16 import '../context/abstract_context.dart'; |
17 | 17 |
18 main() { | 18 main() { |
19 initializeTestEnvironment(); | 19 initializeTestEnvironment(); |
20 runReflectiveTests(InstanceMemberInferrerTest); | 20 runReflectiveTests(InstanceMemberInferrerTest); |
| 21 runReflectiveTests(SetFieldTypeTest); |
21 runReflectiveTests(VariableGathererTest); | 22 runReflectiveTests(VariableGathererTest); |
22 } | 23 } |
23 | 24 |
24 @reflectiveTest | 25 @reflectiveTest |
25 class InstanceMemberInferrerTest extends AbstractContextTest { | 26 class InstanceMemberInferrerTest extends AbstractContextTest { |
26 InstanceMemberInferrer get createInferrer => | 27 InstanceMemberInferrer get createInferrer => |
27 new InstanceMemberInferrer(context.typeProvider, | 28 new InstanceMemberInferrer(context.typeProvider, |
28 typeSystem: context.typeSystem); | 29 typeSystem: context.typeSystem); |
29 | 30 |
30 /** | 31 /** |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 // are treated as independent methods. | 976 // are treated as independent methods. |
976 expect(setterB.parameters[0].type, setterA.parameters[0].type); | 977 expect(setterB.parameters[0].type, setterA.parameters[0].type); |
977 | 978 |
978 // Note that B's synthetic field type will be String. This matches what | 979 // Note that B's synthetic field type will be String. This matches what |
979 // resolver would do if we explicitly typed the parameter as 'String' | 980 // resolver would do if we explicitly typed the parameter as 'String' |
980 expect(fieldB.type, setterB.parameters[0].type); | 981 expect(fieldB.type, setterB.parameters[0].type); |
981 } | 982 } |
982 } | 983 } |
983 | 984 |
984 @reflectiveTest | 985 @reflectiveTest |
| 986 class SetFieldTypeTest extends AbstractContextTest { |
| 987 void test_setter_withoutParameter() { |
| 988 CompilationUnitElement unit = _resolve(''' |
| 989 var x = 0; |
| 990 set x() {} |
| 991 '''); |
| 992 TopLevelVariableElement variable = unit.topLevelVariables.single; |
| 993 setFieldType(variable, context.typeProvider.intType); |
| 994 } |
| 995 |
| 996 CompilationUnitElement _resolve(String content) { |
| 997 Source source = addSource('/test.dart', content); |
| 998 return context.resolveCompilationUnit2(source, source).element; |
| 999 } |
| 1000 } |
| 1001 |
| 1002 @reflectiveTest |
985 class VariableGathererTest extends AbstractContextTest { | 1003 class VariableGathererTest extends AbstractContextTest { |
986 void test_creation_withFilter() { | 1004 void test_creation_withFilter() { |
987 VariableFilter filter = (variable) => true; | 1005 VariableFilter filter = (variable) => true; |
988 VariableGatherer gatherer = new VariableGatherer(filter); | 1006 VariableGatherer gatherer = new VariableGatherer(filter); |
989 expect(gatherer, isNotNull); | 1007 expect(gatherer, isNotNull); |
990 expect(gatherer.filter, filter); | 1008 expect(gatherer.filter, filter); |
991 } | 1009 } |
992 | 1010 |
993 void test_creation_withoutFilter() { | 1011 void test_creation_withoutFilter() { |
994 VariableGatherer gatherer = new VariableGatherer(); | 1012 VariableGatherer gatherer = new VariableGatherer(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 } | 1060 } |
1043 } | 1061 } |
1044 } | 1062 } |
1045 '''); | 1063 '''); |
1046 CompilationUnit unit = context.resolveCompilationUnit2(source, source); | 1064 CompilationUnit unit = context.resolveCompilationUnit2(source, source); |
1047 VariableGatherer gatherer = new VariableGatherer(filter); | 1065 VariableGatherer gatherer = new VariableGatherer(filter); |
1048 unit.accept(gatherer); | 1066 unit.accept(gatherer); |
1049 return gatherer.results; | 1067 return gatherer.results; |
1050 } | 1068 } |
1051 } | 1069 } |
OLD | NEW |