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 DartObjectImpl value = result.value; |
| 1199 expect(value.getConstructor(), isNotNull); |
| 1200 expect(value.getPositionalArguments(), hasLength(1)); |
| 1201 expect(value.getPositionalArguments().single.toIntValue(), 5); |
| 1202 expect(value.getNamedArguments(), 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 DartObjectImpl value = result.value; |
| 1220 expect(value.getConstructor(), isNotNull); |
| 1221 expect(value.getPositionalArguments(), isEmpty); |
| 1222 expect(value.getNamedArguments(), isNotEmpty); |
| 1223 expect(value.getNamedArguments()['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 DartObjectImpl value = result.value; |
| 1244 expect(value.getConstructor().isFactory, isTrue); |
| 1245 } |
| 1246 |
1184 Map<String, DartObjectImpl> _assertFieldType( | 1247 Map<String, DartObjectImpl> _assertFieldType( |
1185 Map<String, DartObjectImpl> fields, | 1248 Map<String, DartObjectImpl> fields, |
1186 String fieldName, | 1249 String fieldName, |
1187 String expectedType) { | 1250 String expectedType) { |
1188 DartObjectImpl field = fields[fieldName]; | 1251 DartObjectImpl field = fields[fieldName]; |
1189 expect(field.type.displayName, expectedType); | 1252 expect(field.type.displayName, expectedType); |
1190 return field.fields; | 1253 return field.fields; |
1191 } | 1254 } |
1192 | 1255 |
1193 void _assertIntField( | 1256 void _assertIntField( |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 } | 1692 } |
1630 } | 1693 } |
1631 | 1694 |
1632 @reflectiveTest | 1695 @reflectiveTest |
1633 class StrongConstantValueComputerTest extends ConstantValueComputerTest { | 1696 class StrongConstantValueComputerTest extends ConstantValueComputerTest { |
1634 void setUp() { | 1697 void setUp() { |
1635 super.setUp(); | 1698 super.setUp(); |
1636 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); | 1699 resetWith(options: new AnalysisOptionsImpl()..strongMode = true); |
1637 } | 1700 } |
1638 } | 1701 } |
OLD | NEW |