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

Unified Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1707073002: Serialize and resynthesize variable initializers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fixes for review comments. Created 4 years, 10 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
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/summary/summary_common.dart
diff --git a/pkg/analyzer/test/src/summary/summary_common.dart b/pkg/analyzer/test/src/summary/summary_common.dart
index 5e2f084a858189de7f3dd0751212ee6dea90f964..de38e8ee03851d0610d7a955ba24df2de5e23bb6 100644
--- a/pkg/analyzer/test/src/summary/summary_common.dart
+++ b/pkg/analyzer/test/src/summary/summary_common.dart
@@ -3249,6 +3249,7 @@ int foo() => 0;
.executables);
UnlinkedParam parameter = executable.parameters[0];
expect(parameter.kind, UnlinkedParamKind.named);
+ expect(parameter.initializer, isNotNull);
_assertUnlinkedConst(parameter.defaultValue,
operators: [UnlinkedConstOperation.pushInt], ints: [42]);
}
@@ -3277,6 +3278,7 @@ int foo() => 0;
.executables);
UnlinkedParam parameter = executable.parameters[0];
expect(parameter.kind, UnlinkedParamKind.positional);
+ expect(parameter.initializer, isNotNull);
_assertUnlinkedConst(parameter.defaultValue,
operators: [UnlinkedConstOperation.pushInt], ints: [42]);
}
@@ -4418,6 +4420,7 @@ int foo(int a, String b) => 0;
''');
UnlinkedParam param = executable.parameters[0];
expect(param.kind, UnlinkedParamKind.positional);
+ expect(param.initializer, isNotNull);
_assertUnlinkedConst(param.defaultValue, operators: [
UnlinkedConstOperation.pushReference
], referenceValidators: [
@@ -4430,6 +4433,7 @@ int foo(int a, String b) => 0;
UnlinkedExecutable executable = serializeExecutableText('f({x}) {}');
UnlinkedParam param = executable.parameters[0];
expect(param.kind, UnlinkedParamKind.named);
+ expect(param.initializer, isNull);
expect(param.defaultValue, isNull);
}
@@ -4437,6 +4441,7 @@ int foo(int a, String b) => 0;
UnlinkedExecutable executable = serializeExecutableText('f({x: 42}) {}');
UnlinkedParam param = executable.parameters[0];
expect(param.kind, UnlinkedParamKind.named);
+ expect(param.initializer, isNotNull);
_assertUnlinkedConst(param.defaultValue,
operators: [UnlinkedConstOperation.pushInt], ints: [42]);
}
@@ -4445,6 +4450,7 @@ int foo(int a, String b) => 0;
UnlinkedExecutable executable = serializeExecutableText('f([x]) {}');
UnlinkedParam param = executable.parameters[0];
expect(param.kind, UnlinkedParamKind.positional);
+ expect(param.initializer, isNull);
expect(param.defaultValue, isNull);
}
@@ -4452,6 +4458,7 @@ int foo(int a, String b) => 0;
UnlinkedExecutable executable = serializeExecutableText('f([x = 42]) {}');
UnlinkedParam param = executable.parameters[0];
expect(param.kind, UnlinkedParamKind.positional);
+ expect(param.initializer, isNotNull);
_assertUnlinkedConst(param.defaultValue,
operators: [UnlinkedConstOperation.pushInt], ints: [42]);
}
@@ -4460,6 +4467,7 @@ int foo(int a, String b) => 0;
UnlinkedExecutable executable = serializeExecutableText('f(x) {}');
UnlinkedParam param = executable.parameters[0];
expect(param.kind, UnlinkedParamKind.required);
+ expect(param.initializer, isNull);
expect(param.defaultValue, isNull);
}
@@ -6697,6 +6705,60 @@ var v;''';
expect(v.inferredTypeSlot, 0);
}
+ test_variable_initializer_literal() {
+ UnlinkedVariable variable = serializeVariableText('var v = 42;');
+ UnlinkedExecutable initializer = variable.initializer;
+ expect(initializer, isNotNull);
+ expect(initializer.nameOffset, 8);
+ expect(initializer.name, isEmpty);
+ expect(initializer.localFunctions, isEmpty);
+ expect(initializer.localVariables, isEmpty);
+ }
+
+ test_variable_initializer_noInitializer() {
+ UnlinkedVariable variable = serializeVariableText('var v;');
+ expect(variable.initializer, isNull);
+ }
+
+ test_variable_initializer_withLocals() {
+ String text =
+ 'var v = {"1": () { f1() {} var v1; }, "2": () { f2() {} var v2; }};';
+ UnlinkedVariable variable = serializeVariableText(text);
+ UnlinkedExecutable initializer = variable.initializer;
+ expect(initializer, isNotNull);
+ expect(initializer.nameOffset, text.indexOf('{"1'));
+ expect(initializer.name, isEmpty);
+ expect(initializer.localFunctions, hasLength(2));
+ // closure: () { f1() {} var v1; }
+ {
+ UnlinkedExecutable closure = initializer.localFunctions[0];
+ expect(closure.nameOffset, text.indexOf('() { f1()'));
+ expect(closure.name, isEmpty);
+ // closure - f1
+ expect(closure.localFunctions, hasLength(1));
+ expect(closure.localFunctions[0].name, 'f1');
+ expect(closure.localFunctions[0].nameOffset, text.indexOf('f1()'));
+ // closure - v1
+ expect(closure.localVariables, hasLength(1));
+ expect(closure.localVariables[0].name, 'v1');
+ expect(closure.localVariables[0].nameOffset, text.indexOf('v1;'));
+ }
+ // closure: () { f2() {} var v2; }
+ {
+ UnlinkedExecutable closure = initializer.localFunctions[1];
+ expect(closure.nameOffset, text.indexOf('() { f2()'));
+ expect(closure.name, isEmpty);
+ // closure - f1
+ expect(closure.localFunctions, hasLength(1));
+ expect(closure.localFunctions[0].name, 'f2');
+ expect(closure.localFunctions[0].nameOffset, text.indexOf('f2()'));
+ // closure - v1
+ expect(closure.localVariables, hasLength(1));
+ expect(closure.localVariables[0].name, 'v2');
+ expect(closure.localVariables[0].nameOffset, text.indexOf('v2;'));
+ }
+ }
+
test_variable_name() {
UnlinkedVariable variable =
serializeVariableText('int i;', variableName: 'i');
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698