| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Dart test program for testing throw expressions. | 7 // Dart test program for testing throw expressions. |
| 8 | 8 |
| 9 void test1() { | 9 void test1() { |
| 10 var x = 6; | 10 var x = 6; |
| 11 try { | 11 try { |
| 12 throw x = 10; | 12 throw x = 10; |
| 13 x = 0; | 13 x = 0; |
| 14 } catch(e) { | 14 } catch (e) { |
| 15 Expect.equals(10, e); | 15 Expect.equals(10, e); |
| 16 Expect.equals(10, x); | 16 Expect.equals(10, x); |
| 17 x = 15; | 17 x = 15; |
| 18 } | 18 } |
| 19 Expect.equals(15, x); | 19 Expect.equals(15, x); |
| 20 x = 100; | 20 x = 100; |
| 21 try { | 21 try { |
| 22 throw x++; | 22 throw x++; |
| 23 x = 0; | 23 x = 0; |
| 24 } catch(e) { | 24 } catch (e) { |
| 25 Expect.equals(100, e); | 25 Expect.equals(100, e); |
| 26 Expect.equals(101, x); | 26 Expect.equals(101, x); |
| 27 x = 150; | 27 x = 150; |
| 28 } | 28 } |
| 29 Expect.equals(150, x); | 29 Expect.equals(150, x); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void test2() { | 32 void test2() { |
| 33 var x = 6; | 33 var x = 6; |
| 34 try { | 34 try { |
| 35 throw x + 4; | 35 throw x + 4; |
| 36 } catch(e) { | 36 } catch (e) { |
| 37 Expect.equals(10, e); | 37 Expect.equals(10, e); |
| 38 Expect.equals(6, x); | 38 Expect.equals(6, x); |
| 39 x = 15; | 39 x = 15; |
| 40 } | 40 } |
| 41 Expect.equals(15, x); | 41 Expect.equals(15, x); |
| 42 } | 42 } |
| 43 | 43 |
| 44 foo(x, y) => throw "foo" "$x"; | 44 foo(x, y) => throw "foo" "$x"; |
| 45 | 45 |
| 46 bar(x, y) => throw "foo" "${throw x}"; | 46 bar(x, y) => throw "foo" "${throw x}"; |
| 47 | 47 |
| 48 class Q { | 48 class Q { |
| 49 var qqq; | 49 var qqq; |
| 50 f(x) { qqq = x; } | 50 f(x) { |
| 51 qqq = x; |
| 52 } |
| 53 |
| 51 Q get nono => throw "nono"; | 54 Q get nono => throw "nono"; |
| 52 } | 55 } |
| 53 | 56 |
| 54 void test3() { | 57 void test3() { |
| 55 try { | 58 try { |
| 56 throw throw throw "up"; | 59 throw throw throw "up"; |
| 57 } catch(e) { | 60 } catch (e) { |
| 58 Expect.equals("up", e); | 61 Expect.equals("up", e); |
| 59 } | 62 } |
| 60 | 63 |
| 61 var x = 10; | 64 var x = 10; |
| 62 try { | 65 try { |
| 63 foo(x = 12, throw 7); | 66 foo(x = 12, throw 7); |
| 64 } catch(e) { | 67 } catch (e) { |
| 65 Expect.equals(7, e); | 68 Expect.equals(7, e); |
| 66 Expect.equals(12, x); | 69 Expect.equals(12, x); |
| 67 } | 70 } |
| 68 | 71 |
| 69 x = 10; | 72 x = 10; |
| 70 try { | 73 try { |
| 71 foo(x++, 10); | 74 foo(x++, 10); |
| 72 } catch(e) { | 75 } catch (e) { |
| 73 Expect.equals("foo10", e); | 76 Expect.equals("foo10", e); |
| 74 Expect.equals(11, x); | 77 Expect.equals(11, x); |
| 75 } | 78 } |
| 76 | 79 |
| 77 x = 100; | 80 x = 100; |
| 78 try { | 81 try { |
| 79 bar(++x, 10); | 82 bar(++x, 10); |
| 80 } catch(e) { | 83 } catch (e) { |
| 81 Expect.equals(101, e); | 84 Expect.equals(101, e); |
| 82 Expect.equals(101, x); | 85 Expect.equals(101, x); |
| 83 } | 86 } |
| 84 | 87 |
| 85 x = null; | 88 x = null; |
| 86 try { | 89 try { |
| 87 x = new Q(); | 90 x = new Q(); |
| 88 x..f(11) ..qqq = throw 77 ..f(22); | 91 x |
| 89 } catch(e) { | 92 ..f(11) |
| 93 ..qqq = throw 77 |
| 94 ..f(22); |
| 95 } catch (e) { |
| 90 Expect.equals(77, e); | 96 Expect.equals(77, e); |
| 91 Expect.equals(11, x.qqq); | 97 Expect.equals(11, x.qqq); |
| 92 } | 98 } |
| 93 } | 99 } |
| 94 | 100 |
| 95 void test4() { | 101 void test4() { |
| 96 var q = new Q(); | 102 var q = new Q(); |
| 97 Expect.throws(() => q.nono, (e) => e == "nono"); | 103 Expect.throws(() => q.nono, (e) => e == "nono"); |
| 98 } | 104 } |
| 99 | 105 |
| 100 main() { | 106 main() { |
| 101 test1(); | 107 test1(); |
| 102 test2(); | 108 test2(); |
| 103 test3(); | 109 test3(); |
| 104 test4(); | 110 test4(); |
| 105 } | 111 } |
| OLD | NEW |