Chromium Code Reviews| Index: tests/lib/async/future_or_non_strong_test.dart |
| diff --git a/tests/lib/async/future_or_non_strong_test.dart b/tests/lib/async/future_or_non_strong_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a5f7f92f0790e6ae0a790e6bf841759a5f8517c0 |
| --- /dev/null |
| +++ b/tests/lib/async/future_or_non_strong_test.dart |
| @@ -0,0 +1,108 @@ |
| +// 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 non strong-mode, `FutureOr` should just behave like dynamic. |
| + |
| +import 'dart:async'; |
| +import 'package:expect/expect.dart'; |
| + |
| +void foo(FutureOr x) {} |
| +FutureOr bar() => 499; |
| + |
| +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); |
| + Expect.isTrue(499 is FutureOr<String>); |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is! or Expect.isFalse?
floitsch
2016/12/08 18:41:55
not in non-strong mode.
|
| + Expect.isTrue(499 is FutureOr<int>); |
| + |
| + Expect.isTrue(new Future.value(499) is FutureOr); |
| + Expect.isTrue(new Future.value(499) is FutureOr<int>); |
| + Expect.isTrue(new Future.value(499) is FutureOr<String>); |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:28
This is spec mode, so it's a Future<dynamic> which
floitsch
2016/12/08 18:41:55
The whole test is for spec mode. This is hinted by
Lasse Reichstein Nielsen
2016/12/08 19:31:00
No, that's just me being too used to think of Futu
|
| + |
| + 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>>>); |
| + |
| + Expect.isTrue(bar is FunReturns<dynamic>); |
| + Expect.isTrue(bar is FunReturns<Object>); |
| + Expect.isTrue(bar is FunReturns<int>); |
| + Expect.isTrue(bar is FunReturns<String>); |
| + Expect.isTrue(bar is FunReturns<Future<int>>); |
| + Expect.isTrue(bar is FunReturns<Future<String>>); |
| + Expect.isTrue(bar is FunReturns<FutureOr<Object>>); |
| + Expect.isTrue(bar is FunReturns<FutureOr<int>>); |
| + Expect.isTrue(bar is FunReturns<FutureOr<String>>); |
| + Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<Object>>>); |
| + Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<int>>>); |
| + Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<String>>>); |
| + |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:28
You could move the declaration of foo2 down here s
floitsch
2016/12/08 18:41:55
Done.
|
| + Expect.isTrue(foo2 is FunTakes<dynamic>); |
| + Expect.isTrue(foo2 is FunTakes<Object>); |
| + Expect.isTrue(foo2 is FunTakes<int>); |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is!
floitsch
2016/12/08 18:41:55
Not, if `FutureOr` is equivalent to dynamic (which
|
| + Expect.isTrue(foo2 is FunTakes<String>); |
| + Expect.isTrue(foo2 is FunTakes<Future<int>>); |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is!
More below (everyone except Future<String>, F
floitsch
2016/12/08 18:41:55
Same answer.
|
| + Expect.isTrue(foo2 is FunTakes<Future<String>>); |
| + Expect.isTrue(foo2 is FunTakes<FutureOr<Object>>); |
| + Expect.isTrue(foo2 is FunTakes<FutureOr<int>>); |
| + Expect.isTrue(foo2 is FunTakes<FutureOr<String>>); |
| + Expect.isTrue(foo2 is FunTakes<FutureOr<FutureOr<Object>>>); |
| + Expect.isTrue(foo2 is FunTakes<FutureOr<FutureOr<int>>>); |
| + Expect.isTrue(foo2 is FunTakes<FutureOr<FutureOr<String>>>); |
| + |
| + Expect.isTrue(bar2 is FunReturns<dynamic>); |
| + Expect.isTrue(bar2 is FunReturns<Object>); |
| + Expect.isTrue(bar2 is FunReturns<int>); |
| + Expect.isTrue(bar2 is FunReturns<String>); |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is!
Same for Future<String>, FutureOr<String>, an
floitsch
2016/12/08 18:41:55
Same answer.
|
| + Expect.isTrue(bar2 is FunReturns<Future<int>>); |
| + Expect.isTrue(bar2 is FunReturns<Future<String>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<Object>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<int>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<String>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<Object>>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<int>>>); |
| + Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<String>>>); |
| + |
| + Expect.isTrue(foo3 is FunTakes<dynamic>); |
| + Expect.isTrue(foo3 is FunTakes<Object>); |
|
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is!
(Just figure out the rest :)
floitsch
2016/12/08 18:41:55
No. In Dart1, foo3 *is* a function that takes `Obj
|
| + 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.isTrue(foo3 is FunTakes<FutureOr<Object>>); |
| + Expect.isTrue(foo3 is FunTakes<FutureOr<int>>); |
| + Expect.isTrue(foo3 is FunTakes<FutureOr<String>>); |
| + Expect.isTrue(foo3 is FunTakes<FutureOr<FutureOr<Object>>>); |
| + Expect.isTrue(foo3 is FunTakes<FutureOr<FutureOr<int>>>); |
| + Expect.isTrue(foo3 is FunTakes<FutureOr<FutureOr<String>>>); |
| + |
| + 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.isTrue(bar3 is FunReturns<FutureOr<String>>); |
| + Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<Object>>>); |
| + Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<int>>>); |
| + Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<String>>>); |
| +} |