Chromium Code Reviews| 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 file. | |
| 4 | |
| 5 // In strong mode, `FutureOr` should be equivalent to the union of `Future<T>` | |
| 6 // and `T`. | |
| 7 | |
| 8 import 'dart:async'; | |
| 9 import 'package:expect/expect.dart'; | |
| 10 | |
| 11 void foo(FutureOr x) {} // Equivalent to `void bar(Object x) {}`. | |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:29
So this is a strong-mode only test?
floitsch
2016/12/08 18:41:55
Yes. As hinted by the name and the description on
| |
| 12 FutureOr bar() => 499; // Equivalent to `Object foo() => null`. | |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:29
=> 499?
floitsch
2016/12/08 18:41:55
Done.
| |
| 13 | |
| 14 void foo2(FutureOr<String> x) {} | |
| 15 FutureOr<int> bar2() => 499; | |
| 16 | |
| 17 void foo3(String x) {} | |
| 18 int bar3() => 499; | |
| 19 | |
| 20 typedef void FunTakes<T>(T x); | |
| 21 typedef T FunReturns<T>(); | |
| 22 | |
| 23 main() { | |
| 24 Expect.isTrue(499 is FutureOr); // Same as `is Object`. | |
| 25 Expect.isTrue(499 is FutureOr<int>); | |
| 26 Expect.isFalse(499 is FutureOr<String>); | |
| 27 | |
| 28 Expect.isTrue(new Future.value(499) is FutureOr); // Same as `is Object`. | |
| 29 Expect.isTrue(new Future.value(499) is FutureOr<int>); | |
| 30 Expect.isFalse(new Future.value(499) is FutureOr<String>); | |
| 31 | |
| 32 // A function that takes Object takes everything. | |
| 33 Expect.isTrue(foo is FunTakes<dynamic>); | |
| 34 Expect.isTrue(foo is FunTakes<Object>); | |
| 35 Expect.isTrue(foo is FunTakes<int>); | |
| 36 Expect.isTrue(foo is FunTakes<String>); | |
| 37 Expect.isTrue(foo is FunTakes<Future<int>>); | |
| 38 Expect.isTrue(foo is FunTakes<Future<String>>); | |
| 39 Expect.isTrue(foo is FunTakes<FutureOr<Object>>); | |
| 40 Expect.isTrue(foo is FunTakes<FutureOr<int>>); | |
| 41 Expect.isTrue(foo is FunTakes<FutureOr<String>>); | |
| 42 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<Object>>>); | |
| 43 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<int>>>); | |
| 44 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<String>>>); | |
| 45 | |
| 46 // Is check treats `dynamic` special in function types. | |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:29
special -> specially
Sentence is hard to read. Als
floitsch
2016/12/08 18:41:55
Done.
| |
| 47 Expect.isTrue(bar is FunReturns<dynamic>); | |
| 48 | |
| 49 Expect.isTrue(bar is FunReturns<Object>); | |
| 50 Expect.isFalse(bar is FunReturns<int>); | |
| 51 Expect.isFalse(bar is FunReturns<String>); | |
| 52 Expect.isFalse(bar is FunReturns<Future<int>>); | |
| 53 Expect.isFalse(bar is FunReturns<Future<String>>); | |
| 54 Expect.isTrue(bar is FunReturns<FutureOr<Object>>); | |
| 55 Expect.isFalse(bar is FunReturns<FutureOr<int>>); | |
| 56 Expect.isFalse(bar is FunReturns<FutureOr<String>>); | |
| 57 Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<Object>>>); | |
| 58 Expect.isFalse(bar is FunReturns<FutureOr<FutureOr<int>>>); | |
| 59 Expect.isFalse(bar is FunReturns<FutureOr<FutureOr<String>>>); | |
| 60 | |
| 61 // Is check treats `dynamic` special in function types. | |
| 62 Expect.isTrue(foo2 is FunTakes<dynamic>); | |
| 63 | |
| 64 Expect.isTrue(foo2 is FunTakes<Object>); | |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:29
isFalse. foo2 takes String or Future<String>, but
floitsch
2016/12/08 18:41:55
Done.
| |
| 65 Expect.isFalse(foo2 is FunTakes<int>); | |
| 66 Expect.isTrue(foo2 is FunTakes<String>); | |
| 67 Expect.isFalse(foo2 is FunTakes<Future<int>>); | |
| 68 Expect.isTrue(foo2 is FunTakes<Future<String>>); | |
| 69 Expect.isFalse(foo2 is FunTakes<FutureOr<Object>>); | |
| 70 Expect.isFalse(foo2 is FunTakes<FutureOr<int>>); | |
| 71 Expect.isTrue(foo2 is FunTakes<FutureOr<String>>); | |
| 72 Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<Object>>>); | |
| 73 Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<int>>>); | |
| 74 Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<String>>>); | |
| 75 | |
| 76 // Is check treats `dynamic` special in function types. | |
| 77 Expect.isTrue(bar2 is FunReturns<dynamic>); | |
| 78 | |
| 79 Expect.isTrue(bar2 is FunReturns<Object>); | |
| 80 Expect.isFalse(bar2 is FunReturns<int>); | |
| 81 Expect.isFalse(bar2 is FunReturns<String>); | |
| 82 Expect.isFalse(bar2 is FunReturns<Future<int>>); | |
| 83 Expect.isFalse(bar2 is FunReturns<Future<String>>); | |
| 84 Expect.isTrue(bar2 is FunReturns<FutureOr<Object>>); | |
| 85 Expect.isTrue(bar2 is FunReturns<FutureOr<int>>); | |
| 86 Expect.isFalse(bar2 is FunReturns<FutureOr<String>>); | |
| 87 Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<Object>>>); | |
| 88 Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<int>>>); | |
| 89 Expect.isFalse(bar2 is FunReturns<FutureOr<FutureOr<String>>>); | |
| 90 | |
| 91 // Is check treats `dynamic` special in function types. | |
| 92 Expect.isTrue(foo3 is FunTakes<dynamic>); | |
| 93 | |
| 94 Expect.isFalse(foo3 is FunTakes<Object>); | |
| 95 Expect.isFalse(foo3 is FunTakes<int>); | |
| 96 Expect.isTrue(foo3 is FunTakes<String>); | |
| 97 Expect.isFalse(foo3 is FunTakes<Future<int>>); | |
| 98 Expect.isFalse(foo3 is FunTakes<Future<String>>); | |
| 99 Expect.isFalse(foo3 is FunTakes<FutureOr<Object>>); | |
| 100 Expect.isFalse(foo3 is FunTakes<FutureOr<int>>); | |
| 101 Expect.isFalse(foo3 is FunTakes<FutureOr<String>>); | |
| 102 Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<Object>>>); | |
| 103 Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<int>>>); | |
| 104 Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<String>>>); | |
| 105 | |
| 106 // Is check treats `dynamic` special in function types. | |
| 107 Expect.isTrue(bar3 is FunReturns<dynamic>); | |
| 108 | |
| 109 Expect.isTrue(bar3 is FunReturns<Object>); | |
| 110 Expect.isTrue(bar3 is FunReturns<int>); | |
| 111 Expect.isFalse(bar3 is FunReturns<String>); | |
| 112 Expect.isFalse(bar3 is FunReturns<Future<int>>); | |
| 113 Expect.isFalse(bar3 is FunReturns<Future<String>>); | |
| 114 Expect.isTrue(bar3 is FunReturns<FutureOr<Object>>); | |
| 115 Expect.isTrue(bar3 is FunReturns<FutureOr<int>>); | |
| 116 Expect.isFalse(bar3 is FunReturns<FutureOr<String>>); | |
| 117 Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<Object>>>); | |
| 118 Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<int>>>); | |
| 119 Expect.isFalse(bar3 is FunReturns<FutureOr<FutureOr<String>>>); | |
| 120 } | |
| OLD | NEW |