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

Side by Side 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 unified diff | Download patch
« runtime/vm/parser.cc ('K') | « tests/language/language_dart2js.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
31 testMalformed() {
32 Expect.throws(() => new NoSuchClass#);
33 Expect.throws(() => new A#noSuchContstructor);
34 }
35
36 testA() {
37 var cc = new A#; // Closurize implicit constructor.
38 var o = cc();
39 Expect.equals("A.f1", o.f1);
40 Expect.equals("A.f1", (new A#)().f1);
41 Expect.throws(() => new A#foo);
42 }
43
44 testP() {
45 var cc = new P#origin;
46 var o = cc();
47 Expect.equals(0, o.x);
48 cc = new P#ursprung;
49 o = cc();
50 Expect.equals(0, o.x);
51 cc = new P#onXAxis;
52 o = cc(5);
53 Expect.equals(0, o.y);
54 Expect.equals(5, o.x);
55 Expect.throws(() => cc(1, 1)); // Too many arguments.
56 }
57
58 testC() {
59 var cc = new C<int>#;
60 var o = cc(5);
61 Expect.equals("int", "${o.f1.runtimeType}");
62 Expect.throws(() => cc()); // Missing constructor parameter.
63
64 cc = new C<String>#n;
65 o = cc("foo");
66 Expect.equals("String", "${o.f1.runtimeType}");
67 o = cc();
68 Expect.equals(null, o.f1);
69
70 cc = o.listMaker();
71 Expect.isTrue(cc is Function);
72 var l = cc();
73 Expect.equals("List<String>", "${l.runtimeType}");
74 }
75
76 main() {
77 testA();
78 testC();
79 testP();
80 testMalformed();
81 }
OLDNEW
« 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