Index: tests/compiler/dart2js/constant_expression_evaluate_test.dart |
diff --git a/tests/compiler/dart2js/constant_expression_evaluate_test.dart b/tests/compiler/dart2js/constant_expression_evaluate_test.dart |
index 3dd05aca7e278388a528581b03437ac31ad5d2ef..a3ab7e266fb5fd1d6203b2de281e49e68d0d1c14 100644 |
--- a/tests/compiler/dart2js/constant_expression_evaluate_test.dart |
+++ b/tests/compiler/dart2js/constant_expression_evaluate_test.dart |
@@ -18,6 +18,7 @@ import 'memory_compiler.dart'; |
class TestData { |
/// Declarations needed for the [constants]. |
final String declarations; |
+ |
/// Tested constants. |
final List constants; |
@@ -27,19 +28,18 @@ class TestData { |
class ConstantData { |
/// Source code for the constant expression. |
final String code; |
+ |
/// Map from environment to expected constant value as structured text. |
final Map<Map<String, String>, String> expectedValues; |
- const ConstantData(this.code, |
- this.expectedValues); |
+ const ConstantData(this.code, this.expectedValues); |
} |
class MemoryEnvironment implements Environment { |
final Compiler compiler; |
final Map<String, String> env; |
- MemoryEnvironment(this.compiler, |
- [this.env = const <String, String>{}]); |
+ MemoryEnvironment(this.compiler, [this.env = const <String, String>{}]); |
@override |
String readFromEnvironment(String name) => env[name]; |
@@ -47,57 +47,62 @@ class MemoryEnvironment implements Environment { |
const List<TestData> DATA = const [ |
const TestData('', const [ |
- const ConstantData('null', const { const {} : 'NullConstant' }), |
- const ConstantData('false', const { const {} : 'BoolConstant(false)' }), |
- const ConstantData('true', const { const {} : 'BoolConstant(true)' }), |
- const ConstantData('0', const { const {} : 'IntConstant(0)' }), |
- const ConstantData('0.0', const { const {} : 'DoubleConstant(0.0)' }), |
- const ConstantData('"foo"', const { const {} : 'StringConstant("foo")' }), |
- const ConstantData('1 + 2', const { const {} : 'IntConstant(3)' }), |
- const ConstantData('-(1)', const { const {} : 'IntConstant(-1)' }), |
- const ConstantData('1 == 2', const { const {} : 'BoolConstant(false)' }), |
- const ConstantData('1 != 2', const { const {} : 'BoolConstant(true)' }), |
- const ConstantData('"foo".length', const { const {} : 'IntConstant(3)' }), |
- const ConstantData('identical(0, 1)', |
- const { const {} : 'BoolConstant(false)' }), |
- const ConstantData('"a" "b"', const { const {} : 'StringConstant("ab")' }), |
- const ConstantData(r'"${null}"', |
- const { const {} : 'StringConstant("null")' }), |
- const ConstantData('identical', |
- const { const {} : 'FunctionConstant(identical)' }), |
- const ConstantData('true ? 0 : 1', const { const {} : 'IntConstant(0)' }), |
- const ConstantData('proxy', |
- const { const {} : 'ConstructedConstant(_Proxy())' }), |
- const ConstantData('Object', const { const {} : 'TypeConstant(Object)' }), |
+ const ConstantData('null', const {const {}: 'NullConstant'}), |
+ const ConstantData('false', const {const {}: 'BoolConstant(false)'}), |
+ const ConstantData('true', const {const {}: 'BoolConstant(true)'}), |
+ const ConstantData('0', const {const {}: 'IntConstant(0)'}), |
+ const ConstantData('0.0', const {const {}: 'DoubleConstant(0.0)'}), |
+ const ConstantData('"foo"', const {const {}: 'StringConstant("foo")'}), |
+ const ConstantData('1 + 2', const {const {}: 'IntConstant(3)'}), |
+ const ConstantData('-(1)', const {const {}: 'IntConstant(-1)'}), |
+ const ConstantData('1 == 2', const {const {}: 'BoolConstant(false)'}), |
+ const ConstantData('1 != 2', const {const {}: 'BoolConstant(true)'}), |
+ const ConstantData('"foo".length', const {const {}: 'IntConstant(3)'}), |
+ const ConstantData( |
+ 'identical(0, 1)', const {const {}: 'BoolConstant(false)'}), |
+ const ConstantData('"a" "b"', const {const {}: 'StringConstant("ab")'}), |
+ const ConstantData( |
+ r'"${null}"', const {const {}: 'StringConstant("null")'}), |
+ const ConstantData( |
+ 'identical', const {const {}: 'FunctionConstant(identical)'}), |
+ const ConstantData('true ? 0 : 1', const {const {}: 'IntConstant(0)'}), |
+ const ConstantData( |
+ 'proxy', const {const {}: 'ConstructedConstant(_Proxy())'}), |
+ const ConstantData('Object', const {const {}: 'TypeConstant(Object)'}), |
const ConstantData('const [0, 1]', |
- const { const {} : 'ListConstant([IntConstant(0), IntConstant(1)])' }), |
+ const {const {}: 'ListConstant([IntConstant(0), IntConstant(1)])'}), |
const ConstantData('const <int>[0, 1]', const { |
- const {} : 'ListConstant(<int>[IntConstant(0), IntConstant(1)])' }), |
- const ConstantData('const {0: 1, 2: 3}', |
- const { const {} : |
- 'MapConstant({IntConstant(0): IntConstant(1), ' |
- 'IntConstant(2): IntConstant(3)})' }), |
- const ConstantData('const <int, int>{0: 1, 2: 3}', |
- const { const {} : |
- 'MapConstant(<int, int>{IntConstant(0): IntConstant(1), ' |
- 'IntConstant(2): IntConstant(3)})' }), |
- const ConstantData('const <int, int>{0: 1, 0: 2}', |
- const { const {} : |
- 'MapConstant(<int, int>{IntConstant(0): IntConstant(2)})' }), |
+ const {}: 'ListConstant(<int>[IntConstant(0), IntConstant(1)])' |
+ }), |
+ const ConstantData('const {0: 1, 2: 3}', const { |
+ const {}: 'MapConstant({IntConstant(0): IntConstant(1), ' |
+ 'IntConstant(2): IntConstant(3)})' |
+ }), |
+ const ConstantData('const <int, int>{0: 1, 2: 3}', const { |
+ const {}: 'MapConstant(<int, int>{IntConstant(0): IntConstant(1), ' |
+ 'IntConstant(2): IntConstant(3)})' |
+ }), |
+ const ConstantData('const <int, int>{0: 1, 0: 2}', const { |
+ const {}: 'MapConstant(<int, int>{IntConstant(0): IntConstant(2)})' |
+ }), |
const ConstantData( |
- 'const bool.fromEnvironment("foo", defaultValue: false)', |
- const { const {} : 'BoolConstant(false)', |
- const {'foo': 'true'} : 'BoolConstant(true)'}), |
+ 'const bool.fromEnvironment("foo", defaultValue: false)', const { |
+ const {}: 'BoolConstant(false)', |
+ const {'foo': 'true'}: 'BoolConstant(true)' |
+ }), |
const ConstantData( |
- 'const int.fromEnvironment("foo", defaultValue: 42)', |
- const { const {} : 'IntConstant(42)', |
- const {'foo': '87'} : 'IntConstant(87)'}), |
+ 'const int.fromEnvironment("foo", defaultValue: 42)', const { |
+ const {}: 'IntConstant(42)', |
+ const {'foo': '87'}: 'IntConstant(87)' |
+ }), |
const ConstantData( |
- 'const String.fromEnvironment("foo", defaultValue: "bar")', |
- const { const {} : 'StringConstant("bar")', |
- const {'foo': 'foo'} : 'StringConstant("foo")'}), |
+ 'const String.fromEnvironment("foo", defaultValue: "bar")', const { |
+ const {}: 'StringConstant("bar")', |
+ const {'foo': 'foo'}: 'StringConstant("foo")' |
+ }), |
]), |
- const TestData(''' |
+ const TestData( |
+ ''' |
const a = const bool.fromEnvironment("foo", defaultValue: true); |
const b = const int.fromEnvironment("bar", defaultValue: 42); |
@@ -117,44 +122,52 @@ class D extends C { |
final field3 = 99; |
const D(a, b) : super(field2: a, field1: b); |
} |
-''', const [ |
- const ConstantData('const Object()', |
- const { const {} : 'ConstructedConstant(Object())' }), |
- const ConstantData('const A()', |
- const { const {} : 'ConstructedConstant(A())' }), |
- const ConstantData('const B(0)', |
- const { const {} : 'ConstructedConstant(B(field1=IntConstant(0)))' }), |
- const ConstantData('const B(const A())', |
- const { const {} : |
- 'ConstructedConstant(B(field1=ConstructedConstant(A())))' }), |
- const ConstantData('const C()', const { const {} : |
- 'ConstructedConstant(C(field1=IntConstant(42),' |
- 'field2=BoolConstant(false)))' }), |
- const ConstantData('const C(field1: 87)', const { const {} : |
- 'ConstructedConstant(C(field1=IntConstant(87),' |
- 'field2=BoolConstant(false)))' }), |
- const ConstantData('const C(field2: true)', const { const {} : |
- 'ConstructedConstant(C(field1=IntConstant(42),' |
- 'field2=BoolConstant(true)))' }), |
- const ConstantData('const C.named()', const { const {} : |
- 'ConstructedConstant(C(field1=BoolConstant(false),' |
- 'field2=BoolConstant(false)))' }), |
- const ConstantData('const C.named(87)', const { const {} : |
- 'ConstructedConstant(C(field1=IntConstant(87),' |
- 'field2=IntConstant(87)))' }), |
- const ConstantData('const C(field1: a, field2: b)', const { |
- const {} : |
- 'ConstructedConstant(C(field1=BoolConstant(true),' |
- 'field2=IntConstant(42)))', |
- const {'foo': 'false', 'bar': '87'} : |
- 'ConstructedConstant(C(field1=BoolConstant(false),' |
- 'field2=IntConstant(87)))', }), |
- const ConstantData('const D(42, 87)', const { const {} : |
- 'ConstructedConstant(D(field1=IntConstant(87),' |
- 'field2=IntConstant(42),' |
- 'field3=IntConstant(99)))' }), |
- ]), |
- const TestData(''' |
+''', |
+ const [ |
+ const ConstantData('const Object()', |
+ const {const {}: 'ConstructedConstant(Object())'}), |
+ const ConstantData( |
+ 'const A()', const {const {}: 'ConstructedConstant(A())'}), |
+ const ConstantData('const B(0)', |
+ const {const {}: 'ConstructedConstant(B(field1=IntConstant(0)))'}), |
+ const ConstantData('const B(const A())', const { |
+ const {}: 'ConstructedConstant(B(field1=ConstructedConstant(A())))' |
+ }), |
+ const ConstantData('const C()', const { |
+ const {}: 'ConstructedConstant(C(field1=IntConstant(42),' |
+ 'field2=BoolConstant(false)))' |
+ }), |
+ const ConstantData('const C(field1: 87)', const { |
+ const {}: 'ConstructedConstant(C(field1=IntConstant(87),' |
+ 'field2=BoolConstant(false)))' |
+ }), |
+ const ConstantData('const C(field2: true)', const { |
+ const {}: 'ConstructedConstant(C(field1=IntConstant(42),' |
+ 'field2=BoolConstant(true)))' |
+ }), |
+ const ConstantData('const C.named()', const { |
+ const {}: 'ConstructedConstant(C(field1=BoolConstant(false),' |
+ 'field2=BoolConstant(false)))' |
+ }), |
+ const ConstantData('const C.named(87)', const { |
+ const {}: 'ConstructedConstant(C(field1=IntConstant(87),' |
+ 'field2=IntConstant(87)))' |
+ }), |
+ const ConstantData('const C(field1: a, field2: b)', const { |
+ const {}: 'ConstructedConstant(C(field1=BoolConstant(true),' |
+ 'field2=IntConstant(42)))', |
+ const {'foo': 'false', 'bar': '87'}: |
+ 'ConstructedConstant(C(field1=BoolConstant(false),' |
+ 'field2=IntConstant(87)))', |
+ }), |
+ const ConstantData('const D(42, 87)', const { |
+ const {}: 'ConstructedConstant(D(field1=IntConstant(87),' |
+ 'field2=IntConstant(42),' |
+ 'field3=IntConstant(99)))' |
+ }), |
+ ]), |
+ const TestData( |
+ ''' |
class A<T> implements B { |
final field1; |
const A({this.field1:42}); |
@@ -166,30 +179,32 @@ class B<S> implements C { |
class C<U> { |
const factory C({field1}) = A<B<double>>; |
} |
-''', const [ |
- const ConstantData('const A()', |
- const { const {} : |
- 'ConstructedConstant(A<dynamic>(field1=IntConstant(42)))' }), |
- const ConstantData('const A<int>(field1: 87)', |
- const { const {} : |
- 'ConstructedConstant(A<int>(field1=IntConstant(87)))' }), |
- const ConstantData('const B()', |
- const { const {} : |
- 'ConstructedConstant(A<B<dynamic>>(field1=IntConstant(42)))' }), |
- const ConstantData('const B<int>()', |
- const { const {} : |
- 'ConstructedConstant(A<B<int>>(field1=IntConstant(42)))' }), |
- const ConstantData('const B<int>(field1: 87)', |
- const { const {} : |
- 'ConstructedConstant(A<B<int>>(field1=IntConstant(87)))' }), |
- const ConstantData('const C<int>(field1: 87)', |
- const { const {} : |
- 'ConstructedConstant(A<B<double>>(field1=IntConstant(87)))' }), |
- const ConstantData('const B<int>.named()', |
- const { const {} : |
- 'ConstructedConstant(A<int>(field1=IntConstant(42)))' }), |
- ]), |
- const TestData(''' |
+''', |
+ const [ |
+ const ConstantData('const A()', const { |
+ const {}: 'ConstructedConstant(A<dynamic>(field1=IntConstant(42)))' |
+ }), |
+ const ConstantData('const A<int>(field1: 87)', const { |
+ const {}: 'ConstructedConstant(A<int>(field1=IntConstant(87)))' |
+ }), |
+ const ConstantData('const B()', const { |
+ const {}: 'ConstructedConstant(A<B<dynamic>>(field1=IntConstant(42)))' |
+ }), |
+ const ConstantData('const B<int>()', const { |
+ const {}: 'ConstructedConstant(A<B<int>>(field1=IntConstant(42)))' |
+ }), |
+ const ConstantData('const B<int>(field1: 87)', const { |
+ const {}: 'ConstructedConstant(A<B<int>>(field1=IntConstant(87)))' |
+ }), |
+ const ConstantData('const C<int>(field1: 87)', const { |
+ const {}: 'ConstructedConstant(A<B<double>>(field1=IntConstant(87)))' |
+ }), |
+ const ConstantData('const B<int>.named()', const { |
+ const {}: 'ConstructedConstant(A<int>(field1=IntConstant(42)))' |
+ }), |
+ ]), |
+ const TestData( |
+ ''' |
const c = const int.fromEnvironment("foo", defaultValue: 5); |
const d = const int.fromEnvironment("bar", defaultValue: 10); |
@@ -201,18 +216,18 @@ class A { |
class B extends A { |
const B(a) : super(a, a * 2); |
} |
-''', const [ |
- const ConstantData('const A(c, d)', const { |
- const {} : |
- 'ConstructedConstant(A(field=IntConstant(15)))', |
- const {'foo': '7', 'bar': '11'} : |
- 'ConstructedConstant(A(field=IntConstant(18)))', }), |
- const ConstantData('const B(d)', const { |
- const {} : |
- 'ConstructedConstant(B(field=IntConstant(30)))', |
- const {'bar': '42'} : |
- 'ConstructedConstant(B(field=IntConstant(126)))', }), |
- ]), |
+''', |
+ const [ |
+ const ConstantData('const A(c, d)', const { |
+ const {}: 'ConstructedConstant(A(field=IntConstant(15)))', |
+ const {'foo': '7', 'bar': '11'}: |
+ 'ConstructedConstant(A(field=IntConstant(18)))', |
+ }), |
+ const ConstantData('const B(d)', const { |
+ const {}: 'ConstructedConstant(B(field=IntConstant(30)))', |
+ const {'bar': '42'}: 'ConstructedConstant(B(field=IntConstant(126)))', |
+ }), |
+ ]), |
]; |
main() { |
@@ -237,13 +252,14 @@ Future testData(TestData data) async { |
constants.forEach((String name, ConstantData data) { |
FieldElement field = library.localLookup(name); |
ConstantExpression constant = field.constant; |
- data.expectedValues.forEach( |
- (Map<String, String> env, String expectedText) { |
+ data.expectedValues.forEach((Map<String, String> env, String expectedText) { |
Environment environment = new MemoryEnvironment(compiler, env); |
ConstantValue value = |
constant.evaluate(environment, DART_CONSTANT_SYSTEM); |
String valueText = value.toStructuredText(); |
- Expect.equals(expectedText, valueText, |
+ Expect.equals( |
+ expectedText, |
+ valueText, |
"Unexpected value '${valueText}' for contant " |
"`${constant.toDartText()}`, expected '${expectedText}'."); |
}); |