| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test for generic types. | 4 // Dart test for generic types. |
| 5 | 5 |
| 6 class GenericsTest<T,V> implements Map<int, int> { | 6 class GenericsTest<T,V> implements Map<int, int> { |
| 7 static int myFunc(bool a, bool b) { | 7 static int myFunc(bool a, bool b) { |
| 8 Expect.equals(true, a); | 8 Expect.equals(true, a); |
| 9 Expect.equals(false, b); | 9 Expect.equals(false, b); |
| 10 return 42; | 10 return 42; |
| 11 } | 11 } |
| 12 | 12 |
| 13 static void testMain() { | 13 static void testMain() { |
| 14 int a = 1; | 14 int a = 1; |
| 15 int b = 2; | 15 int b = 2; |
| 16 int c = 3; | 16 int c = 3; |
| 17 int d = 4; | 17 int d = 4; |
| 18 Expect.equals(true, a<b); | 18 Expect.equals(true, a<b); |
| 19 Expect.equals(42, myFunc(a<b, c> d)); | 19 Expect.equals(42, myFunc(a<b, c> d)); |
| 20 Map<int, int> e; | 20 Map<int, int> e; |
| 21 GenericsTest<int, GenericsTest<int, int>> f; | 21 GenericsTest<int, GenericsTest<int, int>> f; |
| 22 | 22 |
| 23 takesVoidMethod(void _(int a) { | 23 takesVoidMethod(void _(int a) { |
| 24 Expect.equals(2, a); | 24 Expect.equals(2, a); |
| 25 return 99; | |
| 26 }); | 25 }); |
| 27 | 26 |
| 28 takesGenericMapMethod(Map<int, int> _(int a) { | 27 takesGenericMapMethod(Map<int, int> _(int a) { |
| 29 Expect.equals(2, a); | 28 Expect.equals(2, a); |
| 30 return null; | 29 return null; |
| 31 }); | 30 }); |
| 32 | 31 |
| 33 takesIntMethod(int _(int a) { | 32 takesIntMethod(int _(int a) { |
| 34 Expect.equals(2, a); | 33 Expect.equals(2, a); |
| 35 return 98; | 34 return 98; |
| 36 }); | 35 }); |
| 37 | 36 |
| 38 e = new Map(); | 37 e = new Map(); |
| 39 takesMapMethod(e); | 38 takesMapMethod(e); |
| 40 Expect.equals(2, e[0]); | 39 Expect.equals(2, e[0]); |
| 41 Map h = new Map<int, int>(); | 40 Map h = new Map<int, int>(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 static void takesVoidMethod(void f(int a)) { | 43 static void takesVoidMethod(void f(int a)) { |
| 45 Expect.equals(99, f(2)); | 44 f(2); |
| 46 } | 45 } |
| 47 | 46 |
| 48 static void takesIntMethod(int f(int a)) { | 47 static void takesIntMethod(int f(int a)) { |
| 49 Expect.equals(98, f(2)); | 48 Expect.equals(98, f(2)); |
| 50 } | 49 } |
| 51 | 50 |
| 52 static void takesGenericMapMethod(Map<int, int> f(int a)) { | 51 static void takesGenericMapMethod(Map<int, int> f(int a)) { |
| 53 f(2); | 52 f(2); |
| 54 } | 53 } |
| 55 | 54 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 77 LongGeneric< | 76 LongGeneric< |
| 78 C, | 77 C, |
| 79 List<E>, | 78 List<E>, |
| 80 Map<G, LongGeneric<I, J, List<A>>>>> id2; | 79 Map<G, LongGeneric<I, J, List<A>>>>> id2; |
| 81 } | 80 } |
| 82 } | 81 } |
| 83 | 82 |
| 84 main() { | 83 main() { |
| 85 GenericsTest.testMain(); | 84 GenericsTest.testMain(); |
| 86 } | 85 } |
| OLD | NEW |