| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'type_test_helper.dart'; | 8 import 'type_test_helper.dart'; |
| 9 | 9 |
| 10 test(String constantInitializer, [String expectedOutput]) { | 10 test(String constantInitializer, [String expectedOutput]) { |
| 11 if (expectedOutput == null) { | 11 if (expectedOutput == null) { |
| 12 expectedOutput = constantInitializer; | 12 expectedOutput = constantInitializer; |
| 13 } | 13 } |
| 14 return () => TypeEnvironment | 14 return () => TypeEnvironment.create(""" |
| 15 .create( | |
| 16 """ | |
| 17 class Class<T, S> { | 15 class Class<T, S> { |
| 18 final a; | 16 final a; |
| 19 final b; | 17 final b; |
| 20 final c; | 18 final c; |
| 21 const Class(this.a, {this.b, this.c: true}); | 19 const Class(this.a, {this.b, this.c: true}); |
| 22 const Class.named([this.a, this.b = 0, this.c = 2]); | 20 const Class.named([this.a, this.b = 0, this.c = 2]); |
| 23 | 21 |
| 24 static const staticConstant = 0; | 22 static const staticConstant = 0; |
| 25 static staticFunction() {} | 23 static staticFunction() {} |
| 26 } | 24 } |
| 27 const t = true; | 25 const t = true; |
| 28 const f = false; | 26 const f = false; |
| 29 const toplevelConstant = 0; | 27 const toplevelConstant = 0; |
| 30 toplevelFunction() {} | 28 toplevelFunction() {} |
| 31 const constant = $constantInitializer; | 29 const constant = $constantInitializer; |
| 32 """, | 30 """, expectNoWarningsOrErrors: true).then((env) { |
| 33 expectNoWarningsOrErrors: true) | |
| 34 .then((env) { | |
| 35 dynamic element = env.getElement('constant'); | 31 dynamic element = env.getElement('constant'); |
| 36 Expect.isNotNull(element, "Element 'constant' not found."); | 32 Expect.isNotNull(element, "Element 'constant' not found."); |
| 37 var constant = element.constant; | 33 var constant = element.constant; |
| 38 var value = env.compiler.constants.getConstantValue(constant); | 34 var value = env.compiler.constants.getConstantValue(constant); |
| 39 Expect.isNotNull(constant, "No constant computed for '$element'."); | 35 Expect.isNotNull(constant, "No constant computed for '$element'."); |
| 40 Expect.equals( | 36 Expect.equals( |
| 41 expectedOutput, | 37 expectedOutput, |
| 42 constant.toDartText(), | 38 constant.toDartText(), |
| 43 "Unexpected to string '${constant.toDartText()}' for constant " | 39 "Unexpected to string '${constant.toDartText()}' for constant " |
| 44 "'$constantInitializer' of value " | 40 "'$constantInitializer' of value " |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 test('t ? t : f ? f ? 0 : 1 : 2'), | 98 test('t ? t : f ? f ? 0 : 1 : 2'), |
| 103 test('t ? t ? t : t : t ? t : t'), | 99 test('t ? t ? t : t : t ? t : t'), |
| 104 test('t ? (t ? t : t) : (t ? t : t)', 't ? t ? t : t : t ? t : t'), | 100 test('t ? (t ? t : t) : (t ? t : t)', 't ? t ? t : t : t ? t : t'), |
| 105 test( | 101 test( |
| 106 'const [const <dynamic, dynamic>{0: true, "1": "c" "d"}, ' | 102 'const [const <dynamic, dynamic>{0: true, "1": "c" "d"}, ' |
| 107 'const Class(const Class<dynamic, dynamic>(toplevelConstant))]', | 103 'const Class(const Class<dynamic, dynamic>(toplevelConstant))]', |
| 108 'const [const {0: true, "1": "cd"}, ' | 104 'const [const {0: true, "1": "cd"}, ' |
| 109 'const Class(const Class(toplevelConstant))]'), | 105 'const Class(const Class(toplevelConstant))]'), |
| 110 ], (f) => f())); | 106 ], (f) => f())); |
| 111 } | 107 } |
| OLD | NEW |