| 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 // VMOptions=--enable_type_checks | 4 // VMOptions=--enable_type_checks |
| 5 // | 5 // |
| 6 // Dart test for function type alias. | 6 // Dart test for function type alias. |
| 7 | 7 |
| 8 typedef Fun(a, b); | 8 typedef Fun(a, b); |
| 9 | 9 |
| 10 typedef int IntFun(a, b); | 10 typedef int IntFun(a, b); |
| 11 | 11 |
| 12 typedef bool BoolFun(a, b); | 12 typedef bool BoolFun(a, b); |
| 13 | 13 |
| 14 typedef int CompareObj(Object a, Object b); | 14 typedef int CompareObj(Object a, Object b); |
| 15 | 15 |
| 16 typedef int CompareInt(int a, int b); | 16 typedef int CompareInt(int a, int b); |
| 17 | 17 |
| 18 typedef int CompareString(String a, String b, [bool swap]); | 18 typedef int CompareString(String a, String b, [bool swap]); |
| 19 | 19 |
| 20 typedef void Test(); | 20 typedef void Test(); |
| 21 | 21 |
| 22 typedef ParametrizedFun1<T, U extends bool, V>(T t, U u); | 22 typedef ParametrizedFun1<T, U extends bool, V>(T t, U u); |
| 23 | 23 |
| 24 typedef List<T> ParametrizedFun2<T, U, V extends Map<T, int>>( | 24 typedef List<T> ParametrizedFun2<T, U, V extends Map<T, int>>( |
| 25 Map<T, int> t, U u); | 25 Map<T, int> t, U u); |
| 26 | 26 |
| 27 typedef void BoundsCheck<T extends num>(T arg); |
| 28 |
| 27 class FunctionTypeAliasTest { | 29 class FunctionTypeAliasTest { |
| 28 FunctionTypeAliasTest() {} | 30 FunctionTypeAliasTest() {} |
| 29 static int test(CompareObj compare, Object a, Object b) { | 31 static int test(CompareObj compare, Object a, Object b) { |
| 30 return compare(a, b); | 32 return compare(a, b); |
| 31 } | 33 } |
| 32 foo(Test test) {} | 34 foo(Test arg) {} |
| 33 static bar() { | 35 static bar() { |
| 34 FunctionTypeAliasTest a = new FunctionTypeAliasTest(); | 36 FunctionTypeAliasTest a = new FunctionTypeAliasTest(); |
| 35 a.foo(() { }); | 37 a.foo(() { }); |
| 36 return 0; | 38 return 0; |
| 37 } | 39 } |
| 38 | 40 |
| 39 static void testMain() { | 41 static void testMain() { |
| 40 int compareStrLen(String a, String b) { return a.length - b.length; } | 42 int compareStrLen(String a, String b) { return a.length - b.length; } |
| 41 Expect.isTrue(compareStrLen is Fun); | 43 Expect.isTrue(compareStrLen is Fun); |
| 42 Expect.isTrue(compareStrLen is IntFun); | 44 Expect.isTrue(compareStrLen is IntFun); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 88 |
| 87 int plus (int a, [int b = 1]) { return a + b; }; | 89 int plus (int a, [int b = 1]) { return a + b; }; |
| 88 Expect.isTrue(plus is !Fun); | 90 Expect.isTrue(plus is !Fun); |
| 89 Expect.isTrue(plus is !IntFun); | 91 Expect.isTrue(plus is !IntFun); |
| 90 Expect.isTrue(plus is !BoolFun); | 92 Expect.isTrue(plus is !BoolFun); |
| 91 Expect.isTrue(plus is !CompareObj); | 93 Expect.isTrue(plus is !CompareObj); |
| 92 Expect.isTrue(plus is !CompareInt); | 94 Expect.isTrue(plus is !CompareInt); |
| 93 Expect.isTrue(plus is !CompareString); | 95 Expect.isTrue(plus is !CompareString); |
| 94 | 96 |
| 95 Expect.equals(0, bar()); | 97 Expect.equals(0, bar()); |
| 98 |
| 99 Function boundsTrue = void _(int arg) { }; |
| 100 Function boundsFalse = void _(String arg) { }; |
| 101 Expect.isTrue(boundsTrue is BoundsCheck<num>); |
| 102 Expect.isFalse(boundsFalse is BoundsCheck<num>); |
| 96 } | 103 } |
| 97 } | 104 } |
| 98 | 105 |
| 99 main() { | 106 main() { |
| 100 FunctionTypeAliasTest.testMain(); | 107 FunctionTypeAliasTest.testMain(); |
| 101 } | 108 } |
| OLD | NEW |