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