Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tests/language_strong/bool_test.dart

Issue 2985243002: Migrate block 44. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
5 import "package:expect/expect.dart";
6
7 class BoolTest {
8 static void testEquality() {
9 Expect.equals(true, true);
10 Expect.equals(false, false);
11 Expect.isTrue(identical(true, true));
12 Expect.isFalse(identical(true, false));
13 Expect.isTrue(identical(false, false));
14 Expect.isFalse(identical(false, true));
15 Expect.isFalse(!identical(true, true));
16 Expect.isTrue(!identical(true, false));
17 Expect.isFalse(!identical(false, false));
18 Expect.isTrue(!identical(false, true));
19 Expect.isTrue(true == true);
20 Expect.isFalse(true == false);
21 Expect.isTrue(false == false);
22 Expect.isFalse(false == true);
23 Expect.isFalse(true != true);
24 Expect.isTrue(true != false);
25 Expect.isFalse(false != false);
26 Expect.isTrue(false != true);
27 Expect.isTrue(identical(true, (true == true)));
28 Expect.isTrue(identical(false, (true == false)));
29 Expect.isTrue(identical(true, (false == false)));
30 Expect.isTrue(identical(false, (false == true)));
31 Expect.isFalse(!identical(true, (true == true)));
32 Expect.isFalse(!identical(false, (true == false)));
33 Expect.isFalse(!identical(true, (false == false)));
34 Expect.isFalse(!identical(false, (false == true)));
35 Expect.isFalse(identical(false, (true == true)));
36 Expect.isFalse(identical(true, (true == false)));
37 Expect.isFalse(identical(false, (false == false)));
38 Expect.isFalse(identical(true, (false == true)));
39 Expect.isTrue(!identical(false, (true == true)));
40 Expect.isTrue(!identical(true, (true == false)));
41 Expect.isTrue(!identical(false, (false == false)));
42 Expect.isTrue(!identical(true, (false == true)));
43 // Expect.equals could rely on a broken boolean equality.
44 if (true == false) {
45 throw "Expect.equals broken";
46 }
47 if (false == true) {
48 throw "Expect.equals broken";
49 }
50 if (identical(true, false)) {
51 throw "Expect.equals broken";
52 }
53 if (identical(false, true)) {
54 throw "Expect.equals broken";
55 }
56 if (true == true) {} else {
57 throw "Expect.equals broken";
58 }
59 if (false == false) {} else {
60 throw "Expect.equals broken";
61 }
62 if (identical(true, true)) {} else {
63 throw "Expect.equals broken";
64 }
65 if (identical(false, false)) {} else {
66 throw "Expect.equals broken";
67 }
68 if (true != false) {} else {
69 throw "Expect.equals broken";
70 }
71 if (false != true) {} else {
72 throw "Expect.equals broken";
73 }
74 if (!identical(true, false)) {} else {
75 throw "Expect.equals broken";
76 }
77 if (!identical(false, true)) {} else {
78 throw "Expect.equals broken";
79 }
80 if (true != true) {
81 throw "Expect.equals broken";
82 }
83 if (false != false) {
84 throw "Expect.equals broken";
85 }
86 if (!identical(true, true)) {
87 throw "Expect.equals broken";
88 }
89 if (!identical(false, false)) {
90 throw "Expect.equals broken";
91 }
92 }
93
94 static void testToString() {
95 Expect.equals("true", true.toString());
96 Expect.equals("false", false.toString());
97 }
98
99 static void testNegate(isTrue, isFalse) {
100 Expect.equals(true, !false);
101 Expect.equals(false, !true);
102 Expect.equals(true, !isFalse);
103 Expect.equals(false, !isTrue);
104 }
105
106 static void testLogicalOp() {
107 testOr(a, b, onTypeError) {
108 try {
109 return a || b;
110 } on TypeError catch (t) {
111 return onTypeError;
112 }
113 }
114
115 testAnd(a, b, onTypeError) {
116 try {
117 return a && b;
118 } on TypeError catch (t) {
119 return onTypeError;
120 }
121 }
122
123 var isTrue = true;
124 var isFalse = false;
125 Expect.equals(true, testAnd(isTrue, isTrue, false));
126 Expect.equals(false, testAnd(isTrue, 0, false));
127 Expect.equals(false, testAnd(isTrue, 1, false));
128 Expect.equals(false, testAnd(isTrue, "true", false));
129 Expect.equals(false, testAnd(0, isTrue, false));
130 Expect.equals(false, testAnd(1, isTrue, false));
131
132 Expect.equals(true, testOr(isTrue, isTrue, false));
133 Expect.equals(true, testOr(isFalse, isTrue, false));
134 Expect.equals(true, testOr(isTrue, isFalse, false));
135 Expect.equals(true, testOr(isTrue, 0, true));
136 Expect.equals(true, testOr(isTrue, 1, true));
137 Expect.equals(false, testOr(isFalse, 0, false));
138 Expect.equals(false, testOr(isFalse, 1, false));
139 Expect.equals(true, testOr(0, isTrue, true));
140 Expect.equals(true, testOr(1, isTrue, true));
141 Expect.equals(false, testOr(0, isFalse, false));
142 Expect.equals(false, testOr(1, isFalse, false));
143
144 // Test side effects.
145 int trueCount = 0, falseCount = 0;
146
147 trueFunc() {
148 trueCount++;
149 return true;
150 }
151
152 falseFunc() {
153 falseCount++;
154 return false;
155 }
156
157 Expect.equals(0, trueCount);
158 Expect.equals(0, falseCount);
159
160 trueFunc() && trueFunc();
161 Expect.equals(2, trueCount);
162 Expect.equals(0, falseCount);
163
164 trueCount = falseCount = 0;
165 falseFunc() && trueFunc();
166 Expect.equals(0, trueCount);
167 Expect.equals(1, falseCount);
168
169 trueCount = falseCount = 0;
170 trueFunc() && falseFunc();
171 Expect.equals(1, trueCount);
172 Expect.equals(1, falseCount);
173
174 trueCount = falseCount = 0;
175 falseFunc() && falseFunc();
176 Expect.equals(0, trueCount);
177 Expect.equals(1, falseCount);
178
179 trueCount = falseCount = 0;
180 trueFunc() || trueFunc();
181 Expect.equals(1, trueCount);
182 Expect.equals(0, falseCount);
183
184 trueCount = falseCount = 0;
185 falseFunc() || trueFunc();
186 Expect.equals(1, trueCount);
187 Expect.equals(1, falseCount);
188
189 trueCount = falseCount = 0;
190 trueFunc() || falseFunc();
191 Expect.equals(1, trueCount);
192 Expect.equals(0, falseCount);
193
194 trueCount = falseCount = 0;
195 falseFunc() || falseFunc();
196 Expect.equals(0, trueCount);
197 Expect.equals(2, falseCount);
198 }
199
200 static void testMain() {
201 testEquality();
202 testNegate(true, false);
203 testToString();
204 testLogicalOp();
205 }
206 }
207
208 main() {
209 BoolTest.testMain();
210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698