OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.constant_test; | 5 library analyzer.test.constant_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analyzer/context/declared_variables.dart'; | 9 import 'package:analyzer/context/declared_variables.dart'; |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 await resolveSource("const voidSymbol = #void;"); | 1174 await resolveSource("const voidSymbol = #void;"); |
1175 VariableDeclaration voidSymbol = | 1175 VariableDeclaration voidSymbol = |
1176 findTopLevelDeclaration(compilationUnit, "voidSymbol"); | 1176 findTopLevelDeclaration(compilationUnit, "voidSymbol"); |
1177 EvaluationResultImpl voidSymbolResult = | 1177 EvaluationResultImpl voidSymbolResult = |
1178 (voidSymbol.element as VariableElementImpl).evaluationResult; | 1178 (voidSymbol.element as VariableElementImpl).evaluationResult; |
1179 DartObjectImpl value = voidSymbolResult.value; | 1179 DartObjectImpl value = voidSymbolResult.value; |
1180 expect(value.type, typeProvider.symbolType); | 1180 expect(value.type, typeProvider.symbolType); |
1181 expect(value.toSymbolValue(), "void"); | 1181 expect(value.toSymbolValue(), "void"); |
1182 } | 1182 } |
1183 | 1183 |
| 1184 test_getConstructor_withArgs() async { |
| 1185 CompilationUnit compilationUnit = await resolveSource(r''' |
| 1186 class A { |
| 1187 final int i; |
| 1188 const A(this.i); |
| 1189 } |
| 1190 |
| 1191 class C { |
| 1192 @A(5) |
| 1193 f() {} |
| 1194 } |
| 1195 '''); |
| 1196 EvaluationResultImpl result = |
| 1197 _evaluateAnnotation(compilationUnit, "C", "f"); |
| 1198 ConstructorInvocation invocation = result.value.getInvocation(); |
| 1199 expect(invocation.constructor, isNotNull); |
| 1200 expect(invocation.positionalArguments, hasLength(1)); |
| 1201 expect(invocation.positionalArguments.single.toIntValue(), 5); |
| 1202 expect(invocation.namedArguments, isEmpty); |
| 1203 } |
| 1204 |
| 1205 test_getConstructor_withNamedArgs() async { |
| 1206 CompilationUnit compilationUnit = await resolveSource(r''' |
| 1207 class A { |
| 1208 final int i; |
| 1209 const A({this.i}); |
| 1210 } |
| 1211 |
| 1212 class C { |
| 1213 @A(i: 5) |
| 1214 f() {} |
| 1215 } |
| 1216 '''); |
| 1217 EvaluationResultImpl result = |
| 1218 _evaluateAnnotation(compilationUnit, "C", "f"); |
| 1219 ConstructorInvocation invocation = result.value.getInvocation(); |
| 1220 expect(invocation.constructor, isNotNull); |
| 1221 expect(invocation.positionalArguments, isEmpty); |
| 1222 expect(invocation.namedArguments, isNotEmpty); |
| 1223 expect(invocation.namedArguments['i'].toIntValue(), 5); |
| 1224 } |
| 1225 |
| 1226 test_getConstructor_redirectingFactory() async { |
| 1227 CompilationUnit compilationUnit = await resolveSource(r''' |
| 1228 class A { |
| 1229 factory const A() = B; |
| 1230 } |
| 1231 |
| 1232 class B implements A { |
| 1233 const B(); |
| 1234 } |
| 1235 |
| 1236 class C { |
| 1237 @A() |
| 1238 f() {} |
| 1239 } |
| 1240 '''); |
| 1241 EvaluationResultImpl result = |
| 1242 _evaluateAnnotation(compilationUnit, "C", "f"); |
| 1243 expect(result.value.getInvocation().constructor.isFactory, isTrue); |
| 1244 } |
| 1245 |
1184 Map<String, DartObjectImpl> _assertFieldType( | 1246 Map<String, DartObjectImpl> _assertFieldType( |
1185 Map<String, DartObjectImpl> fields, | 1247 Map<String, DartObjectImpl> fields, |
1186 String fieldName, | 1248 String fieldName, |
1187 String expectedType) { | 1249 String expectedType) { |
1188 DartObjectImpl field = fields[fieldName]; | 1250 DartObjectImpl field = fields[fieldName]; |
1189 expect(field.type.displayName, expectedType); | 1251 expect(field.type.displayName, expectedType); |
1190 return field.fields; | 1252 return field.fields; |
1191 } | 1253 } |
1192 | 1254 |
1193 void _assertIntField( | 1255 void _assertIntField( |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 } | 1691 } |
1630 } | 1692 } |
1631 | 1693 |
1632 @reflectiveTest | 1694 @reflectiveTest |
1633 class StrongConstantValueComputerTest extends ConstantValueComputerTest { | 1695 class StrongConstantValueComputerTest extends ConstantValueComputerTest { |
1634 void setUp() { | 1696 void setUp() { |
1635 super.setUp(); | 1697 super.setUp(); |
1636 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 1698 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
1637 } | 1699 } |
1638 } | 1700 } |
OLD | NEW |