| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Basic test for tear-off constructor closures. | |
| 6 | |
| 7 import "package:expect/expect.dart"; | |
| 8 | |
| 9 class A { | |
| 10 // Implicit constructor A(); | |
| 11 var f1 = "A.f1"; | |
| 12 } | |
| 13 | |
| 14 class P { | |
| 15 var x, y; | |
| 16 P(this.x, this.y); | |
| 17 factory P.origin() { return new P(0,0); } | |
| 18 factory P.ursprung() = P.origin; | |
| 19 P.onXAxis(x) : this(x, 0); | |
| 20 } | |
| 21 | |
| 22 class C<T> { | |
| 23 T f1; | |
| 24 C(T p) : f1 = p; | |
| 25 C.n([T p]) : f1 = p; | |
| 26 listMaker() { return new List<T>#; } // Closurize type parameter. | |
| 27 } | |
| 28 | |
| 29 | |
| 30 testMalformed() { | |
| 31 Expect.throws(() => new NoSuchClass#); | |
| 32 Expect.throws(() => new A#noSuchContstructor); | |
| 33 } | |
| 34 | |
| 35 testA() { | |
| 36 var cc = new A#; // Closurize implicit constructor. | |
| 37 var o = cc(); | |
| 38 Expect.equals("A.f1", o.f1); | |
| 39 Expect.equals("A.f1", (new A#)().f1); | |
| 40 Expect.throws(() => new A#foo); | |
| 41 } | |
| 42 | |
| 43 testP() { | |
| 44 var cc = new P#origin; | |
| 45 var o = cc(); | |
| 46 Expect.equals(0, o.x); | |
| 47 cc = new P#ursprung; | |
| 48 o = cc(); | |
| 49 Expect.equals(0, o.x); | |
| 50 cc = new P#onXAxis; | |
| 51 o = cc(5); | |
| 52 Expect.equals(0, o.y); | |
| 53 Expect.equals(5, o.x); | |
| 54 Expect.throws(() => cc(1, 1)); // Too many arguments. | |
| 55 } | |
| 56 | |
| 57 testC() { | |
| 58 var cc = new C<int>#; | |
| 59 var o = cc(5); | |
| 60 Expect.equals("int", "${o.f1.runtimeType}"); | |
| 61 Expect.throws(() => cc()); // Missing constructor parameter. | |
| 62 | |
| 63 cc = new C<String>#n; | |
| 64 o = cc("foo"); | |
| 65 Expect.equals("String", "${o.f1.runtimeType}"); | |
| 66 o = cc(); | |
| 67 Expect.equals(null, o.f1); | |
| 68 | |
| 69 cc = o.listMaker(); | |
| 70 Expect.isTrue(cc is Function); | |
| 71 var l = cc(); | |
| 72 Expect.equals("List<String>", "${l.runtimeType}"); | |
| 73 } | |
| 74 | |
| 75 main() { | |
| 76 testA(); | |
| 77 testC(); | |
| 78 testP(); | |
| 79 testMalformed(); | |
| 80 } | |
| OLD | NEW |