| 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 constant_expression_test; | 5 library constant_expression_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/expressions.dart'; | 10 import 'package:compiler/src/constants/expressions.dart'; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 const List<TestData> DATA = const [ | 45 const List<TestData> DATA = const [ |
| 46 const TestData('', const [ | 46 const TestData('', const [ |
| 47 const ConstantData('null', ConstantExpressionKind.NULL), | 47 const ConstantData('null', ConstantExpressionKind.NULL), |
| 48 const ConstantData('false', ConstantExpressionKind.BOOL), | 48 const ConstantData('false', ConstantExpressionKind.BOOL), |
| 49 const ConstantData('true', ConstantExpressionKind.BOOL), | 49 const ConstantData('true', ConstantExpressionKind.BOOL), |
| 50 const ConstantData('0', ConstantExpressionKind.INT), | 50 const ConstantData('0', ConstantExpressionKind.INT), |
| 51 const ConstantData('0.0', ConstantExpressionKind.DOUBLE), | 51 const ConstantData('0.0', ConstantExpressionKind.DOUBLE), |
| 52 const ConstantData('"foo"', ConstantExpressionKind.STRING), | 52 const ConstantData('"foo"', ConstantExpressionKind.STRING), |
| 53 const ConstantData('1 + 2', ConstantExpressionKind.BINARY), | 53 const ConstantData('1 + 2', ConstantExpressionKind.BINARY), |
| 54 const ConstantData('-(1)', ConstantExpressionKind.UNARY, text: '-1'), | 54 const ConstantData('-(1)', ConstantExpressionKind.UNARY, text: '-1'), |
| 55 const ConstantData('"foo".length', ConstantExpressionKind.STRING_LENGTH), |
| 55 const ConstantData('identical(0, 1)', ConstantExpressionKind.IDENTICAL), | 56 const ConstantData('identical(0, 1)', ConstantExpressionKind.IDENTICAL), |
| 56 const ConstantData('"a" "b"', ConstantExpressionKind.CONCATENATE, | 57 const ConstantData('"a" "b"', ConstantExpressionKind.CONCATENATE, |
| 57 text: '"ab"'), | 58 text: '"ab"'), |
| 58 const ConstantData('identical', ConstantExpressionKind.FUNCTION), | 59 const ConstantData('identical', ConstantExpressionKind.FUNCTION), |
| 59 const ConstantData('true ? 0 : 1', ConstantExpressionKind.CONDITIONAL), | 60 const ConstantData('true ? 0 : 1', ConstantExpressionKind.CONDITIONAL), |
| 60 const ConstantData('proxy', ConstantExpressionKind.VARIABLE), | 61 const ConstantData('proxy', ConstantExpressionKind.VARIABLE), |
| 61 const ConstantData('Object', ConstantExpressionKind.TYPE), | 62 const ConstantData('Object', ConstantExpressionKind.TYPE), |
| 62 const ConstantData('#name', ConstantExpressionKind.SYMBOL), | 63 const ConstantData('#name', ConstantExpressionKind.SYMBOL), |
| 63 const ConstantData('const [0, 1]', ConstantExpressionKind.LIST), | 64 const ConstantData('const [0, 1]', ConstantExpressionKind.LIST), |
| 64 const ConstantData('const <int>[0, 1]', ConstantExpressionKind.LIST), | 65 const ConstantData('const <int>[0, 1]', ConstantExpressionKind.LIST), |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 ]), | 142 ]), |
| 142 const TestData(''' | 143 const TestData(''' |
| 143 class A<T> implements B { | 144 class A<T> implements B { |
| 144 final field1; | 145 final field1; |
| 145 const A({this.field1:42}); | 146 const A({this.field1:42}); |
| 146 } | 147 } |
| 147 class B<S> implements C { | 148 class B<S> implements C { |
| 148 const factory B({field1}) = A<B<S>>; | 149 const factory B({field1}) = A<B<S>>; |
| 149 // TODO(johnniwinther): Enable this when the constructor evaluator doesn't | 150 // TODO(johnniwinther): Enable this when the constructor evaluator doesn't |
| 150 // crash: | 151 // crash: |
| 151 /*const factory B.named() = A<S>;*/ | 152 const factory B.named() = A<S>; |
| 152 } | 153 } |
| 153 class C<U> { | 154 class C<U> { |
| 154 const factory C({field1}) = A<B<double>>; | 155 const factory C({field1}) = A<B<double>>; |
| 155 } | 156 } |
| 156 ''', const [ | 157 ''', const [ |
| 157 const ConstantData('const A()', ConstantExpressionKind.CONSTRUCTED, | 158 const ConstantData('const A()', ConstantExpressionKind.CONSTRUCTED, |
| 158 type: 'A<dynamic>', | 159 type: 'A<dynamic>', |
| 159 fields: const {'field(A#field1)': '42'}), | 160 fields: const {'field(A#field1)': '42'}), |
| 160 const ConstantData('const A<int>(field1: 87)', | 161 const ConstantData('const A<int>(field1: 87)', |
| 161 ConstantExpressionKind.CONSTRUCTED, | 162 ConstantExpressionKind.CONSTRUCTED, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 176 type: 'A<B<int>>', | 177 type: 'A<B<int>>', |
| 177 fields: const { | 178 fields: const { |
| 178 'field(A#field1)': '87', | 179 'field(A#field1)': '87', |
| 179 }), | 180 }), |
| 180 const ConstantData('const C<int>(field1: 87)', | 181 const ConstantData('const C<int>(field1: 87)', |
| 181 ConstantExpressionKind.CONSTRUCTED, | 182 ConstantExpressionKind.CONSTRUCTED, |
| 182 type: 'A<B<double>>', | 183 type: 'A<B<double>>', |
| 183 fields: const { | 184 fields: const { |
| 184 'field(A#field1)': '87', | 185 'field(A#field1)': '87', |
| 185 }), | 186 }), |
| 186 // TODO(johnniwinther): Enable this when the constructor evaluator doesn't | 187 const ConstantData('const B<int>.named()', |
| 187 // crash: | |
| 188 /*const ConstantData('const B<int>.named()', | |
| 189 ConstantExpressionKind.CONSTRUCTED, | 188 ConstantExpressionKind.CONSTRUCTED, |
| 190 type: 'A<int>', | 189 type: 'A<int>', |
| 191 fields: const { | 190 fields: const { |
| 192 'field(A#field1)': '42', | 191 'field(A#field1)': '42', |
| 193 }),*/ | 192 }), |
| 194 ]), | 193 ]), |
| 195 ]; | 194 ]; |
| 196 | 195 |
| 197 main() { | 196 main() { |
| 198 asyncTest(() => Future.forEach(DATA, testData)); | 197 asyncTest(() => Future.forEach(DATA, testData)); |
| 199 } | 198 } |
| 200 | 199 |
| 201 Future testData(TestData data) { | 200 Future testData(TestData data) { |
| 202 StringBuffer sb = new StringBuffer(); | 201 StringBuffer sb = new StringBuffer(); |
| 203 sb.write('${data.declarations}\n'); | 202 sb.write('${data.declarations}\n'); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 String expression = instanceFields[field].getText(); | 237 String expression = instanceFields[field].getText(); |
| 239 String expected = data.fields[name]; | 238 String expected = data.fields[name]; |
| 240 Expect.equals(expected, expression, | 239 Expect.equals(expected, expression, |
| 241 "Unexpected field expression ${expression} for field '$name' in " | 240 "Unexpected field expression ${expression} for field '$name' in " |
| 242 "contant `${constant.getText()}`, expected '${expected}'."); | 241 "contant `${constant.getText()}`, expected '${expected}'."); |
| 243 }); | 242 }); |
| 244 } | 243 } |
| 245 }); | 244 }); |
| 246 }); | 245 }); |
| 247 } | 246 } |
| OLD | NEW |