| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:async'; |
| 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'package:expect/expect.dart'; |
| 8 import 'type_test_helper.dart'; |
| 9 |
| 10 test(String constantInitializer, [String expectedOutput]) { |
| 11 if (expectedOutput == null) { |
| 12 expectedOutput = constantInitializer; |
| 13 } |
| 14 return () => TypeEnvironment.create(""" |
| 15 class Class<T, S> { |
| 16 final a; |
| 17 final b; |
| 18 final c; |
| 19 const Class(this.a, {this.b, this.c: true}); |
| 20 const Class.named([this.a, this.b = 0, this.c = 2]); |
| 21 |
| 22 static const staticConstant = 0; |
| 23 static staticFunction() {} |
| 24 } |
| 25 const t = true; |
| 26 const f = false; |
| 27 const toplevelConstant = 0; |
| 28 toplevelFunction() {} |
| 29 const constant = $constantInitializer; |
| 30 """, expectNoWarningsOrErrors: true).then((env) { |
| 31 var element = env.getElement('constant'); |
| 32 Expect.isNotNull(element, "Element 'constant' not found."); |
| 33 var constant = env.compiler.constants.getConstantForVariable(element); |
| 34 Expect.isNotNull(constant, |
| 35 "No constant computed for '$element'."); |
| 36 Expect.equals(expectedOutput, constant.getText(), |
| 37 "Unexpected to string '${constant.getText()}' for constant " |
| 38 "'$constantInitializer' of value " |
| 39 "${constant.value.toStructuredString()}"); |
| 40 }); |
| 41 } |
| 42 |
| 43 void main() { |
| 44 asyncTest(() => Future.forEach([ |
| 45 test('null'), |
| 46 test('0'), |
| 47 test('1.5'), |
| 48 test('true'), |
| 49 test('false'), |
| 50 test('"f"'), |
| 51 test('"a" "b"', '"ab"'), |
| 52 test('const []'), |
| 53 test('const <int>[0, 1]'), |
| 54 test('const <dynamic>[0, 1]', 'const [0, 1]'), |
| 55 test('const {}'), |
| 56 test('const {0: 1, 2: 3}'), |
| 57 test('const <String, int>{"0": 1, "2": 3}'), |
| 58 test('const <String, dynamic>{"0": 1, "2": 3}'), |
| 59 test('const <dynamic, dynamic>{"0": 1, "2": 3}', 'const {"0": 1, "2": 3}'), |
| 60 test('const Class(0)'), |
| 61 test('const Class(0, b: 1)'), |
| 62 test('const Class(0, c: 2)'), |
| 63 test('const Class(0, b: 3, c: 4)'), |
| 64 test('const Class.named()'), |
| 65 test('const Class.named(0)'), |
| 66 test('const Class.named(0, 1)'), |
| 67 test('const Class.named(0, 1, 2)'), |
| 68 test('const Class<String, int>(0)'), |
| 69 test('const Class<String, dynamic>(0)'), |
| 70 test('const Class<dynamic, String>(0)'), |
| 71 test('const Class<dynamic, dynamic>(0)', 'const Class(0)'), |
| 72 test('toplevelConstant'), |
| 73 test('toplevelFunction'), |
| 74 test('Class.staticConstant'), |
| 75 test('Class.staticFunction'), |
| 76 test('#a'), |
| 77 test('1 + 2'), |
| 78 test('1 + 2 + 3'), |
| 79 test('1 + -2'), |
| 80 test('-1 + 2'), |
| 81 test('(1 + 2) + 3', '1 + 2 + 3'), |
| 82 test('1 + (2 + 3)', '1 + 2 + 3'), |
| 83 test('1 * 2'), |
| 84 test('1 * 2 + 3'), |
| 85 test('1 * (2 + 3)'), |
| 86 test('1 + 2 * 3'), |
| 87 test('(1 + 2) * 3'), |
| 88 test('false || identical(0, 1)'), |
| 89 test('!identical(0, 1)'), |
| 90 test('!identical(0, 1) || false'), |
| 91 test('!(identical(0, 1) || false)'), |
| 92 test('identical(0, 1) ? 3 * 4 + 5 : 6 + 7 * 8'), |
| 93 test('t ? f ? 0 : 1 : 2'), |
| 94 test('(t ? t : f) ? f ? 0 : 1 : 2'), |
| 95 test('t ? t : f ? f ? 0 : 1 : 2'), |
| 96 test('t ? t ? t : t : t ? t : t'), |
| 97 test('t ? (t ? t : t) : (t ? t : t)', |
| 98 't ? t ? t : t : t ? t : t'), |
| 99 test('const [const <dynamic, dynamic>{0: true, "1": "c" "d"}, ' |
| 100 'const Class(const Class<dynamic, dynamic>(toplevelConstant))]', |
| 101 'const [const {0: true, "1": "cd"}, ' |
| 102 'const Class(const Class(toplevelConstant))]'), |
| 103 ], (f) => f())); |
| 104 } |
| OLD | NEW |