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 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 class BoolTest { | 7 class BoolTest { |
8 static void testEquality() { | 8 static void testEquality() { |
9 Expect.equals(true, true); | 9 Expect.equals(true, true); |
10 Expect.equals(false, false); | 10 Expect.equals(false, false); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 } | 46 } |
47 if (false == true) { | 47 if (false == true) { |
48 throw "Expect.equals broken"; | 48 throw "Expect.equals broken"; |
49 } | 49 } |
50 if (identical(true, false)) { | 50 if (identical(true, false)) { |
51 throw "Expect.equals broken"; | 51 throw "Expect.equals broken"; |
52 } | 52 } |
53 if (identical(false, true)) { | 53 if (identical(false, true)) { |
54 throw "Expect.equals broken"; | 54 throw "Expect.equals broken"; |
55 } | 55 } |
56 if (true == true) { | 56 if (true == true) {} else { |
57 } else { | |
58 throw "Expect.equals broken"; | 57 throw "Expect.equals broken"; |
59 } | 58 } |
60 if (false == false) { | 59 if (false == false) {} else { |
61 } else { | |
62 throw "Expect.equals broken"; | 60 throw "Expect.equals broken"; |
63 } | 61 } |
64 if (identical(true, true)) { | 62 if (identical(true, true)) {} else { |
65 } else { | |
66 throw "Expect.equals broken"; | 63 throw "Expect.equals broken"; |
67 } | 64 } |
68 if (identical(false, false)) { | 65 if (identical(false, false)) {} else { |
69 } else { | |
70 throw "Expect.equals broken"; | 66 throw "Expect.equals broken"; |
71 } | 67 } |
72 if (true != false) { | 68 if (true != false) {} else { |
73 } else { | |
74 throw "Expect.equals broken"; | 69 throw "Expect.equals broken"; |
75 } | 70 } |
76 if (false != true) { | 71 if (false != true) {} else { |
77 } else { | |
78 throw "Expect.equals broken"; | 72 throw "Expect.equals broken"; |
79 } | 73 } |
80 if (!identical(true, false)) { | 74 if (!identical(true, false)) {} else { |
81 } else { | |
82 throw "Expect.equals broken"; | 75 throw "Expect.equals broken"; |
83 } | 76 } |
84 if (!identical(false, true)) { | 77 if (!identical(false, true)) {} else { |
85 } else { | |
86 throw "Expect.equals broken"; | 78 throw "Expect.equals broken"; |
87 } | 79 } |
88 if (true != true) { | 80 if (true != true) { |
89 throw "Expect.equals broken"; | 81 throw "Expect.equals broken"; |
90 } | 82 } |
91 if (false != false) { | 83 if (false != false) { |
92 throw "Expect.equals broken"; | 84 throw "Expect.equals broken"; |
93 } | 85 } |
94 if (!identical(true, true)) { | 86 if (!identical(true, true)) { |
95 throw "Expect.equals broken"; | 87 throw "Expect.equals broken"; |
(...skipping 16 matching lines...) Expand all Loading... |
112 } | 104 } |
113 | 105 |
114 static void testLogicalOp() { | 106 static void testLogicalOp() { |
115 testOr(a, b, onTypeError) { | 107 testOr(a, b, onTypeError) { |
116 try { | 108 try { |
117 return a || b; | 109 return a || b; |
118 } on TypeError catch (t) { | 110 } on TypeError catch (t) { |
119 return onTypeError; | 111 return onTypeError; |
120 } | 112 } |
121 } | 113 } |
| 114 |
122 testAnd(a, b, onTypeError) { | 115 testAnd(a, b, onTypeError) { |
123 try { | 116 try { |
124 return a && b; | 117 return a && b; |
125 } on TypeError catch (t) { | 118 } on TypeError catch (t) { |
126 return onTypeError; | 119 return onTypeError; |
127 } | 120 } |
128 } | 121 } |
129 | 122 |
130 var isTrue = true; | 123 var isTrue = true; |
131 var isFalse = false; | 124 var isFalse = false; |
132 Expect.equals(true, testAnd(isTrue, isTrue, false)); | 125 Expect.equals(true, testAnd(isTrue, isTrue, false)); |
133 Expect.equals(false, testAnd(isTrue, 0, false)); | 126 Expect.equals(false, testAnd(isTrue, 0, false)); |
134 Expect.equals(false, testAnd(isTrue, 1, false)); | 127 Expect.equals(false, testAnd(isTrue, 1, false)); |
135 Expect.equals(false, testAnd(isTrue, "true", false)); | 128 Expect.equals(false, testAnd(isTrue, "true", false)); |
136 Expect.equals(false, testAnd(0, isTrue, false)); | 129 Expect.equals(false, testAnd(0, isTrue, false)); |
137 Expect.equals(false, testAnd(1, isTrue, false)); | 130 Expect.equals(false, testAnd(1, isTrue, false)); |
138 | 131 |
139 Expect.equals(true, testOr(isTrue, isTrue, false)); | 132 Expect.equals(true, testOr(isTrue, isTrue, false)); |
140 Expect.equals(true, testOr(isFalse, isTrue, false)); | 133 Expect.equals(true, testOr(isFalse, isTrue, false)); |
141 Expect.equals(true, testOr(isTrue, isFalse, false)); | 134 Expect.equals(true, testOr(isTrue, isFalse, false)); |
142 Expect.equals(true, testOr(isTrue, 0, true)); | 135 Expect.equals(true, testOr(isTrue, 0, true)); |
143 Expect.equals(true, testOr(isTrue, 1, true)); | 136 Expect.equals(true, testOr(isTrue, 1, true)); |
144 Expect.equals(false, testOr(isFalse, 0, false)); | 137 Expect.equals(false, testOr(isFalse, 0, false)); |
145 Expect.equals(false, testOr(isFalse, 1, false)); | 138 Expect.equals(false, testOr(isFalse, 1, false)); |
146 Expect.equals(true, testOr(0, isTrue, true)); | 139 Expect.equals(true, testOr(0, isTrue, true)); |
147 Expect.equals(true, testOr(1, isTrue, true)); | 140 Expect.equals(true, testOr(1, isTrue, true)); |
148 Expect.equals(false, testOr(0, isFalse, false)); | 141 Expect.equals(false, testOr(0, isFalse, false)); |
149 Expect.equals(false, testOr(1, isFalse, false)); | 142 Expect.equals(false, testOr(1, isFalse, false)); |
150 | 143 |
151 // Test side effects. | 144 // Test side effects. |
152 int trueCount = 0, falseCount = 0; | 145 int trueCount = 0, falseCount = 0; |
153 | 146 |
154 trueFunc() { | 147 trueFunc() { |
155 trueCount++; | 148 trueCount++; |
156 return true; | 149 return true; |
157 } | 150 } |
158 | 151 |
159 falseFunc() { | 152 falseFunc() { |
160 falseCount++; | 153 falseCount++; |
161 return false; | 154 return false; |
162 } | 155 } |
163 | 156 |
164 Expect.equals(0, trueCount); | 157 Expect.equals(0, trueCount); |
165 Expect.equals(0, falseCount); | 158 Expect.equals(0, falseCount); |
166 | 159 |
167 trueFunc() && trueFunc(); | 160 trueFunc() && trueFunc(); |
168 Expect.equals(2, trueCount); | 161 Expect.equals(2, trueCount); |
169 Expect.equals(0, falseCount); | 162 Expect.equals(0, falseCount); |
170 | 163 |
171 trueCount = falseCount = 0; | 164 trueCount = falseCount = 0; |
172 falseFunc() && trueFunc(); | 165 falseFunc() && trueFunc(); |
173 Expect.equals(0, trueCount); | 166 Expect.equals(0, trueCount); |
174 Expect.equals(1, falseCount); | 167 Expect.equals(1, falseCount); |
175 | 168 |
176 trueCount = falseCount = 0; | 169 trueCount = falseCount = 0; |
177 trueFunc() && falseFunc(); | 170 trueFunc() && falseFunc(); |
178 Expect.equals(1, trueCount); | 171 Expect.equals(1, trueCount); |
179 Expect.equals(1, falseCount); | 172 Expect.equals(1, falseCount); |
180 | 173 |
181 trueCount = falseCount = 0; | 174 trueCount = falseCount = 0; |
182 falseFunc() && falseFunc(); | 175 falseFunc() && falseFunc(); |
183 Expect.equals(0, trueCount); | 176 Expect.equals(0, trueCount); |
184 Expect.equals(1, falseCount); | 177 Expect.equals(1, falseCount); |
185 | 178 |
186 trueCount = falseCount = 0; | 179 trueCount = falseCount = 0; |
187 trueFunc() || trueFunc(); | 180 trueFunc() || trueFunc(); |
188 Expect.equals(1, trueCount); | 181 Expect.equals(1, trueCount); |
189 Expect.equals(0, falseCount); | 182 Expect.equals(0, falseCount); |
190 | 183 |
191 trueCount = falseCount = 0; | 184 trueCount = falseCount = 0; |
192 falseFunc() || trueFunc(); | 185 falseFunc() || trueFunc(); |
193 Expect.equals(1, trueCount); | 186 Expect.equals(1, trueCount); |
194 Expect.equals(1, falseCount); | 187 Expect.equals(1, falseCount); |
195 | 188 |
196 trueCount = falseCount = 0; | 189 trueCount = falseCount = 0; |
197 trueFunc() || falseFunc(); | 190 trueFunc() || falseFunc(); |
198 Expect.equals(1, trueCount); | 191 Expect.equals(1, trueCount); |
199 Expect.equals(0, falseCount); | 192 Expect.equals(0, falseCount); |
200 | 193 |
201 trueCount = falseCount = 0; | 194 trueCount = falseCount = 0; |
202 falseFunc() || falseFunc(); | 195 falseFunc() || falseFunc(); |
203 Expect.equals(0, trueCount); | 196 Expect.equals(0, trueCount); |
204 Expect.equals(2, falseCount); | 197 Expect.equals(2, falseCount); |
205 } | 198 } |
206 | |
207 | 199 |
208 static void testMain() { | 200 static void testMain() { |
209 testEquality(); | 201 testEquality(); |
210 testNegate(true, false); | 202 testNegate(true, false); |
211 testToString(); | 203 testToString(); |
212 testLogicalOp(); | 204 testLogicalOp(); |
213 } | 205 } |
214 } | 206 } |
215 | 207 |
216 main() { | 208 main() { |
217 BoolTest.testMain(); | 209 BoolTest.testMain(); |
218 } | 210 } |
OLD | NEW |