| 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) => x; |
| 15 T g(T x) => x; |
| 16 } |
| 17 |
| 18 main() { |
| 19 { |
| 20 var c = new C<int>(); |
| 21 var f = c.f; |
| 22 var g = c.g; |
| 23 Expect.equals("(int) -> int", f.runtimeType.toString()); //# 01: ok |
| 24 Expect.equals("(Object) -> int", g.runtimeType.toString()); //# 01: ok |
| 25 Expect.equals(21, f(21)); |
| 26 Expect.equals(14, g(14)); |
| 27 Expect.isTrue(f is Function); |
| 28 Expect.isTrue(g is Function); |
| 29 Expect.isTrue(f is F); |
| 30 Expect.isTrue(g is F); |
| 31 Expect.isTrue(f is F<int>); |
| 32 Expect.isTrue(g is F<int>); |
| 33 Expect.isTrue(f is! F<bool>); |
| 34 Expect.isTrue(g is! F<bool>); |
| 35 Expect.isTrue(f is G<int, int>); |
| 36 Expect.isTrue(g is G<int, int>); |
| 37 Expect.isTrue(f is! G<int, bool>); |
| 38 Expect.isTrue(g is! G<int, bool>); |
| 39 Expect.isTrue(f is! G<Object,int>); |
| 40 Expect.isTrue(g is G<Object, int>); |
| 41 } |
| 42 |
| 43 { |
| 44 var c = new C<bool>(); |
| 45 var f = c.f; |
| 46 var g = c.g; |
| 47 Expect.equals("(bool) -> bool", f.runtimeType.toString()); //# 01: ok |
| 48 Expect.equals("(Object) -> bool", g.runtimeType.toString()); //# 01: ok |
| 49 Expect.isTrue(f is F); |
| 50 Expect.isTrue(g is F); |
| 51 Expect.isTrue(f is! F<int>); |
| 52 Expect.isTrue(g is! F<int>); |
| 53 Expect.isTrue(f is F<bool>); |
| 54 Expect.isTrue(g is F<bool>); |
| 55 } |
| 56 |
| 57 { |
| 58 var c = new C(); |
| 59 var f = c.f; |
| 60 var g = c.g; |
| 61 Expect.equals("(dynamic) -> dynamic", f.runtimeType.toString()); //# 01: ok |
| 62 Expect.equals("(Object) -> dynamic", g.runtimeType.toString()); //# 01: ok |
| 63 Expect.isTrue(f is F); |
| 64 Expect.isTrue(g is F); |
| 65 Expect.isTrue(f is! F<int>); |
| 66 Expect.isTrue(g is! F<int>); |
| 67 Expect.isTrue(f is! F<bool>); |
| 68 Expect.isTrue(g is! F<bool>); |
| 69 } |
| 70 } |
| OLD | NEW |