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

Unified Diff: tests/language/tearoff_constructor_basic_test.dart

Issue 1255063005: Constructor tear-off closures (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Skip tearoff test in analyzer and dart2js Created 5 years, 4 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
« runtime/vm/parser.cc ('K') | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/tearoff_constructor_basic_test.dart
diff --git a/tests/language/tearoff_constructor_basic_test.dart b/tests/language/tearoff_constructor_basic_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..d86f2cb320d87769a1ef26f6dff2513206e094e4
--- /dev/null
+++ b/tests/language/tearoff_constructor_basic_test.dart
@@ -0,0 +1,81 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Basic test for tear-off constructor closures.
+
+import "package:expect/expect.dart";
+
+class A {
+ // Implicit constructor A();
+ var f1 = "A.f1";
+}
+
+class P {
+ var x, y;
+ P(this.x, this.y);
+ factory P.origin() { return new P(0,0); }
+ factory P.ursprung() = P.origin;
+ P.onXAxis(x) : this(x, 0);
+}
+
+class C<T> {
+ T f1;
+ C(T p) : f1 = p;
+ C.n([T p]) : f1 = p;
+ listMaker() { return new List<T>#; } // Closurize type parameter.
+}
+
+
+
+testMalformed() {
+ Expect.throws(() => new NoSuchClass#);
+ Expect.throws(() => new A#noSuchContstructor);
+}
+
+testA() {
+ var cc = new A#; // Closurize implicit constructor.
+ var o = cc();
+ Expect.equals("A.f1", o.f1);
+ Expect.equals("A.f1", (new A#)().f1);
+ Expect.throws(() => new A#foo);
+}
+
+testP() {
+ var cc = new P#origin;
+ var o = cc();
+ Expect.equals(0, o.x);
+ cc = new P#ursprung;
+ o = cc();
+ Expect.equals(0, o.x);
+ cc = new P#onXAxis;
+ o = cc(5);
+ Expect.equals(0, o.y);
+ Expect.equals(5, o.x);
+ Expect.throws(() => cc(1, 1)); // Too many arguments.
+}
+
+testC() {
+ var cc = new C<int>#;
+ var o = cc(5);
+ Expect.equals("int", "${o.f1.runtimeType}");
+ Expect.throws(() => cc()); // Missing constructor parameter.
+
+ cc = new C<String>#n;
+ o = cc("foo");
+ Expect.equals("String", "${o.f1.runtimeType}");
+ o = cc();
+ Expect.equals(null, o.f1);
+
+ cc = o.listMaker();
+ Expect.isTrue(cc is Function);
+ var l = cc();
+ Expect.equals("List<String>", "${l.runtimeType}");
+}
+
+main() {
+ testA();
+ testC();
+ testP();
+ testMalformed();
+}
« runtime/vm/parser.cc ('K') | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698