OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 |
| 5 // Dart test for type checks involving the void type. |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
| 9 typedef F = void Function(Object); |
| 10 typedef F2 = void Function([Object]); |
| 11 typedef F3 = void Function({Object x}); |
| 12 |
| 13 typedef G = void Function(void); |
| 14 typedef G2 = void Function([void]); |
| 15 typedef G3 = void Function({void x}); |
| 16 |
| 17 typedef H = int Function(void); |
| 18 typedef H2 = int Function([void]); |
| 19 typedef H3 = int Function({void x}); |
| 20 |
| 21 void f(Object x) {} |
| 22 void f2([Object x]) {} |
| 23 void f3({Object x}) {} |
| 24 |
| 25 void g(void x) {} |
| 26 void g2([void x]) {} |
| 27 void g3({void x}) {} |
| 28 |
| 29 int h(void x) => 499; |
| 30 int h2([void x]) => 499; |
| 31 int h3({void x}) => 499; |
| 32 |
| 33 void expectsF(F f) {} |
| 34 void expectsG(G g) {} |
| 35 void expectsH(H h) {} |
| 36 |
| 37 void expectsF2(F2 f) {} |
| 38 void expectsG2(G2 g) {} |
| 39 void expectsH2(H2 h) {} |
| 40 |
| 41 void expectsF3(F3 f) {} |
| 42 void expectsG3(G3 g) {} |
| 43 void expectsH3(H3 h) {} |
| 44 |
| 45 void throwsInChecked(f) { |
| 46 bool checkedMode = false; |
| 47 assert((checkedMode = true)); |
| 48 |
| 49 bool caughtError = false; |
| 50 try { |
| 51 f(); |
| 52 } catch(e) { |
| 53 caughtError = true; |
| 54 } |
| 55 Expect.equals(checkedMode, caughtError); |
| 56 } |
| 57 |
| 58 main() { |
| 59 Expect.isTrue(f is F); |
| 60 Expect.isTrue(f is G); |
| 61 Expect.isFalse(f is H); |
| 62 expectsF(f); |
| 63 expectsG(f); |
| 64 throwsInChecked(() { expectsH(f); }); /// 00: static type warning |
| 65 |
| 66 Expect.isTrue(f2 is F2); |
| 67 Expect.isTrue(f2 is G2); |
| 68 Expect.isFalse(f2 is H2); |
| 69 expectsF2(f2); |
| 70 expectsG2(f2); |
| 71 throwsInChecked(() { expectsH2(f2); }); /// 01: static type warning |
| 72 |
| 73 Expect.isTrue(f3 is F3); |
| 74 Expect.isTrue(f3 is G3); |
| 75 Expect.isFalse(f3 is H3); |
| 76 expectsF3(f3); |
| 77 expectsG3(f3); |
| 78 throwsInChecked(() { expectsH3(f3); }); /// 03: static type warning |
| 79 |
| 80 Expect.isTrue(g is F); |
| 81 Expect.isTrue(g is G); |
| 82 Expect.isFalse(g is H); |
| 83 expectsF(g); /// 04: static type warning |
| 84 expectsG(g); |
| 85 throwsInChecked(() { expectsH(g); }); /// 05: static type warning |
| 86 |
| 87 Expect.isTrue(g2 is F2); |
| 88 Expect.isTrue(g2 is G2); |
| 89 Expect.isFalse(g2 is H2); |
| 90 expectsF2(g2); /// 06: static type warning |
| 91 expectsG2(g2); |
| 92 throwsInChecked(() { expectsH2(g2); }); /// 07: static type warning |
| 93 |
| 94 Expect.isTrue(g3 is F3); |
| 95 Expect.isTrue(g3 is G3); |
| 96 Expect.isFalse(g3 is H3); |
| 97 expectsF3(g3); /// 08: static type warning |
| 98 expectsG3(g3); |
| 99 throwsInChecked(() { expectsH3(g3); }); /// 09: static type warning |
| 100 |
| 101 Expect.isTrue(h is F); |
| 102 Expect.isTrue(h is G); |
| 103 Expect.isTrue(h is H); |
| 104 expectsF(h); |
| 105 expectsG(h); |
| 106 expectsH(h); |
| 107 |
| 108 Expect.isTrue(h2 is H2); |
| 109 Expect.isTrue(h2 is G2); |
| 110 Expect.isTrue(h2 is H2); |
| 111 expectsF2(h2); |
| 112 expectsG2(h2); |
| 113 expectsH2(h2); |
| 114 |
| 115 Expect.isTrue(h3 is H3); |
| 116 Expect.isTrue(h3 is G3); |
| 117 Expect.isTrue(h3 is H3); |
| 118 expectsF3(h3); |
| 119 expectsG3(h3); |
| 120 expectsH3(h3); |
| 121 } |
OLD | NEW |