| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 // Dart test program for constructors and initializers. | |
| 5 | |
| 6 // Check that generic closures are properly instantiated. | |
| 7 | |
| 8 import 'package:expect/expect.dart'; | |
| 9 | |
| 10 typedef T F<T>(T x); | |
| 11 typedef R G<T, R>(T x); | |
| 12 | |
| 13 class C<T> { | |
| 14 get f => (T x) => 2 * x; | |
| 15 T g(T x) => 3 * x; | |
| 16 } | |
| 17 | |
| 18 main() { | |
| 19 var c = new C<int>(); | |
| 20 var f = c.f; | |
| 21 var g = c.g; | |
| 22 Expect.equals(42, f(21)); | |
| 23 Expect.equals(42, g(14)); | |
| 24 Expect.isTrue(f is Function); | |
| 25 Expect.isTrue(g is Function); | |
| 26 Expect.isTrue(f is F); | |
| 27 Expect.isTrue(g is F); | |
| 28 Expect.isTrue(f is F<int>); | |
| 29 Expect.isTrue(g is F<int>); | |
| 30 Expect.isTrue(f is! F<bool>); | |
| 31 Expect.isTrue(g is! F<bool>); | |
| 32 Expect.isTrue(f is G<int, int>); | |
| 33 Expect.isTrue(g is G<int, int>); | |
| 34 Expect.isTrue(f is G<int, bool>); | |
| 35 Expect.isTrue(g is! G<int, bool>); | |
| 36 Expect.equals("(int) => dynamic", f.runtimeType.toString()); | |
| 37 Expect.equals("(int) => int", g.runtimeType.toString()); | |
| 38 | |
| 39 c = new C<bool>(); | |
| 40 f = c.f; | |
| 41 g = c.g; | |
| 42 Expect.isTrue(f is F); | |
| 43 Expect.isTrue(g is F); | |
| 44 Expect.isTrue(f is! F<int>); | |
| 45 Expect.isTrue(g is! F<int>); | |
| 46 Expect.isTrue(f is F<bool>); | |
| 47 Expect.isTrue(g is F<bool>); | |
| 48 Expect.equals("(bool) => dynamic", f.runtimeType.toString()); | |
| 49 Expect.equals("(bool) => bool", g.runtimeType.toString()); | |
| 50 | |
| 51 c = new C(); | |
| 52 f = c.f; | |
| 53 g = c.g; | |
| 54 Expect.isTrue(f is F); | |
| 55 Expect.isTrue(g is F); | |
| 56 Expect.isTrue(f is F<int>); | |
| 57 Expect.isTrue(g is F<int>); | |
| 58 Expect.isTrue(f is F<bool>); | |
| 59 Expect.isTrue(g is F<bool>); | |
| 60 Expect.equals("(dynamic) => dynamic", f.runtimeType.toString()); | |
| 61 Expect.equals("(dynamic) => dynamic", g.runtimeType.toString()); | |
| 62 } | |
| OLD | NEW |