OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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.md file. |
| 4 |
| 5 class C { |
| 6 var f = () => "f"; |
| 7 get g => (x) => "g($x)"; |
| 8 a() => "a"; |
| 9 b(x) => x; |
| 10 c(x, [y = 2]) => x + y; |
| 11 d(x, {y: 2}) => x + y; |
| 12 } |
| 13 |
| 14 /// This class doesn't use its type variable. |
| 15 class D<T> { |
| 16 var f = () => "f"; |
| 17 get g => (x) => "g($x)"; |
| 18 a() => "a"; |
| 19 b(x) => x; |
| 20 c(x, [y = 2]) => x + y; |
| 21 d(x, {y: 2}) => x + y; |
| 22 } |
| 23 |
| 24 /// This class uses its type variable. |
| 25 class E<T> { |
| 26 var f = () => "f"; |
| 27 get g => (T x) => "g($x)"; |
| 28 a() => "a"; |
| 29 b(T x) => x; |
| 30 c(T x, [T y = 2]) => x + y; |
| 31 d(T x, {T y: 2}) => x + y; |
| 32 } |
| 33 |
| 34 expect(expected, actual) { |
| 35 print("Expecting '$expected' and got '$actual'"); |
| 36 if (expected != actual) { |
| 37 print("Expected '$expected' but got '$actual'"); |
| 38 throw "Expected '$expected' but got '$actual'"; |
| 39 } |
| 40 } |
| 41 |
| 42 test(o) { |
| 43 expect("f", o.f()); |
| 44 expect("f", (o.f)()); |
| 45 expect("g(42)", o.g(42)); |
| 46 expect("g(42)", (o.g)(42)); |
| 47 expect("a", o.a()); |
| 48 expect("a", (o.a)()); |
| 49 expect(42, o.b(42)); |
| 50 expect(42, (o.b)(42)); |
| 51 expect(42, o.c(40)); |
| 52 expect(42, (o.c)(40)); |
| 53 expect(87, o.c(80, 7)); |
| 54 expect(87, (o.c)(80, 7)); |
| 55 expect(42, o.d(40)); |
| 56 expect(42, (o.d)(40)); |
| 57 expect(87, o.d(80, y: 7)); |
| 58 expect(87, (o.d)(80, y: 7)); |
| 59 } |
| 60 |
| 61 main(arguments) { |
| 62 test(new C()); |
| 63 test(new D<int>()); |
| 64 test(new E<int>()); |
| 65 } |
OLD | NEW |