OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | 4 |
5 library async_await_test; | 5 library async_await_test; |
6 | 6 |
7 import "package:unittest/unittest.dart"; | 7 import "package:unittest/unittest.dart"; |
8 import "dart:async"; | 8 import "dart:async"; |
9 | 9 |
10 main() { | 10 main() { |
(...skipping 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 | 1529 |
1530 test("sync in async", () { | 1530 test("sync in async", () { |
1531 return expect42(syncInAsync(f42)); | 1531 return expect42(syncInAsync(f42)); |
1532 }); | 1532 }); |
1533 | 1533 |
1534 test("async in sync", () { | 1534 test("async in sync", () { |
1535 return expect42(asyncInSync(f42)); | 1535 return expect42(asyncInSync(f42)); |
1536 }); | 1536 }); |
1537 | 1537 |
1538 // Equality and identity. | 1538 // Equality and identity. |
1539 test("Identical and equals", () { | 1539 // TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/265 |
| 1540 skip_test("Identical and equals", () { |
1540 expect(async.instanceMethod, equals(async.instanceMethod)); | 1541 expect(async.instanceMethod, equals(async.instanceMethod)); |
1541 expect(Async.staticMethod, same(Async.staticMethod)); | 1542 expect(Async.staticMethod, same(Async.staticMethod)); |
1542 expect(topMethod, same(topMethod)); | 1543 expect(topMethod, same(topMethod)); |
1543 }, skip: 'https://github.com/dart-lang/dev_compiler/issues/265'); | 1544 }); |
1544 }); | 1545 }); |
1545 | 1546 |
1546 group("await expression", () { | 1547 group("await expression", () { |
1547 const c42 = 42; | 1548 const c42 = 42; |
1548 final v42 = 42; | 1549 final v42 = 42; |
1549 | 1550 |
1550 test("local variable", () { | 1551 test("local variable", () { |
1551 var l42 = 42; | 1552 var l42 = 42; |
1552 f() async { | 1553 f() async { |
1553 return await l42; | 1554 return await l42; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 }); | 1617 }); |
1617 | 1618 |
1618 test("unary pre-increment operator", () { | 1619 test("unary pre-increment operator", () { |
1619 f() async { | 1620 f() async { |
1620 var x = 41; | 1621 var x = 41; |
1621 return await ++x; | 1622 return await ++x; |
1622 } | 1623 } |
1623 return expect42(f()); | 1624 return expect42(f()); |
1624 }); | 1625 }); |
1625 | 1626 |
1626 test("suffix operator + pre-increment", () { | 1627 // TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/265 |
| 1628 skip_test("suffix operator + pre-increment", () { |
1627 f() async { | 1629 f() async { |
1628 var v = [41]; | 1630 var v = [41]; |
1629 return await ++v[0]; | 1631 return await ++v[0]; |
1630 } | 1632 } |
1631 return expect42(f()); | 1633 return expect42(f()); |
1632 }, skip: 'https://github.com/dart-lang/dev_compiler/issues/267'); | 1634 }); |
1633 | 1635 |
1634 test("assignment operator", () { | 1636 test("assignment operator", () { |
1635 f() async { | 1637 f() async { |
1636 var x = 37; | 1638 var x = 37; |
1637 return await (x = 42); | 1639 return await (x = 42); |
1638 } | 1640 } |
1639 return expect42(f()); | 1641 return expect42(f()); |
1640 }); | 1642 }); |
1641 | 1643 |
1642 test("assignment-op operator", () { | 1644 test("assignment-op operator", () { |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 } | 1958 } |
1957 return await inner(f); | 1959 return await inner(f); |
1958 } | 1960 } |
1959 | 1961 |
1960 /** | 1962 /** |
1961 * A non-standard implementation of Future with a value. | 1963 * A non-standard implementation of Future with a value. |
1962 */ | 1964 */ |
1963 class FakeValueFuture implements Future { | 1965 class FakeValueFuture implements Future { |
1964 final _value; | 1966 final _value; |
1965 FakeValueFuture(this._value); | 1967 FakeValueFuture(this._value); |
1966 Future/*<S>*/ then/*<S>*/(/*=S*/ callback(value), {Function onError}) { | 1968 Future/*<S>*/ then/*<S>*/(callback(value), {Function onError}) { |
1967 return new Future<dynamic /*=S*/>.microtask(() => callback(_value)); | 1969 return new Future/*<S>*/.microtask(() => callback(_value)); |
1968 } | 1970 } |
1969 Future whenComplete(callback()) { | 1971 Future whenComplete(callback()) { |
1970 return new Future.microtask(() { callback(); }); | 1972 return new Future.microtask(() { callback(); }); |
1971 } | 1973 } |
1972 Future catchError(Function onError, {bool test(error)}) => this; | 1974 Future catchError(Function onError, {bool test(error)}) => this; |
1973 Stream asStream() => (new StreamController()..add(_value)..close()).stream; | 1975 Stream asStream() => (new StreamController()..add(_value)..close()).stream; |
1974 Future timeout(Duration duration, {onTimeout()}) => this; | 1976 Future timeout(Duration duration, {onTimeout()}) => this; |
1975 } | 1977 } |
1976 | 1978 |
1977 typedef BinaryFunction(a, b); | 1979 typedef BinaryFunction(a, b); |
1978 | 1980 |
1979 /** | 1981 /** |
1980 * A non-standard implementation of Future with an error. | 1982 * A non-standard implementation of Future with an error. |
1981 */ | 1983 */ |
1982 class FakeErrorFuture implements Future { | 1984 class FakeErrorFuture implements Future { |
1983 final _error; | 1985 final _error; |
1984 FakeErrorFuture(this._error); | 1986 FakeErrorFuture(this._error); |
1985 Future/*<S>*/ then/*<S>*/(/*=S*/ callback(value), {Function onError}) { | 1987 Future/*<S>*/ then/*<S>*/(callback(value), {Function onError}) { |
1986 if (onError != null) { | 1988 if (onError != null) { |
1987 if (onError is BinaryFunction) { | 1989 if (onError is BinaryFunction) { |
1988 return new Future/*<S>*/.microtask(() => onError(_error, null)); | 1990 return new Future/*<S>*/.microtask(() => onError(_error, null)); |
1989 } | 1991 } |
1990 return new Future/*<S>*/.microtask(() => onError(_error)); | 1992 return new Future/*<S>*/.microtask(() => onError(_error)); |
1991 } | 1993 } |
1992 return new Future/*<S>*/.error(_error); | 1994 return new Future/*<S>*/.error(_error); |
1993 } | 1995 } |
1994 Future whenComplete(callback()) { | 1996 Future whenComplete(callback()) { |
1995 return new Future.microtask(() { callback(); }).then((_) => this); | 1997 return new Future.microtask(() { callback(); }).then((_) => this); |
1996 } | 1998 } |
1997 Future catchError(Function onError, {bool test(error)}) { | 1999 Future catchError(Function onError, {bool test(error)}) { |
1998 return new Future.microtask(() { | 2000 return new Future.microtask(() { |
1999 if (test != null && !test(_error)) return this; | 2001 if (test != null && !test(_error)) return this; |
2000 if (onError is BinaryFunction) { | 2002 if (onError is BinaryFunction) { |
2001 return onError(_error, null); | 2003 return onError(_error, null); |
2002 } | 2004 } |
2003 return onError(_error); | 2005 return onError(_error); |
2004 }); | 2006 }); |
2005 } | 2007 } |
2006 Stream asStream() => | 2008 Stream asStream() => |
2007 (new StreamController()..addError(_error)..close()).stream; | 2009 (new StreamController()..addError(_error)..close()).stream; |
2008 Future timeout(Duration duration, {onTimeout()}) => this; | 2010 Future timeout(Duration duration, {onTimeout()}) => this; |
2009 } | 2011 } |
OLD | NEW |