| 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 // Use of package:unittest and package:test is deprecated in sdk/tests. |
| 8 // Do not add any more uses of this package. |
| 7 import "package:unittest/unittest.dart"; | 9 import "package:unittest/unittest.dart"; |
| 8 import "dart:async"; | 10 import "dart:async"; |
| 9 | 11 |
| 10 main() { | 12 main() { |
| 11 bool checkedMode = false; | 13 bool checkedMode = false; |
| 12 assert((checkedMode = true)); | 14 assert((checkedMode = true)); |
| 13 | 15 |
| 14 group("basic", () { | 16 group("basic", () { |
| 15 test("async w/o await", () { | 17 test("async w/o await", () { |
| 16 f() async { return id(42); } | 18 f() async { return id(42); } |
| (...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 test("top-level getter call", () { | 1723 test("top-level getter call", () { |
| 1722 f() async { | 1724 f() async { |
| 1723 var a = new Async(); | 1725 var a = new Async(); |
| 1724 return await a.instanceGetter; | 1726 return await a.instanceGetter; |
| 1725 } | 1727 } |
| 1726 return expect42(f()); | 1728 return expect42(f()); |
| 1727 }); | 1729 }); |
| 1728 | 1730 |
| 1729 if (!checkedMode) return; | 1731 if (!checkedMode) return; |
| 1730 | 1732 |
| 1731 test("inside assert, true", () { /// 03: ok | 1733 test("inside assert, true", () { |
| 1732 f() async { /// 03: continued | 1734 f() async { |
| 1733 assert(await new Future.microtask(() => true)); /// 03: continued | 1735 assert(await new Future.microtask(() => true)); |
| 1734 return 42; /// 03: continued | 1736 return 42; |
| 1735 } /// 03: continued | 1737 } |
| 1736 return expect42(f()); /// 03: continued | 1738 return expect42(f()); |
| 1737 }); /// 03: continued | 1739 }); |
| 1738 | 1740 |
| 1739 test("inside assert, false", () { /// 03: continued | 1741 test("inside assert, false", () { |
| 1740 f() async { /// 03: continued | 1742 f() async { |
| 1741 assert(await new Future.microtask(() => false)); /// 03: continued | 1743 assert(await new Future.microtask(() => false)); |
| 1742 return 42; /// 03: continued | 1744 return 42; |
| 1743 } /// 03: continued | 1745 } |
| 1744 return f().then((_) { /// 03: continued | 1746 return f().then((_) { |
| 1745 fail("assert didn't throw"); /// 03: continued | 1747 fail("assert didn't throw"); |
| 1746 }, onError: (e, s) { /// 03: continued | 1748 }, onError: (e, s) { |
| 1747 expect(e is AssertionError, isTrue); /// 03: continued | 1749 expect(e is AssertionError, isTrue); |
| 1748 }); /// 03: continued | 1750 }); |
| 1749 }); /// 03: continued | 1751 }); |
| 1750 | 1752 |
| 1751 test("inside assert, function -> false", () { /// 03: continued | 1753 test("inside assert, function -> false", () { |
| 1752 f() async { /// 03: continued | 1754 f() async { |
| 1753 assert(await new Future.microtask(() => false)); /// 03: continued | 1755 assert(await new Future.microtask(() => false)); |
| 1754 return 42; /// 03: continued | 1756 return 42; |
| 1755 } /// 03: continued | 1757 } |
| 1756 return f().then((_) { /// 03: continued | 1758 return f().then((_) { |
| 1757 fail("assert didn't throw"); /// 03: continued | 1759 fail("assert didn't throw"); |
| 1758 }, onError: (e, s) { /// 03: continued | 1760 }, onError: (e, s) { |
| 1759 expect(e is AssertionError, isTrue); /// 03: continued | 1761 expect(e is AssertionError, isTrue); |
| 1760 }); /// 03: continued | 1762 }); |
| 1761 }); /// 03: continued | 1763 }); |
| 1762 | 1764 |
| 1763 }); | 1765 }); |
| 1764 | 1766 |
| 1765 group("syntax", () { | 1767 group("syntax", () { |
| 1766 test("async as variable", () { | 1768 test("async as variable", () { |
| 1767 // Valid identifiers outside of async function. | 1769 // Valid identifiers outside of async function. |
| 1768 var async = 42; | 1770 var async = 42; |
| 1769 expect(async, equals(42)); | 1771 expect(async, equals(42)); |
| 1770 }); | 1772 }); |
| 1771 | 1773 |
| 1772 test("await as variable", () { /// 02: ok | 1774 test("await as variable", () { |
| 1773 // Valid identifiers outside of async function. /// 02: continued | 1775 // Valid identifiers outside of async function. |
| 1774 var await = 42; /// 02: continued | 1776 var await = 42; |
| 1775 expect(await, equals(42)); /// 02: continued | 1777 expect(await, equals(42)); |
| 1776 }); /// 02: continued | 1778 }); |
| 1777 | 1779 |
| 1778 test("yield as variable", () { | 1780 test("yield as variable", () { |
| 1779 // Valid identifiers outside of async function. | 1781 // Valid identifiers outside of async function. |
| 1780 var yield = 42; | 1782 var yield = 42; |
| 1781 expect(yield, equals(42)); | 1783 expect(yield, equals(42)); |
| 1782 }); | 1784 }); |
| 1783 }); | 1785 }); |
| 1784 } | 1786 } |
| 1785 | 1787 |
| 1786 | 1788 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1999 if (onError is BinaryFunction) { | 2001 if (onError is BinaryFunction) { |
| 2000 return onError(_error, null); | 2002 return onError(_error, null); |
| 2001 } | 2003 } |
| 2002 return onError(_error); | 2004 return onError(_error); |
| 2003 }); | 2005 }); |
| 2004 } | 2006 } |
| 2005 Stream asStream() => | 2007 Stream asStream() => |
| 2006 (new StreamController()..addError(_error)..close()).stream; | 2008 (new StreamController()..addError(_error)..close()).stream; |
| 2007 Future timeout(Duration duration, {onTimeout}) => this; | 2009 Future timeout(Duration duration, {onTimeout}) => this; |
| 2008 } | 2010 } |
| OLD | NEW |