Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: tests/compiler/dart2js/constant_expression_evaluate_test.dart

Issue 2990223002: Reformat untouched files. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/constructors.dart'; 10 import 'package:compiler/src/constants/constructors.dart';
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 'const int.fromEnvironment("foo", defaultValue: 42)', const { 121 'const int.fromEnvironment("foo", defaultValue: 42)', const {
122 const {}: 'IntConstant(42)', 122 const {}: 'IntConstant(42)',
123 const {'foo': '87'}: 'IntConstant(87)' 123 const {'foo': '87'}: 'IntConstant(87)'
124 }), 124 }),
125 const ConstantData( 125 const ConstantData(
126 'const String.fromEnvironment("foo", defaultValue: "bar")', const { 126 'const String.fromEnvironment("foo", defaultValue: "bar")', const {
127 const {}: 'StringConstant("bar")', 127 const {}: 'StringConstant("bar")',
128 const {'foo': 'foo'}: 'StringConstant("foo")' 128 const {'foo': 'foo'}: 'StringConstant("foo")'
129 }), 129 }),
130 ]), 130 ]),
131 const TestData( 131 const TestData('''
132 '''
133 const a = const bool.fromEnvironment("foo", defaultValue: true); 132 const a = const bool.fromEnvironment("foo", defaultValue: true);
134 const b = const int.fromEnvironment("bar", defaultValue: 42); 133 const b = const int.fromEnvironment("bar", defaultValue: 42);
135 134
136 class A { 135 class A {
137 const A(); 136 const A();
138 } 137 }
139 class B { 138 class B {
140 final field1; 139 final field1;
141 const B(this.field1); 140 const B(this.field1);
142 } 141 }
143 class C extends B { 142 class C extends B {
144 final field2; 143 final field2;
145 const C({field1: 42, this.field2: false}) : super(field1); 144 const C({field1: 42, this.field2: false}) : super(field1);
146 const C.named([field = false]) : this(field1: field, field2: field); 145 const C.named([field = false]) : this(field1: field, field2: field);
147 } 146 }
148 class D extends C { 147 class D extends C {
149 final field3 = 99; 148 final field3 = 99;
150 const D(a, b) : super(field2: a, field1: b); 149 const D(a, b) : super(field2: a, field1: b);
151 } 150 }
152 ''', 151 ''', const [
153 const [ 152 const ConstantData(
154 const ConstantData('const Object()', 153 'const Object()', const {const {}: 'ConstructedConstant(Object())'}),
155 const {const {}: 'ConstructedConstant(Object())'}), 154 const ConstantData(
156 const ConstantData( 155 'const A()', const {const {}: 'ConstructedConstant(A())'}),
157 'const A()', const {const {}: 'ConstructedConstant(A())'}), 156 const ConstantData('const B(0)',
158 const ConstantData('const B(0)', 157 const {const {}: 'ConstructedConstant(B(field1=IntConstant(0)))'}),
159 const {const {}: 'ConstructedConstant(B(field1=IntConstant(0)))'}), 158 const ConstantData('const B(const A())', const {
160 const ConstantData('const B(const A())', const { 159 const {}: 'ConstructedConstant(B(field1=ConstructedConstant(A())))'
161 const {}: 'ConstructedConstant(B(field1=ConstructedConstant(A())))' 160 }),
162 }), 161 const ConstantData('const C()', const {
163 const ConstantData('const C()', const { 162 const {}: 'ConstructedConstant(C(field1=IntConstant(42),'
164 const {}: 'ConstructedConstant(C(field1=IntConstant(42),' 163 'field2=BoolConstant(false)))'
165 'field2=BoolConstant(false)))' 164 }),
166 }), 165 const ConstantData('const C(field1: 87)', const {
167 const ConstantData('const C(field1: 87)', const { 166 const {}: 'ConstructedConstant(C(field1=IntConstant(87),'
168 const {}: 'ConstructedConstant(C(field1=IntConstant(87),' 167 'field2=BoolConstant(false)))'
169 'field2=BoolConstant(false)))' 168 }),
170 }), 169 const ConstantData('const C(field2: true)', const {
171 const ConstantData('const C(field2: true)', const { 170 const {}: 'ConstructedConstant(C(field1=IntConstant(42),'
172 const {}: 'ConstructedConstant(C(field1=IntConstant(42),' 171 'field2=BoolConstant(true)))'
173 'field2=BoolConstant(true)))' 172 }),
174 }), 173 const ConstantData('const C.named()', const {
175 const ConstantData('const C.named()', const { 174 const {}: 'ConstructedConstant(C(field1=BoolConstant(false),'
176 const {}: 'ConstructedConstant(C(field1=BoolConstant(false),' 175 'field2=BoolConstant(false)))'
177 'field2=BoolConstant(false)))' 176 }),
178 }), 177 const ConstantData('const C.named(87)', const {
179 const ConstantData('const C.named(87)', const { 178 const {}: 'ConstructedConstant(C(field1=IntConstant(87),'
180 const {}: 'ConstructedConstant(C(field1=IntConstant(87),' 179 'field2=IntConstant(87)))'
181 'field2=IntConstant(87)))' 180 }),
182 }), 181 const ConstantData('const C(field1: a, field2: b)', const {
183 const ConstantData('const C(field1: a, field2: b)', const { 182 const {}: 'ConstructedConstant(C(field1=BoolConstant(true),'
184 const {}: 'ConstructedConstant(C(field1=BoolConstant(true),' 183 'field2=IntConstant(42)))',
185 'field2=IntConstant(42)))', 184 const {'foo': 'false', 'bar': '87'}:
186 const {'foo': 'false', 'bar': '87'}: 185 'ConstructedConstant(C(field1=BoolConstant(false),'
187 'ConstructedConstant(C(field1=BoolConstant(false),' 186 'field2=IntConstant(87)))',
188 'field2=IntConstant(87)))', 187 }),
189 }), 188 const ConstantData('const D(42, 87)', const {
190 const ConstantData('const D(42, 87)', const { 189 const {}: 'ConstructedConstant(D(field1=IntConstant(87),'
191 const {}: 'ConstructedConstant(D(field1=IntConstant(87),' 190 'field2=IntConstant(42),'
192 'field2=IntConstant(42),' 191 'field3=IntConstant(99)))'
193 'field3=IntConstant(99)))' 192 }),
194 }), 193 ]),
195 ]), 194 const TestData('''
196 const TestData(
197 '''
198 class A<T> implements B { 195 class A<T> implements B {
199 final field1; 196 final field1;
200 const A({this.field1:42}); 197 const A({this.field1:42});
201 } 198 }
202 class B<S> implements C { 199 class B<S> implements C {
203 const factory B({field1}) = A<B<S>>; 200 const factory B({field1}) = A<B<S>>;
204 const factory B.named() = A<S>; 201 const factory B.named() = A<S>;
205 } 202 }
206 class C<U> { 203 class C<U> {
207 const factory C({field1}) = A<B<double>>; 204 const factory C({field1}) = A<B<double>>;
208 } 205 }
209 ''', 206 ''', const [
210 const [ 207 const ConstantData('const A()', const {
211 const ConstantData('const A()', const { 208 const {}: 'ConstructedConstant(A<dynamic>(field1=IntConstant(42)))'
212 const {}: 'ConstructedConstant(A<dynamic>(field1=IntConstant(42)))' 209 }),
213 }), 210 const ConstantData('const A<int>(field1: 87)', const {
214 const ConstantData('const A<int>(field1: 87)', const { 211 const {}: 'ConstructedConstant(A<int>(field1=IntConstant(87)))'
215 const {}: 'ConstructedConstant(A<int>(field1=IntConstant(87)))' 212 }),
216 }), 213 const ConstantData('const B()', const {
217 const ConstantData('const B()', const { 214 const {}: 'ConstructedConstant(A<B<dynamic>>(field1=IntConstant(42)))'
218 const {}: 'ConstructedConstant(A<B<dynamic>>(field1=IntConstant(42)))' 215 }),
219 }), 216 const ConstantData('const B<int>()', const {
220 const ConstantData('const B<int>()', const { 217 const {}: 'ConstructedConstant(A<B<int>>(field1=IntConstant(42)))'
221 const {}: 'ConstructedConstant(A<B<int>>(field1=IntConstant(42)))' 218 }),
222 }), 219 const ConstantData('const B<int>(field1: 87)', const {
223 const ConstantData('const B<int>(field1: 87)', const { 220 const {}: 'ConstructedConstant(A<B<int>>(field1=IntConstant(87)))'
224 const {}: 'ConstructedConstant(A<B<int>>(field1=IntConstant(87)))' 221 }),
225 }), 222 const ConstantData('const C<int>(field1: 87)', const {
226 const ConstantData('const C<int>(field1: 87)', const { 223 const {}: 'ConstructedConstant(A<B<double>>(field1=IntConstant(87)))'
227 const {}: 'ConstructedConstant(A<B<double>>(field1=IntConstant(87)))' 224 }),
228 }), 225 const ConstantData('const B<int>.named()', const {
229 const ConstantData('const B<int>.named()', const { 226 const {}: 'ConstructedConstant(A<int>(field1=IntConstant(42)))'
230 const {}: 'ConstructedConstant(A<int>(field1=IntConstant(42)))' 227 }),
231 }), 228 ]),
232 ]), 229 const TestData('''
233 const TestData(
234 '''
235 const c = const int.fromEnvironment("foo", defaultValue: 5); 230 const c = const int.fromEnvironment("foo", defaultValue: 5);
236 const d = const int.fromEnvironment("bar", defaultValue: 10); 231 const d = const int.fromEnvironment("bar", defaultValue: 10);
237 232
238 class A { 233 class A {
239 final field; 234 final field;
240 const A(a, b) : field = a + b; 235 const A(a, b) : field = a + b;
241 } 236 }
242 237
243 class B extends A { 238 class B extends A {
244 const B(a) : super(a, a * 2); 239 const B(a) : super(a, a * 2);
245 } 240 }
246 ''', 241 ''', const [
247 const [ 242 const ConstantData('const A(c, d)', const {
248 const ConstantData('const A(c, d)', const { 243 const {}: 'ConstructedConstant(A(field=IntConstant(15)))',
249 const {}: 'ConstructedConstant(A(field=IntConstant(15)))', 244 const {'foo': '7', 'bar': '11'}:
250 const {'foo': '7', 'bar': '11'}: 245 'ConstructedConstant(A(field=IntConstant(18)))',
251 'ConstructedConstant(A(field=IntConstant(18)))', 246 }),
252 }), 247 const ConstantData('const B(d)', const {
253 const ConstantData('const B(d)', const { 248 const {}: 'ConstructedConstant(B(field=IntConstant(30)))',
254 const {}: 'ConstructedConstant(B(field=IntConstant(30)))', 249 const {'bar': '42'}: 'ConstructedConstant(B(field=IntConstant(126)))',
255 const {'bar': '42'}: 'ConstructedConstant(B(field=IntConstant(126)))', 250 }),
256 }), 251 ]),
257 ]),
258 ]; 252 ];
259 253
260 main() { 254 main() {
261 asyncTest(() => Future.forEach(DATA, testData)); 255 asyncTest(() => Future.forEach(DATA, testData));
262 } 256 }
263 257
264 Future testData(TestData data) async { 258 Future testData(TestData data) async {
265 StringBuffer sb = new StringBuffer(); 259 StringBuffer sb = new StringBuffer();
266 sb.write('${data.declarations}\n'); 260 sb.write('${data.declarations}\n');
267 Map constants = {}; 261 Map constants = {};
(...skipping 17 matching lines...) Expand all
285 constant.evaluate(environment, DART_CONSTANT_SYSTEM); 279 constant.evaluate(environment, DART_CONSTANT_SYSTEM);
286 String valueText = value.toStructuredText(); 280 String valueText = value.toStructuredText();
287 Expect.equals( 281 Expect.equals(
288 expectedText, 282 expectedText,
289 valueText, 283 valueText,
290 "Unexpected value '${valueText}' for constant " 284 "Unexpected value '${valueText}' for constant "
291 "`${constant.toDartText()}`, expected '${expectedText}'."); 285 "`${constant.toDartText()}`, expected '${expectedText}'.");
292 }); 286 });
293 }); 287 });
294 } 288 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/const_exp_test.dart ('k') | tests/compiler/dart2js/constant_expression_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698