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 dart2js.constants.expressions.evaluate_test; | 5 library dart2js.constants.expressions.evaluate_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import 'package:compiler/src/constants/evaluation.dart'; | 10 import 'package:compiler/src/constants/evaluation.dart'; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 class B { | 102 class B { |
103 final field1; | 103 final field1; |
104 const B(this.field1); | 104 const B(this.field1); |
105 } | 105 } |
106 class C extends B { | 106 class C extends B { |
107 final field2; | 107 final field2; |
108 const C({field1: 42, this.field2: false}) : super(field1); | 108 const C({field1: 42, this.field2: false}) : super(field1); |
109 const C.named([field = false]) : this(field1: field, field2: field); | 109 const C.named([field = false]) : this(field1: field, field2: field); |
110 } | 110 } |
| 111 class D extends C { |
| 112 final field3 = 99; |
| 113 const D(a, b) : super(field2: a, field1: b); |
| 114 } |
111 ''', const [ | 115 ''', const [ |
112 const ConstantData('const Object()', | 116 const ConstantData('const Object()', |
113 const { const {} : 'ConstructedConstant(Object())' }), | 117 const { const {} : 'ConstructedConstant(Object())' }), |
114 const ConstantData('const A()', | 118 const ConstantData('const A()', |
115 const { const {} : 'ConstructedConstant(A())' }), | 119 const { const {} : 'ConstructedConstant(A())' }), |
116 const ConstantData('const B(0)', | 120 const ConstantData('const B(0)', |
117 const { const {} : 'ConstructedConstant(B(field1=IntConstant(0)))' }), | 121 const { const {} : 'ConstructedConstant(B(field1=IntConstant(0)))' }), |
118 const ConstantData('const B(const A())', | 122 const ConstantData('const B(const A())', |
119 const { const {} : | 123 const { const {} : |
120 'ConstructedConstant(B(field1=ConstructedConstant(A())))' }), | 124 'ConstructedConstant(B(field1=ConstructedConstant(A())))' }), |
(...skipping 12 matching lines...) Expand all Loading... |
133 const ConstantData('const C.named(87)', const { const {} : | 137 const ConstantData('const C.named(87)', const { const {} : |
134 'ConstructedConstant(C(field1=IntConstant(87),' | 138 'ConstructedConstant(C(field1=IntConstant(87),' |
135 'field2=IntConstant(87)))' }), | 139 'field2=IntConstant(87)))' }), |
136 const ConstantData('const C(field1: a, field2: b)', const { | 140 const ConstantData('const C(field1: a, field2: b)', const { |
137 const {} : | 141 const {} : |
138 'ConstructedConstant(C(field1=BoolConstant(true),' | 142 'ConstructedConstant(C(field1=BoolConstant(true),' |
139 'field2=IntConstant(42)))', | 143 'field2=IntConstant(42)))', |
140 const {'foo': 'false', 'bar': '87'} : | 144 const {'foo': 'false', 'bar': '87'} : |
141 'ConstructedConstant(C(field1=BoolConstant(false),' | 145 'ConstructedConstant(C(field1=BoolConstant(false),' |
142 'field2=IntConstant(87)))', }), | 146 'field2=IntConstant(87)))', }), |
| 147 const ConstantData('const D(42, 87)', const { const {} : |
| 148 'ConstructedConstant(D(field1=IntConstant(87),' |
| 149 'field2=IntConstant(42),' |
| 150 'field3=IntConstant(99)))' }), |
143 ]), | 151 ]), |
144 const TestData(''' | 152 const TestData(''' |
145 class A<T> implements B { | 153 class A<T> implements B { |
146 final field1; | 154 final field1; |
147 const A({this.field1:42}); | 155 const A({this.field1:42}); |
148 } | 156 } |
149 class B<S> implements C { | 157 class B<S> implements C { |
150 const factory B({field1}) = A<B<S>>; | 158 const factory B({field1}) = A<B<S>>; |
151 const factory B.named() = A<S>; | 159 const factory B.named() = A<S>; |
152 } | 160 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 Environment environment = new MemoryEnvironment(compiler, env); | 237 Environment environment = new MemoryEnvironment(compiler, env); |
230 ConstantValue value = | 238 ConstantValue value = |
231 constant.evaluate(environment, DART_CONSTANT_SYSTEM); | 239 constant.evaluate(environment, DART_CONSTANT_SYSTEM); |
232 String valueText = value.toStructuredText(); | 240 String valueText = value.toStructuredText(); |
233 Expect.equals(expectedText, valueText, | 241 Expect.equals(expectedText, valueText, |
234 "Unexpected value '${valueText}' for contant " | 242 "Unexpected value '${valueText}' for contant " |
235 "`${constant.toDartText()}`, expected '${expectedText}'."); | 243 "`${constant.toDartText()}`, expected '${expectedText}'."); |
236 }); | 244 }); |
237 }); | 245 }); |
238 } | 246 } |
OLD | NEW |