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 // Test program for sync* generator functions and yielding in try blocks. | 5 // Test program for sync* generator functions and yielding in try blocks. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 f() sync* { | 9 f() sync* { |
10 try { | 10 try { |
(...skipping 16 matching lines...) Expand all Loading... |
27 g() sync* { | 27 g() sync* { |
28 try { | 28 try { |
29 yield "a"; | 29 yield "a"; |
30 throw "pow!"; | 30 throw "pow!"; |
31 } finally { | 31 } finally { |
32 yield "b"; | 32 yield "b"; |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 test2() { | 36 test2() { |
37 var s; | 37 Iterator i = g().iterator; |
38 try { | 38 Expect.isTrue(i.moveNext()); |
39 s = g().toString(); | 39 Expect.equals("a", i.current); |
40 } catch (e) { | 40 Expect.isTrue(i.moveNext()); |
41 Expect.equals("pow!", e); | 41 Expect.equals("b", i.current); |
42 Expect.equals("(a, b)", s); | 42 Expect.throws(() => i.moveNext(), (error) => error == "pow!"); |
43 print(s); | |
44 } | |
45 } | 43 } |
46 | 44 |
47 main() { | 45 main() { |
48 test1(); /// test1: ok | 46 test1(); /// test1: ok |
49 test2(); /// test2: ok | 47 test2(); /// test2: ok |
50 } | 48 } |
OLD | NEW |