OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // VMOptions=--enable_type_checks | 4 // VMOptions=--enable_type_checks |
5 // | 5 // |
6 // Dart test program testing assert statements. | 6 // Dart test program testing assert statements. |
7 | 7 |
8 class AssertionTest { | 8 class AssertionTest { |
9 static testTrue() { | 9 static testTrue() { |
10 int i = 0; | 10 int i = 0; |
11 try { | 11 try { |
12 assert(true); | 12 assert(true); |
13 } catch (AssertionError error) { | 13 } on AssertionError catch (error) { |
14 i = 1; | 14 i = 1; |
15 } | 15 } |
16 return i; | 16 return i; |
17 } | 17 } |
18 | 18 |
19 static testFalse() { | 19 static testFalse() { |
20 int i = 0; | 20 int i = 0; |
21 try { | 21 try { |
22 assert(false); | 22 assert(false); |
23 } catch (AssertionError error) { | 23 } on AssertionError catch (error) { |
24 i = 1; | 24 i = 1; |
25 } | 25 } |
26 return i; | 26 return i; |
27 } | 27 } |
28 | 28 |
29 static unknown(var a) { | 29 static unknown(var a) { |
30 return (a) ? true : false; | 30 return (a) ? true : false; |
31 } | 31 } |
32 | 32 |
33 static testUnknown() { | 33 static testUnknown() { |
34 var x = unknown(false); | 34 var x = unknown(false); |
35 int i = 0; | 35 int i = 0; |
36 try { | 36 try { |
37 assert(x); | 37 assert(x); |
38 } catch (AssertionError error) { | 38 } on AssertionError catch (error) { |
39 i = 1; | 39 i = 1; |
40 } | 40 } |
41 return i; | 41 return i; |
42 } | 42 } |
43 | 43 |
44 static testClosure() { | 44 static testClosure() { |
45 int i = 0; | 45 int i = 0; |
46 try { | 46 try { |
47 assert(() => false); | 47 assert(() => false); |
48 } catch (AssertionError error) { | 48 } on AssertionError catch (error) { |
49 i = 1; | 49 i = 1; |
50 } | 50 } |
51 return i; | 51 return i; |
52 } | 52 } |
53 | 53 |
54 static testClosure2() { | 54 static testClosure2() { |
55 int i = 0; | 55 int i = 0; |
56 try { | 56 try { |
57 var x = () => false; | 57 var x = () => false; |
58 assert(x); | 58 assert(x); |
59 } catch (AssertionError error) { | 59 } on AssertionError catch (error) { |
60 i = 1; | 60 i = 1; |
61 } | 61 } |
62 return i; | 62 return i; |
63 } | 63 } |
64 | 64 |
65 static testMain() { | 65 static testMain() { |
66 Expect.equals(0, testTrue()); | 66 Expect.equals(0, testTrue()); |
67 Expect.equals(1, testFalse()); | 67 Expect.equals(1, testFalse()); |
68 Expect.equals(1, testClosure()); | 68 Expect.equals(1, testClosure()); |
69 Expect.equals(1, testClosure2()); | 69 Expect.equals(1, testClosure2()); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 main() { | 73 main() { |
74 AssertionTest.testMain(); | 74 AssertionTest.testMain(); |
75 } | 75 } |
OLD | NEW |