OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // Dart test program for testing throw expressions. | |
6 | |
7 void test1() { | |
8 var x = 6; | |
9 try { | |
10 throw x = 10; | |
11 x = 0; | |
12 } catch(e) { | |
13 Expect.equals(10, e); | |
14 Expect.equals(10, x); | |
15 x = 15; | |
16 } | |
17 Expect.equals(15, x); | |
18 x = 100; | |
19 try { | |
20 throw x++; | |
21 x = 0; | |
22 } catch(e) { | |
23 Expect.equals(100, e); | |
24 Expect.equals(101, x); | |
25 x = 150; | |
26 } | |
27 Expect.equals(150, x); | |
28 } | |
29 | |
30 void test2() { | |
31 var x = 6; | |
32 try { | |
33 throw x + 4; | |
34 } catch(e) { | |
35 Expect.equals(10, e); | |
36 Expect.equals(6, x); | |
37 x = 15; | |
38 } | |
39 Expect.equals(15, x); | |
40 } | |
41 | |
42 foo(x, y) => throw "foo" "$x"; | |
43 | |
44 bar(x, y) => throw "foo" "${throw x}"; | |
45 | |
46 class Q { | |
47 var qqq; | |
48 f(x) { qqq = x; } | |
49 } | |
50 | |
51 void test3() { | |
52 try { | |
53 throw throw throw "throw"; | |
54 } catch(e) { | |
55 Expect.equals("throw", e); | |
56 } | |
siva
2012/09/26 21:09:12
I think the test will read much better if you chan
| |
57 | |
58 var x = 10; | |
59 try { | |
60 foo(x = 12, throw 7); | |
61 } catch(e) { | |
62 Expect.equals(7, e); | |
63 Expect.equals(12, x); | |
64 } | |
65 | |
66 x = 10; | |
67 try { | |
68 foo(x++, 10); | |
69 } catch(e) { | |
70 Expect.equals("foo10", e); | |
71 Expect.equals(11, x); | |
72 } | |
73 | |
74 x = 100; | |
75 try { | |
76 bar(++x, 10); | |
77 } catch(e) { | |
78 Expect.equals(101, e); | |
79 Expect.equals(101, x); | |
80 } | |
81 | |
82 x = null; | |
83 try { | |
84 x = new Q(); | |
85 x..f(11) ..qqq = throw 77 ..f(22); | |
86 } catch(e) { | |
87 Expect.equals(77, e); | |
88 Expect.equals(11, x.qqq); | |
89 } | |
90 } | |
91 | |
92 main() { | |
93 test1(); | |
94 test2(); | |
95 test3(); | |
96 } | |
OLD | NEW |