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

Unified Diff: tests/compiler/dart2js/constant_expression_test.dart

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: tests/compiler/dart2js/constant_expression_test.dart
diff --git a/tests/compiler/dart2js/constant_expression_test.dart b/tests/compiler/dart2js/constant_expression_test.dart
index 16ec71e28fdbad3e2e4d5c1858af9f78cd1b45e0..7013167e36397aff03fcf4bc0aaefc095f6a7b99 100644
--- a/tests/compiler/dart2js/constant_expression_test.dart
+++ b/tests/compiler/dart2js/constant_expression_test.dart
@@ -15,6 +15,7 @@ import 'memory_compiler.dart';
class TestData {
/// Declarations needed for the [constants].
final String declarations;
+
/// Tested constants.
final List constants;
@@ -24,20 +25,21 @@ class TestData {
class ConstantData {
/// Source code for the constant expression.
final String code;
+
/// The expected constant expression kind.
final ConstantExpressionKind kind;
+
/// ConstantExpression.getText() result if different from [code].
final String text;
+
/// The expected instance type for ConstructedConstantExpression.
final String type;
+
/// The expected instance fields for ConstructedConstantExpression.
final Map<String, String> fields;
- const ConstantData(String code,
- this.kind,
- {String text,
- this.type,
- this.fields})
+ const ConstantData(String code, this.kind,
+ {String text, this.type, this.fields})
: this.code = code,
this.text = text != null ? text : code;
}
@@ -58,7 +60,7 @@ const List<TestData> DATA = const [
const ConstantData('"foo".length', ConstantExpressionKind.STRING_LENGTH),
const ConstantData('identical(0, 1)', ConstantExpressionKind.IDENTICAL),
const ConstantData('"a" "b"', ConstantExpressionKind.CONCATENATE,
- text: '"ab"'),
+ text: '"ab"'),
const ConstantData('identical', ConstantExpressionKind.FUNCTION),
const ConstantData('true ? 0 : 1', ConstantExpressionKind.CONDITIONAL),
const ConstantData('proxy', ConstantExpressionKind.VARIABLE),
@@ -67,19 +69,18 @@ const List<TestData> DATA = const [
const ConstantData('const [0, 1]', ConstantExpressionKind.LIST),
const ConstantData('const <int>[0, 1]', ConstantExpressionKind.LIST),
const ConstantData('const {0: 1, 2: 3}', ConstantExpressionKind.MAP),
- const ConstantData('const <int, int>{0: 1, 2: 3}',
- ConstantExpressionKind.MAP),
const ConstantData(
- 'const bool.fromEnvironment("foo", defaultValue: false)',
+ 'const <int, int>{0: 1, 2: 3}', ConstantExpressionKind.MAP),
+ const ConstantData('const bool.fromEnvironment("foo", defaultValue: false)',
ConstantExpressionKind.BOOL_FROM_ENVIRONMENT),
- const ConstantData(
- 'const int.fromEnvironment("foo", defaultValue: 42)',
+ const ConstantData('const int.fromEnvironment("foo", defaultValue: 42)',
ConstantExpressionKind.INT_FROM_ENVIRONMENT),
const ConstantData(
'const String.fromEnvironment("foo", defaultValue: "bar")',
ConstantExpressionKind.STRING_FROM_ENVIRONMENT),
]),
- const TestData('''
+ const TestData(
+ '''
class A {
const A();
}
@@ -92,58 +93,54 @@ class C extends B {
const C({field1: 42, this.field2: false}) : super(field1);
const C.named([field = false]) : this(field1: field, field2: field);
}
-''', const [
- const ConstantData('const Object()',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'Object', fields: const {}),
- const ConstantData('const A()',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'A', fields: const {}),
- const ConstantData('const B(0)',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'B',
- fields: const {'field(B#field1)': '0'}),
- const ConstantData('const B(const A())',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'B',
- fields: const {'field(B#field1)': 'const A()'}),
- const ConstantData('const C()',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'C',
- fields: const {
- 'field(B#field1)': '42',
- 'field(C#field2)': 'false',
- }),
- const ConstantData('const C(field1: 87)',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'C',
- fields: const {
- 'field(B#field1)': '87',
- 'field(C#field2)': 'false',
- }),
- const ConstantData('const C(field2: true)',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'C',
- fields: const {
- 'field(B#field1)': '42',
- 'field(C#field2)': 'true',
- }),
- const ConstantData('const C.named()',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'C',
- fields: const {
- 'field(B#field1)': 'false',
- 'field(C#field2)': 'false',
- }),
- const ConstantData('const C.named(87)',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'C',
- fields: const {
- 'field(B#field1)': '87',
- 'field(C#field2)': '87',
- }),
- ]),
- const TestData('''
+''',
+ const [
+ const ConstantData('const Object()', ConstantExpressionKind.CONSTRUCTED,
+ type: 'Object', fields: const {}),
+ const ConstantData('const A()', ConstantExpressionKind.CONSTRUCTED,
+ type: 'A', fields: const {}),
+ const ConstantData('const B(0)', ConstantExpressionKind.CONSTRUCTED,
+ type: 'B', fields: const {'field(B#field1)': '0'}),
+ const ConstantData(
+ 'const B(const A())', ConstantExpressionKind.CONSTRUCTED,
+ type: 'B', fields: const {'field(B#field1)': 'const A()'}),
+ const ConstantData('const C()', ConstantExpressionKind.CONSTRUCTED,
+ type: 'C',
+ fields: const {
+ 'field(B#field1)': '42',
+ 'field(C#field2)': 'false',
+ }),
+ const ConstantData(
+ 'const C(field1: 87)', ConstantExpressionKind.CONSTRUCTED,
+ type: 'C',
+ fields: const {
+ 'field(B#field1)': '87',
+ 'field(C#field2)': 'false',
+ }),
+ const ConstantData(
+ 'const C(field2: true)', ConstantExpressionKind.CONSTRUCTED,
+ type: 'C',
+ fields: const {
+ 'field(B#field1)': '42',
+ 'field(C#field2)': 'true',
+ }),
+ const ConstantData(
+ 'const C.named()', ConstantExpressionKind.CONSTRUCTED,
+ type: 'C',
+ fields: const {
+ 'field(B#field1)': 'false',
+ 'field(C#field2)': 'false',
+ }),
+ const ConstantData(
+ 'const C.named(87)', ConstantExpressionKind.CONSTRUCTED,
+ type: 'C',
+ fields: const {
+ 'field(B#field1)': '87',
+ 'field(C#field2)': '87',
+ }),
+ ]),
+ const TestData(
+ '''
class A<T> implements B {
final field1;
const A({this.field1:42});
@@ -157,43 +154,42 @@ class B<S> implements C {
class C<U> {
const factory C({field1}) = A<B<double>>;
}
-''', const [
- const ConstantData('const A()', ConstantExpressionKind.CONSTRUCTED,
- type: 'A<dynamic>',
- fields: const {'field(A#field1)': '42'}),
- const ConstantData('const A<int>(field1: 87)',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'A<int>',
- fields: const {'field(A#field1)': '87'}),
- const ConstantData('const B()', ConstantExpressionKind.CONSTRUCTED,
- type: 'A<B<dynamic>>',
- fields: const {
- 'field(A#field1)': '42',
- }),
- const ConstantData('const B<int>()', ConstantExpressionKind.CONSTRUCTED,
- type: 'A<B<int>>',
- fields: const {
- 'field(A#field1)': '42',
- }),
- const ConstantData('const B<int>(field1: 87)',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'A<B<int>>',
- fields: const {
- 'field(A#field1)': '87',
- }),
- const ConstantData('const C<int>(field1: 87)',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'A<B<double>>',
- fields: const {
- 'field(A#field1)': '87',
- }),
- const ConstantData('const B<int>.named()',
- ConstantExpressionKind.CONSTRUCTED,
- type: 'A<int>',
- fields: const {
- 'field(A#field1)': '42',
- }),
- ]),
+''',
+ const [
+ const ConstantData('const A()', ConstantExpressionKind.CONSTRUCTED,
+ type: 'A<dynamic>', fields: const {'field(A#field1)': '42'}),
+ const ConstantData(
+ 'const A<int>(field1: 87)', ConstantExpressionKind.CONSTRUCTED,
+ type: 'A<int>', fields: const {'field(A#field1)': '87'}),
+ const ConstantData('const B()', ConstantExpressionKind.CONSTRUCTED,
+ type: 'A<B<dynamic>>',
+ fields: const {
+ 'field(A#field1)': '42',
+ }),
+ const ConstantData('const B<int>()', ConstantExpressionKind.CONSTRUCTED,
+ type: 'A<B<int>>',
+ fields: const {
+ 'field(A#field1)': '42',
+ }),
+ const ConstantData(
+ 'const B<int>(field1: 87)', ConstantExpressionKind.CONSTRUCTED,
+ type: 'A<B<int>>',
+ fields: const {
+ 'field(A#field1)': '87',
+ }),
+ const ConstantData(
+ 'const C<int>(field1: 87)', ConstantExpressionKind.CONSTRUCTED,
+ type: 'A<B<double>>',
+ fields: const {
+ 'field(A#field1)': '87',
+ }),
+ const ConstantData(
+ 'const B<int>.named()', ConstantExpressionKind.CONSTRUCTED,
+ type: 'A<int>',
+ fields: const {
+ 'field(A#field1)': '42',
+ }),
+ ]),
];
main() {
@@ -212,35 +208,44 @@ Future testData(TestData data) async {
sb.write('main() {}\n');
String source = sb.toString();
CompilationResult result = await runCompiler(
- memorySourceFiles: {'main.dart': source},
- options: ['--analyze-all']);
+ memorySourceFiles: {'main.dart': source}, options: ['--analyze-all']);
Compiler compiler = result.compiler;
var library = compiler.mainApp;
constants.forEach((String name, ConstantData data) {
FieldElement field = library.localLookup(name);
var constant = field.constant;
- Expect.equals(data.kind, constant.kind,
+ Expect.equals(
+ data.kind,
+ constant.kind,
"Unexpected kind '${constant.kind}' for contant "
"`${constant.toDartText()}`, expected '${data.kind}'.");
- Expect.equals(data.text, constant.toDartText(),
+ Expect.equals(
+ data.text,
+ constant.toDartText(),
"Unexpected text '${constant.toDartText()}' for contant, "
"expected '${data.text}'.");
if (data.type != null) {
String instanceType = constant.computeInstanceType().toString();
- Expect.equals(data.type, instanceType,
+ Expect.equals(
+ data.type,
+ instanceType,
"Unexpected type '$instanceType' for contant "
"`${constant.toDartText()}`, expected '${data.type}'.");
}
if (data.fields != null) {
Map instanceFields = constant.computeInstanceFields();
- Expect.equals(data.fields.length, instanceFields.length,
+ Expect.equals(
+ data.fields.length,
+ instanceFields.length,
"Unexpected field count ${instanceFields.length} for contant "
"`${constant.toDartText()}`, expected '${data.fields.length}'.");
instanceFields.forEach((field, expression) {
String name = '$field';
String expression = instanceFields[field].toDartText();
String expected = data.fields[name];
- Expect.equals(expected, expression,
+ Expect.equals(
+ expected,
+ expression,
"Unexpected field expression ${expression} for field '$name' in "
"contant `${constant.toDartText()}`, expected '${expected}'.");
});

Powered by Google App Engine
This is Rietveld 408576698