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

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

Issue 11863007: Fix optional arguments handling. Handling of default values is for a further (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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/cpa_inference_test.dart
diff --git a/tests/compiler/dart2js/cpa_inference_test.dart b/tests/compiler/dart2js/cpa_inference_test.dart
index 99558b77a36ee94a952fbe3e558c341ba82ce532..ea8ffce300edb1567e2ce0adfa7e2aacf0ef89d6 100644
--- a/tests/compiler/dart2js/cpa_inference_test.dart
+++ b/tests/compiler/dart2js/cpa_inference_test.dart
@@ -511,15 +511,27 @@ testSetters() {
result.double]); // dynamic.y = double
}
-testNamedParameters() {
+testOptionalNamedParameters() {
karlklose 2013/01/15 09:54:51 Perhaps you should add a few tests using methods i
polux 2013/01/17 09:14:27 Done.
final String source = r"""
class A {
var x, y, z, w;
A(this.x, {this.y, this.z, this.w});
}
+ class B {
+ var x, y;
+ B(this.x, {this.y});
+ }
+ class C {
+ var x, y;
+ C(this.x, {this.y});
+ }
main() {
new A(42);
new A('abc', w: true, z: 42.0);
+ new B('abc', y: true);
+ new B(1, 2); // too many positional arguments
+ new C('abc', y: true);
+ new C(1, z: 2); // non-existing named parameter
}
""";
AnalysisResult result = analyze(source);
@@ -527,6 +539,36 @@ testNamedParameters() {
result.checkFieldHasType('A', 'y', [new NullBaseType()]);
result.checkFieldHasType('A', 'z', [new NullBaseType(), result.double]);
result.checkFieldHasType('A', 'w', [new NullBaseType(), result.bool]);
+ result.checkFieldHasType('B', 'x', [result.string]);
+ result.checkFieldHasType('B', 'y', [result.bool]);
+ result.checkFieldHasType('C', 'x', [result.string]);
+ result.checkFieldHasType('C', 'y', [result.bool]);
+}
+
+testOptionalPositionalParameters() {
+ final String source = r"""
+ class A {
+ var x, y, z, w;
+ A(this.x, [this.y, this.z, this.w]);
+ }
+ class B {
+ var x, y;
+ B(this.x, [this.y]);
+ }
+ main() {
+ new A(42);
+ new A('abc', true, 42.0);
+ new B('a', true);
+ new B(1, 2, 3); // too many arguments
+ }
+ """;
+ AnalysisResult result = analyze(source);
+ result.checkFieldHasType('A', 'x', [result.int, result.string]);
+ result.checkFieldHasType('A', 'y', [new NullBaseType(), result.bool]);
+ result.checkFieldHasType('A', 'z', [new NullBaseType(), result.double]);
+ result.checkFieldHasType('A', 'w', [new NullBaseType()]);
+ result.checkFieldHasType('B', 'x', [result.string]);
+ result.checkFieldHasType('B', 'y', [result.bool]);
}
testListLiterals() {
@@ -861,7 +903,8 @@ void main() {
testConstructor();
testGetters();
testSetters();
- testNamedParameters();
+ testOptionalNamedParameters();
+ testOptionalPositionalParameters();
testListLiterals();
testMapLiterals();
testReturn();

Powered by Google App Engine
This is Rietveld 408576698