Chromium Code Reviews| Index: tests/lib/async/future_or_strong_test.dart |
| diff --git a/tests/lib/async/future_or_strong_test.dart b/tests/lib/async/future_or_strong_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d1052d25e911f0ea03f56e85058dd7116af8906d |
| --- /dev/null |
| +++ b/tests/lib/async/future_or_strong_test.dart |
| @@ -0,0 +1,120 @@ |
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// In strong mode, `FutureOr` should be equivalent to the union of `Future<T>` |
| +// and `T`. |
| + |
| +import 'dart:async'; |
| +import 'package:expect/expect.dart'; |
| + |
| +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
|
| +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.
|
| + |
| +void foo2(FutureOr<String> x) {} |
| +FutureOr<int> bar2() => 499; |
| + |
| +void foo3(String x) {} |
| +int bar3() => 499; |
| + |
| +typedef void FunTakes<T>(T x); |
| +typedef T FunReturns<T>(); |
| + |
| +main() { |
| + Expect.isTrue(499 is FutureOr); // Same as `is Object`. |
| + Expect.isTrue(499 is FutureOr<int>); |
| + Expect.isFalse(499 is FutureOr<String>); |
| + |
| + Expect.isTrue(new Future.value(499) is FutureOr); // Same as `is Object`. |
| + Expect.isTrue(new Future.value(499) is FutureOr<int>); |
| + Expect.isFalse(new Future.value(499) is FutureOr<String>); |
| + |
| + // A function that takes Object takes everything. |
| + Expect.isTrue(foo is FunTakes<dynamic>); |
| + Expect.isTrue(foo is FunTakes<Object>); |
| + Expect.isTrue(foo is FunTakes<int>); |
| + Expect.isTrue(foo is FunTakes<String>); |
| + Expect.isTrue(foo is FunTakes<Future<int>>); |
| + Expect.isTrue(foo is FunTakes<Future<String>>); |
| + Expect.isTrue(foo is FunTakes<FutureOr<Object>>); |
| + Expect.isTrue(foo is FunTakes<FutureOr<int>>); |
| + Expect.isTrue(foo is FunTakes<FutureOr<String>>); |
| + Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<Object>>>); |
| + Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<int>>>); |
| + Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<String>>>); |
| + |
| + // 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.
|
| + Expect.isTrue(bar is FunReturns<dynamic>); |
| + |
| + Expect.isTrue(bar is FunReturns<Object>); |
| + Expect.isFalse(bar is FunReturns<int>); |
| + Expect.isFalse(bar is FunReturns<String>); |
| + Expect.isFalse(bar is FunReturns<Future<int>>); |
| + Expect.isFalse(bar is FunReturns<Future<String>>); |
| + Expect.isTrue(bar is FunReturns<FutureOr<Object>>); |
| + Expect.isFalse(bar is FunReturns<FutureOr<int>>); |
| + Expect.isFalse(bar is FunReturns<FutureOr<String>>); |
| + Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<Object>>>); |
| + Expect.isFalse(bar is FunReturns<FutureOr<FutureOr<int>>>); |
| + Expect.isFalse(bar is FunReturns<FutureOr<FutureOr<String>>>); |
| + |
| + // Is check treats `dynamic` special in function types. |
| + Expect.isTrue(foo2 is FunTakes<dynamic>); |
| + |
| + 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.
|
| + Expect.isFalse(foo2 is FunTakes<int>); |
| + Expect.isTrue(foo2 is FunTakes<String>); |
| + Expect.isFalse(foo2 is FunTakes<Future<int>>); |
| + Expect.isTrue(foo2 is FunTakes<Future<String>>); |
| + Expect.isFalse(foo2 is FunTakes<FutureOr<Object>>); |
| + Expect.isFalse(foo2 is FunTakes<FutureOr<int>>); |
| + Expect.isTrue(foo2 is FunTakes<FutureOr<String>>); |
| + Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<Object>>>); |
| + Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<int>>>); |
| + Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<String>>>); |
| + |
| + // Is check treats `dynamic` special in function types. |
| + Expect.isTrue(bar2 is FunReturns<dynamic>); |
| + |
| + Expect.isTrue(bar2 is FunReturns<Object>); |
| + Expect.isFalse(bar2 is FunReturns<int>); |
| + Expect.isFalse(bar2 is FunReturns<String>); |
| + Expect.isFalse(bar2 is FunReturns<Future<int>>); |
| + Expect.isFalse(bar2 is FunReturns<Future<String>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<Object>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<int>>); |
| + Expect.isFalse(bar2 is FunReturns<FutureOr<String>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<Object>>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<int>>>); |
| + Expect.isFalse(bar2 is FunReturns<FutureOr<FutureOr<String>>>); |
| + |
| + // Is check treats `dynamic` special in function types. |
| + Expect.isTrue(foo3 is FunTakes<dynamic>); |
| + |
| + Expect.isFalse(foo3 is FunTakes<Object>); |
| + Expect.isFalse(foo3 is FunTakes<int>); |
| + Expect.isTrue(foo3 is FunTakes<String>); |
| + Expect.isFalse(foo3 is FunTakes<Future<int>>); |
| + Expect.isFalse(foo3 is FunTakes<Future<String>>); |
| + Expect.isFalse(foo3 is FunTakes<FutureOr<Object>>); |
| + Expect.isFalse(foo3 is FunTakes<FutureOr<int>>); |
| + Expect.isFalse(foo3 is FunTakes<FutureOr<String>>); |
| + Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<Object>>>); |
| + Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<int>>>); |
| + Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<String>>>); |
| + |
| + // Is check treats `dynamic` special in function types. |
| + Expect.isTrue(bar3 is FunReturns<dynamic>); |
| + |
| + Expect.isTrue(bar3 is FunReturns<Object>); |
| + Expect.isTrue(bar3 is FunReturns<int>); |
| + Expect.isFalse(bar3 is FunReturns<String>); |
| + Expect.isFalse(bar3 is FunReturns<Future<int>>); |
| + Expect.isFalse(bar3 is FunReturns<Future<String>>); |
| + Expect.isTrue(bar3 is FunReturns<FutureOr<Object>>); |
| + Expect.isTrue(bar3 is FunReturns<FutureOr<int>>); |
| + Expect.isFalse(bar3 is FunReturns<FutureOr<String>>); |
| + Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<Object>>>); |
| + Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<int>>>); |
| + Expect.isFalse(bar3 is FunReturns<FutureOr<FutureOr<String>>>); |
| +} |