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

Side by Side Diff: pkg/dev_compiler/test/codegen/equality_test.dart

Issue 2930733002: Add codegen test for equality. (Closed)
Patch Set: Created 3 years, 6 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) 2017, 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/minitest.dart';
6
7 /// Both kinds.
8 enum Music { country, western }
9
10 class BluesBrother {}
11
12 // This class does not override object equality
13 class _Jake extends BluesBrother {}
14
15 /// This class overrides object equality
16 class _Elwood extends BluesBrother {
17 bool operator ==(Object other) {
18 return (other is _Elwood);
19 }
20 }
21
22 /// Mock BluesBrother
23 class _Norman extends BluesBrother {}
24
25 /// Hide nullability from the simple minded null analysis
26 T hideNull<T>(T x) => x;
27
28 /// Generate undefined at a type
29 T getUndefined<T>() => (new List(1))[0];
30
31 main() {
32 group('Enum equality', () {
33 // Test equality of two enums, various types, nullable
34 test('Equal enum/enum (nullable)', () {
35 Music e1 = hideNull(Music.country);
36 Music e2 = hideNull(Music.western);
37 dynamic d1 = hideNull(Music.country);
38 dynamic d2 = hideNull(Music.western);
39 Object o1 = hideNull(Music.country);
40 Object o2 = hideNull(Music.western);
41 expect(e1 == e1, true);
42 expect(e1 == d1, true);
43 expect(e1 == o1, true);
44 expect(e1 == e2, false);
45 expect(e1 == o2, false);
46 expect(e1 == d2, false);
47 expect(e1 == e2, false);
48 expect(d1 == e1, true);
49 expect(d1 == d1, true);
50 expect(d1 == o1, true);
51 expect(d1 == e2, false);
52 expect(d1 == d2, false);
53 expect(d1 == o2, false);
54 expect(o1 == e1, true);
55 expect(o1 == d1, true);
56 expect(o1 == o1, true);
57 expect(o1 == e2, false);
58 expect(o1 == d2, false);
59 expect(o1 == o2, false);
60 });
61
62 // Test equality of two enums, various types, non-nullable
63 test('Equal enum/enum (non-null)', () {
64 Music e1 = Music.country;
65 Music e2 = Music.western;
66 dynamic d1 = Music.country;
67 dynamic d2 = Music.western;
68 Object o1 = Music.country;
69 Object o2 = Music.western;
70 expect(e1 == e1, true);
71 expect(e1 == d1, true);
72 expect(e1 == o1, true);
73 expect(e1 == e2, false);
74 expect(e1 == o2, false);
75 expect(e1 == d2, false);
76 expect(e1 == e2, false);
77 expect(d1 == e1, true);
78 expect(d1 == d1, true);
79 expect(d1 == o1, true);
80 expect(d1 == e2, false);
81 expect(d1 == d2, false);
82 expect(d1 == o2, false);
83 expect(o1 == e1, true);
84 expect(o1 == d1, true);
85 expect(o1 == o1, true);
86 expect(o1 == e2, false);
87 expect(o1 == d2, false);
88 expect(o1 == o2, false);
89 });
90
91 // Test equality of enum and other types (static, nullable)
92 test('Equal enum/other (static, nullable)', () {
93 Music e1 = hideNull(Music.country);
94 String s1 = hideNull("hello");
95 String s2 = hideNull("");
96 int i1 = hideNull(3);
97 int i2 = hideNull(0);
98 List l1 = hideNull(new List(3));
99 BluesBrother b1 = hideNull(new _Norman());
100
101 expect(e1 == s1, false);
102 expect(e1 == s2, false);
103 expect(e1 == i1, false);
104 expect(e1 == i2, false);
105 expect(e1 == l1, false);
106 expect(e1 == b1, false);
107
108 expect(s1 == e1, false);
109 expect(s2 == e1, false);
110 expect(i1 == e1, false);
111 expect(i2 == e1, false);
112 expect(l1 == e1, false);
113 expect(b1 == e1, false);
114 });
115
116 // Test equality of enum and other types (static, non-null)
117 test('Equal enum/other (static, non-null)', () {
118 Music e1 = Music.country;
119 String s1 = "hello";
120 String s2 = "";
121 int i1 = 3;
122 int i2 = 0;
123 List l1 = new List(3);
124 BluesBrother b1 = new _Norman();
125
126 expect(e1 == s1, false);
127 expect(e1 == s2, false);
128 expect(e1 == i1, false);
129 expect(e1 == i2, false);
130 expect(e1 == l1, false);
131 expect(e1 == b1, false);
132
133 expect(s1 == e1, false);
134 expect(s2 == e1, false);
135 expect(i1 == e1, false);
136 expect(i2 == e1, false);
137 expect(l1 == e1, false);
138 expect(b1 == e1, false);
139 });
140
141 // Test equality of enum and other types (dynamic, nullable)
142 test('Equal enum/other (dynamic, nullable)', () {
143 Music e1 = hideNull(Music.country);
144 dynamic d1 = hideNull(Music.country);
145 dynamic s1 = hideNull("hello");
146 dynamic s2 = hideNull("");
147 dynamic i1 = hideNull(3);
148 dynamic i2 = hideNull(0);
149 dynamic l1 = hideNull(new List(3));
150 dynamic b1 = hideNull(new _Norman());
151
152 expect(e1 == s1, false);
153 expect(e1 == s2, false);
154 expect(e1 == i1, false);
155 expect(e1 == i2, false);
156 expect(e1 == l1, false);
157 expect(e1 == b1, false);
158
159 expect(s1 == e1, false);
160 expect(s2 == e1, false);
161 expect(i1 == e1, false);
162 expect(i2 == e1, false);
163 expect(l1 == e1, false);
164 expect(b1 == e1, false);
165
166 expect(d1 == s1, false);
167 expect(d1 == s2, false);
168 expect(d1 == i1, false);
169 expect(d1 == i2, false);
170 expect(d1 == l1, false);
171 expect(d1 == b1, false);
172
173 expect(s1 == d1, false);
174 expect(s2 == d1, false);
175 expect(i1 == d1, false);
176 expect(i2 == d1, false);
177 expect(l1 == d1, false);
178 expect(b1 == d1, false);
179 });
180
181 // Test equality of enum and other types (dynamic, non-null)
182 test('Equal enum/other (dynamic, non-null)', () {
183 Music e1 = Music.country;
184 dynamic d1 = Music.country;
185 String s1 = "hello";
186 String s2 = "";
187 int i1 = 3;
188 int i2 = 0;
189 List l1 = new List(3);
190 BluesBrother b1 = new _Norman();
191
192 expect(e1 == s1, false);
193 expect(e1 == s2, false);
194 expect(e1 == i1, false);
195 expect(e1 == i2, false);
196 expect(e1 == l1, false);
197 expect(e1 == b1, false);
198
199 expect(s1 == e1, false);
200 expect(s2 == e1, false);
201 expect(i1 == e1, false);
202 expect(i2 == e1, false);
203 expect(l1 == e1, false);
204 expect(b1 == e1, false);
205
206 expect(d1 == s1, false);
207 expect(d1 == s2, false);
208 expect(d1 == i1, false);
209 expect(d1 == i2, false);
210 expect(d1 == l1, false);
211 expect(d1 == b1, false);
212
213 expect(s1 == d1, false);
214 expect(s2 == d1, false);
215 expect(i1 == d1, false);
216 expect(i2 == d1, false);
217 expect(l1 == d1, false);
218 expect(b1 == d1, false);
219 });
220 });
221
222 group('String equality', () {
223 // Test equality of two strings, various types, nullable
224 test('Equal string/string (nullable)', () {
225 String e1 = hideNull("The");
226 String e2 = hideNull("Band");
227 dynamic d1 = hideNull("The");
228 dynamic d2 = hideNull("Band");
229 Object o1 = hideNull("The");
230 Object o2 = hideNull("Band");
231 expect(e1 == e1, true);
232 expect(e1 == d1, true);
233 expect(e1 == o1, true);
234 expect(e1 == e2, false);
235 expect(e1 == o2, false);
236 expect(e1 == d2, false);
237 expect(e1 == e2, false);
238 expect(d1 == e1, true);
239 expect(d1 == d1, true);
240 expect(d1 == o1, true);
241 expect(d1 == e2, false);
242 expect(d1 == d2, false);
243 expect(d1 == o2, false);
244 expect(o1 == e1, true);
245 expect(o1 == d1, true);
246 expect(o1 == o1, true);
247 expect(o1 == e2, false);
248 expect(o1 == d2, false);
249 expect(o1 == o2, false);
250 });
251
252 // Test equality of two strings, various types, non-nullable
253 test('Equal string/string (non-null)', () {
254 String e1 = "The";
255 String e2 = "Band";
256 dynamic d1 = "The";
257 dynamic d2 = "Band";
258 Object o1 = "The";
259 Object o2 = "Band";
260 expect(e1 == e1, true);
261 expect(e1 == d1, true);
262 expect(e1 == o1, true);
263 expect(e1 == e2, false);
264 expect(e1 == o2, false);
265 expect(e1 == d2, false);
266 expect(e1 == e2, false);
267 expect(d1 == e1, true);
268 expect(d1 == d1, true);
269 expect(d1 == o1, true);
270 expect(d1 == e2, false);
271 expect(d1 == d2, false);
272 expect(d1 == o2, false);
273 expect(o1 == e1, true);
274 expect(o1 == d1, true);
275 expect(o1 == o1, true);
276 expect(o1 == e2, false);
277 expect(o1 == d2, false);
278 expect(o1 == o2, false);
279 });
280
281 // Test equality of string and other types (static, nullable)
282 test('Equal string/other (static, nullable)', () {
283 String e1 = hideNull("The");
284 String s1 = hideNull("hello");
285 String s2 = hideNull("");
286 int i1 = hideNull(3);
287 int i2 = hideNull(0);
288 List l1 = hideNull(new List(3));
289 BluesBrother b1 = hideNull(new _Norman());
290
291 expect(e1 == s1, false);
292 expect(e1 == s2, false);
293 expect(e1 == i1, false);
294 expect(e1 == i2, false);
295 expect(e1 == l1, false);
296 expect(e1 == b1, false);
297
298 expect(s1 == e1, false);
299 expect(s2 == e1, false);
300 expect(i1 == e1, false);
301 expect(i2 == e1, false);
302 expect(l1 == e1, false);
303 expect(b1 == e1, false);
304 });
305
306 // Test equality of string and other types (static, non-null)
307 test('Equal string/other (static, non-null)', () {
308 String e1 = "The";
309 String s1 = "hello";
310 String s2 = "";
311 int i1 = 3;
312 int i2 = 0;
313 List l1 = new List(3);
314 BluesBrother b1 = new _Norman();
315
316 expect(e1 == s1, false);
317 expect(e1 == s2, false);
318 expect(e1 == i1, false);
319 expect(e1 == i2, false);
320 expect(e1 == l1, false);
321 expect(e1 == b1, false);
322
323 expect(s1 == e1, false);
324 expect(s2 == e1, false);
325 expect(i1 == e1, false);
326 expect(i2 == e1, false);
327 expect(l1 == e1, false);
328 expect(b1 == e1, false);
329 });
330
331 // Test equality of string and other types (dynamic, nullable)
332 test('Equal string/other (dynamic, nullable)', () {
333 String e1 = hideNull("The");
334 dynamic d1 = hideNull("The");
335 dynamic s1 = hideNull("hello");
336 dynamic s2 = hideNull("");
337 dynamic i1 = hideNull(3);
338 dynamic i2 = hideNull(0);
339 dynamic l1 = hideNull(new List(3));
340 dynamic b1 = hideNull(new _Norman());
341
342 expect(e1 == s1, false);
343 expect(e1 == s2, false);
344 expect(e1 == i1, false);
345 expect(e1 == i2, false);
346 expect(e1 == l1, false);
347 expect(e1 == b1, false);
348
349 expect(s1 == e1, false);
350 expect(s2 == e1, false);
351 expect(i1 == e1, false);
352 expect(i2 == e1, false);
353 expect(l1 == e1, false);
354 expect(b1 == e1, false);
355
356 expect(d1 == s1, false);
357 expect(d1 == s2, false);
358 expect(d1 == i1, false);
359 expect(d1 == i2, false);
360 expect(d1 == l1, false);
361 expect(d1 == b1, false);
362
363 expect(s1 == d1, false);
364 expect(s2 == d1, false);
365 expect(i1 == d1, false);
366 expect(i2 == d1, false);
367 expect(l1 == d1, false);
368 expect(b1 == d1, false);
369 });
370
371 // Test equality of string and other types (dynamic, non-null)
372 test('Equal string/other (dynamic, non-null)', () {
373 String e1 = "The";
374 dynamic d1 = "The";
375 String s1 = "hello";
376 String s2 = "";
377 int i1 = 3;
378 int i2 = 0;
379 List l1 = new List(3);
380 BluesBrother b1 = new _Norman();
381
382 expect(e1 == s1, false);
383 expect(e1 == s2, false);
384 expect(e1 == i1, false);
385 expect(e1 == i2, false);
386 expect(e1 == l1, false);
387 expect(e1 == b1, false);
388
389 expect(s1 == e1, false);
390 expect(s2 == e1, false);
391 expect(i1 == e1, false);
392 expect(i2 == e1, false);
393 expect(l1 == e1, false);
394 expect(b1 == e1, false);
395
396 expect(d1 == s1, false);
397 expect(d1 == s2, false);
398 expect(d1 == i1, false);
399 expect(d1 == i2, false);
400 expect(d1 == l1, false);
401 expect(d1 == b1, false);
402
403 expect(s1 == d1, false);
404 expect(s2 == d1, false);
405 expect(i1 == d1, false);
406 expect(i2 == d1, false);
407 expect(l1 == d1, false);
408 expect(b1 == d1, false);
409 });
410 });
411
412 group('Boolean equality', () {
413 // Test equality of two bools, various types, nullable
414 test('Equal bool/bool (nullable)', () {
415 bool e1 = hideNull(true);
416 bool e2 = hideNull(false);
417 dynamic d1 = hideNull(true);
418 dynamic d2 = hideNull(false);
419 Object o1 = hideNull(true);
420 Object o2 = hideNull(false);
421 expect(e1 == e1, true);
422 expect(e1 == d1, true);
423 expect(e1 == o1, true);
424 expect(e1 == e2, false);
425 expect(e1 == o2, false);
426 expect(e1 == d2, false);
427 expect(e1 == e2, false);
428 expect(d1 == e1, true);
429 expect(d1 == d1, true);
430 expect(d1 == o1, true);
431 expect(d1 == e2, false);
432 expect(d1 == d2, false);
433 expect(d1 == o2, false);
434 expect(o1 == e1, true);
435 expect(o1 == d1, true);
436 expect(o1 == o1, true);
437 expect(o1 == e2, false);
438 expect(o1 == d2, false);
439 expect(o1 == o2, false);
440 });
441
442 // Test equality of two bools, various types, non-nullable
443 test('Equal bool/bool (non-null)', () {
444 bool e1 = true;
445 bool e2 = false;
446 dynamic d1 = true;
447 dynamic d2 = false;
448 Object o1 = true;
449 Object o2 = false;
450 expect(e1 == e1, true);
451 expect(e1 == d1, true);
452 expect(e1 == o1, true);
453 expect(e1 == e2, false);
454 expect(e1 == o2, false);
455 expect(e1 == d2, false);
456 expect(e1 == e2, false);
457 expect(d1 == e1, true);
458 expect(d1 == d1, true);
459 expect(d1 == o1, true);
460 expect(d1 == e2, false);
461 expect(d1 == d2, false);
462 expect(d1 == o2, false);
463 expect(o1 == e1, true);
464 expect(o1 == d1, true);
465 expect(o1 == o1, true);
466 expect(o1 == e2, false);
467 expect(o1 == d2, false);
468 expect(o1 == o2, false);
469 });
470
471 // Test equality of bool and other types (static, nullable)
472 test('Equal bool/other (static, nullable)', () {
473 bool e1 = hideNull(true);
474 String s1 = hideNull("hello");
475 String s2 = hideNull("");
476 int i1 = hideNull(3);
477 int i2 = hideNull(0);
478 List l1 = hideNull(new List(3));
479 BluesBrother b1 = hideNull(new _Norman());
480
481 expect(e1 == s1, false);
482 expect(e1 == s2, false);
483 expect(e1 == i1, false);
484 expect(e1 == i2, false);
485 expect(e1 == l1, false);
486 expect(e1 == b1, false);
487
488 expect(s1 == e1, false);
489 expect(s2 == e1, false);
490 expect(i1 == e1, false);
491 expect(i2 == e1, false);
492 expect(l1 == e1, false);
493 expect(b1 == e1, false);
494 });
495
496 // Test equality of bool and other types (static, non-null)
497 test('Equal bool/other (static, non-null)', () {
498 bool e1 = true;
499 String s1 = "hello";
500 String s2 = "";
501 int i1 = 3;
502 int i2 = 0;
503 List l1 = new List(3);
504 BluesBrother b1 = new _Norman();
505
506 expect(e1 == s1, false);
507 expect(e1 == s2, false);
508 expect(e1 == i1, false);
509 expect(e1 == i2, false);
510 expect(e1 == l1, false);
511 expect(e1 == b1, false);
512
513 expect(s1 == e1, false);
514 expect(s2 == e1, false);
515 expect(i1 == e1, false);
516 expect(i2 == e1, false);
517 expect(l1 == e1, false);
518 expect(b1 == e1, false);
519 });
520
521 // Test equality of bool and other types (dynamic, nullable)
522 test('Equal bool/other (dynamic, nullable)', () {
523 bool e1 = hideNull(true);
524 dynamic d1 = hideNull(true);
525 dynamic s1 = hideNull("hello");
526 dynamic s2 = hideNull("");
527 dynamic i1 = hideNull(3);
528 dynamic i2 = hideNull(0);
529 dynamic l1 = hideNull(new List(3));
530 dynamic b1 = hideNull(new _Norman());
531
532 expect(e1 == s1, false);
533 expect(e1 == s2, false);
534 expect(e1 == i1, false);
535 expect(e1 == i2, false);
536 expect(e1 == l1, false);
537 expect(e1 == b1, false);
538
539 expect(s1 == e1, false);
540 expect(s2 == e1, false);
541 expect(i1 == e1, false);
542 expect(i2 == e1, false);
543 expect(l1 == e1, false);
544 expect(b1 == e1, false);
545
546 expect(d1 == s1, false);
547 expect(d1 == s2, false);
548 expect(d1 == i1, false);
549 expect(d1 == i2, false);
550 expect(d1 == l1, false);
551 expect(d1 == b1, false);
552
553 expect(s1 == d1, false);
554 expect(s2 == d1, false);
555 expect(i1 == d1, false);
556 expect(i2 == d1, false);
557 expect(l1 == d1, false);
558 expect(b1 == d1, false);
559 });
560
561 // Test equality of bool and other types (dynamic, non-null)
562 test('Equal bool/other (dynamic, non-null)', () {
563 bool e1 = true;
564 dynamic d1 = true;
565 String s1 = "hello";
566 String s2 = "";
567 int i1 = 3;
568 int i2 = 0;
569 List l1 = new List(3);
570 BluesBrother b1 = new _Norman();
571
572 expect(e1 == s1, false);
573 expect(e1 == s2, false);
574 expect(e1 == i1, false);
575 expect(e1 == i2, false);
576 expect(e1 == l1, false);
577 expect(e1 == b1, false);
578
579 expect(s1 == e1, false);
580 expect(s2 == e1, false);
581 expect(i1 == e1, false);
582 expect(i2 == e1, false);
583 expect(l1 == e1, false);
584 expect(b1 == e1, false);
585
586 expect(d1 == s1, false);
587 expect(d1 == s2, false);
588 expect(d1 == i1, false);
589 expect(d1 == i2, false);
590 expect(d1 == l1, false);
591 expect(d1 == b1, false);
592
593 expect(s1 == d1, false);
594 expect(s2 == d1, false);
595 expect(i1 == d1, false);
596 expect(i2 == d1, false);
597 expect(l1 == d1, false);
598 expect(b1 == d1, false);
599 });
600 });
601
602 group('String equality', () {
603 // Test equality of two strings, various types, nullable
604 test('Equal string/string (nullable)', () {
605 String e1 = hideNull("The");
606 String e2 = hideNull("Band");
607 dynamic d1 = hideNull("The");
608 dynamic d2 = hideNull("Band");
609 Object o1 = hideNull("The");
610 Object o2 = hideNull("Band");
611 expect(e1 == e1, true);
612 expect(e1 == d1, true);
613 expect(e1 == o1, true);
614 expect(e1 == e2, false);
615 expect(e1 == o2, false);
616 expect(e1 == d2, false);
617 expect(e1 == e2, false);
618 expect(d1 == e1, true);
619 expect(d1 == d1, true);
620 expect(d1 == o1, true);
621 expect(d1 == e2, false);
622 expect(d1 == d2, false);
623 expect(d1 == o2, false);
624 expect(o1 == e1, true);
625 expect(o1 == d1, true);
626 expect(o1 == o1, true);
627 expect(o1 == e2, false);
628 expect(o1 == d2, false);
629 expect(o1 == o2, false);
630 });
631
632 // Test equality of two strings, various types, non-nullable
633 test('Equal string/string (non-null)', () {
634 String e1 = "The";
635 String e2 = "Band";
636 dynamic d1 = "The";
637 dynamic d2 = "Band";
638 Object o1 = "The";
639 Object o2 = "Band";
640 expect(e1 == e1, true);
641 expect(e1 == d1, true);
642 expect(e1 == o1, true);
643 expect(e1 == e2, false);
644 expect(e1 == o2, false);
645 expect(e1 == d2, false);
646 expect(e1 == e2, false);
647 expect(d1 == e1, true);
648 expect(d1 == d1, true);
649 expect(d1 == o1, true);
650 expect(d1 == e2, false);
651 expect(d1 == d2, false);
652 expect(d1 == o2, false);
653 expect(o1 == e1, true);
654 expect(o1 == d1, true);
655 expect(o1 == o1, true);
656 expect(o1 == e2, false);
657 expect(o1 == d2, false);
658 expect(o1 == o2, false);
659 });
660
661 // Test equality of string and other types (static, nullable)
662 test('Equal string/other (static, nullable)', () {
663 String e1 = hideNull("The");
664 String s1 = hideNull("hello");
665 String s2 = hideNull("");
666 int i1 = hideNull(3);
667 int i2 = hideNull(0);
668 List l1 = hideNull(new List(3));
669 BluesBrother b1 = hideNull(new _Norman());
670
671 expect(e1 == s1, false);
672 expect(e1 == s2, false);
673 expect(e1 == i1, false);
674 expect(e1 == i2, false);
675 expect(e1 == l1, false);
676 expect(e1 == b1, false);
677
678 expect(s1 == e1, false);
679 expect(s2 == e1, false);
680 expect(i1 == e1, false);
681 expect(i2 == e1, false);
682 expect(l1 == e1, false);
683 expect(b1 == e1, false);
684 });
685
686 // Test equality of string and other types (static, non-null)
687 test('Equal string/other (static, non-null)', () {
688 String e1 = "The";
689 String s1 = "hello";
690 String s2 = "";
691 int i1 = 3;
692 int i2 = 0;
693 List l1 = new List(3);
694 BluesBrother b1 = new _Norman();
695
696 expect(e1 == s1, false);
697 expect(e1 == s2, false);
698 expect(e1 == i1, false);
699 expect(e1 == i2, false);
700 expect(e1 == l1, false);
701 expect(e1 == b1, false);
702
703 expect(s1 == e1, false);
704 expect(s2 == e1, false);
705 expect(i1 == e1, false);
706 expect(i2 == e1, false);
707 expect(l1 == e1, false);
708 expect(b1 == e1, false);
709 });
710
711 // Test equality of string and other types (dynamic, nullable)
712 test('Equal string/other (dynamic, nullable)', () {
713 String e1 = hideNull("The");
714 dynamic d1 = hideNull("The");
715 dynamic s1 = hideNull("hello");
716 dynamic s2 = hideNull("");
717 dynamic i1 = hideNull(3);
718 dynamic i2 = hideNull(0);
719 dynamic l1 = hideNull(new List(3));
720 dynamic b1 = hideNull(new _Norman());
721
722 expect(e1 == s1, false);
723 expect(e1 == s2, false);
724 expect(e1 == i1, false);
725 expect(e1 == i2, false);
726 expect(e1 == l1, false);
727 expect(e1 == b1, false);
728
729 expect(s1 == e1, false);
730 expect(s2 == e1, false);
731 expect(i1 == e1, false);
732 expect(i2 == e1, false);
733 expect(l1 == e1, false);
734 expect(b1 == e1, false);
735
736 expect(d1 == s1, false);
737 expect(d1 == s2, false);
738 expect(d1 == i1, false);
739 expect(d1 == i2, false);
740 expect(d1 == l1, false);
741 expect(d1 == b1, false);
742
743 expect(s1 == d1, false);
744 expect(s2 == d1, false);
745 expect(i1 == d1, false);
746 expect(i2 == d1, false);
747 expect(l1 == d1, false);
748 expect(b1 == d1, false);
749 });
750
751 // Test equality of string and other types (dynamic, non-null)
752 test('Equal string/other (dynamic, non-null)', () {
753 String e1 = "The";
754 dynamic d1 = "The";
755 String s1 = "hello";
756 String s2 = "";
757 int i1 = 3;
758 int i2 = 0;
759 List l1 = new List(3);
760 BluesBrother b1 = new _Norman();
761
762 expect(e1 == s1, false);
763 expect(e1 == s2, false);
764 expect(e1 == i1, false);
765 expect(e1 == i2, false);
766 expect(e1 == l1, false);
767 expect(e1 == b1, false);
768
769 expect(s1 == e1, false);
770 expect(s2 == e1, false);
771 expect(i1 == e1, false);
772 expect(i2 == e1, false);
773 expect(l1 == e1, false);
774 expect(b1 == e1, false);
775
776 expect(d1 == s1, false);
777 expect(d1 == s2, false);
778 expect(d1 == i1, false);
779 expect(d1 == i2, false);
780 expect(d1 == l1, false);
781 expect(d1 == b1, false);
782
783 expect(s1 == d1, false);
784 expect(s2 == d1, false);
785 expect(i1 == d1, false);
786 expect(i2 == d1, false);
787 expect(l1 == d1, false);
788 expect(b1 == d1, false);
789 });
790 });
791
792 group('Number equality', () {
793 // Test equality of two ints, various types, nullable
794 test('Equal int/int (nullable)', () {
795 int e1 = hideNull(11);
796 int e2 = hideNull(12);
797 dynamic d1 = hideNull(11);
798 dynamic d2 = hideNull(12);
799 Object o1 = hideNull(11);
800 Object o2 = hideNull(12);
801 expect(e1 == e1, true);
802 expect(e1 == d1, true);
803 expect(e1 == o1, true);
804 expect(e1 == e2, false);
805 expect(e1 == o2, false);
806 expect(e1 == d2, false);
807 expect(e1 == e2, false);
808 expect(d1 == e1, true);
809 expect(d1 == d1, true);
810 expect(d1 == o1, true);
811 expect(d1 == e2, false);
812 expect(d1 == d2, false);
813 expect(d1 == o2, false);
814 expect(o1 == e1, true);
815 expect(o1 == d1, true);
816 expect(o1 == o1, true);
817 expect(o1 == e2, false);
818 expect(o1 == d2, false);
819 expect(o1 == o2, false);
820 });
821
822 // Test equality of two ints, various types, non-nullable
823 test('Equal int/int (non-null)', () {
824 int e1 = 11;
825 int e2 = 12;
826 dynamic d1 = 11;
827 dynamic d2 = 12;
828 Object o1 = 11;
829 Object o2 = 12;
830 expect(e1 == e1, true);
831 expect(e1 == d1, true);
832 expect(e1 == o1, true);
833 expect(e1 == e2, false);
834 expect(e1 == o2, false);
835 expect(e1 == d2, false);
836 expect(e1 == e2, false);
837 expect(d1 == e1, true);
838 expect(d1 == d1, true);
839 expect(d1 == o1, true);
840 expect(d1 == e2, false);
841 expect(d1 == d2, false);
842 expect(d1 == o2, false);
843 expect(o1 == e1, true);
844 expect(o1 == d1, true);
845 expect(o1 == o1, true);
846 expect(o1 == e2, false);
847 expect(o1 == d2, false);
848 expect(o1 == o2, false);
849 });
850
851 // Test equality of int and other types (static, nullable)
852 test('Equal int/other (static, nullable)', () {
853 int e1 = hideNull(11);
854 String s1 = hideNull("hello");
855 String s2 = hideNull("");
856 int i1 = hideNull(3);
857 int i2 = hideNull(0);
858 List l1 = hideNull(new List(3));
859 BluesBrother b1 = hideNull(new _Norman());
860
861 expect(e1 == s1, false);
862 expect(e1 == s2, false);
863 expect(e1 == i1, false);
864 expect(e1 == i2, false);
865 expect(e1 == l1, false);
866 expect(e1 == b1, false);
867
868 expect(s1 == e1, false);
869 expect(s2 == e1, false);
870 expect(i1 == e1, false);
871 expect(i2 == e1, false);
872 expect(l1 == e1, false);
873 expect(b1 == e1, false);
874 });
875
876 // Test equality of int and other types (static, non-null)
877 test('Equal int/other (static, non-null)', () {
878 int e1 = 11;
879 String s1 = "hello";
880 String s2 = "";
881 int i1 = 3;
882 int i2 = 0;
883 List l1 = new List(3);
884 BluesBrother b1 = new _Norman();
885
886 expect(e1 == s1, false);
887 expect(e1 == s2, false);
888 expect(e1 == i1, false);
889 expect(e1 == i2, false);
890 expect(e1 == l1, false);
891 expect(e1 == b1, false);
892
893 expect(s1 == e1, false);
894 expect(s2 == e1, false);
895 expect(i1 == e1, false);
896 expect(i2 == e1, false);
897 expect(l1 == e1, false);
898 expect(b1 == e1, false);
899 });
900
901 // Test equality of int and other types (dynamic, nullable)
902 test('Equal int/other (dynamic, nullable)', () {
903 int e1 = hideNull(11);
904 dynamic d1 = hideNull(11);
905 dynamic s1 = hideNull("hello");
906 dynamic s2 = hideNull("");
907 dynamic i1 = hideNull(3);
908 dynamic i2 = hideNull(0);
909 dynamic l1 = hideNull(new List(3));
910 dynamic b1 = hideNull(new _Norman());
911
912 expect(e1 == s1, false);
913 expect(e1 == s2, false);
914 expect(e1 == i1, false);
915 expect(e1 == i2, false);
916 expect(e1 == l1, false);
917 expect(e1 == b1, false);
918
919 expect(s1 == e1, false);
920 expect(s2 == e1, false);
921 expect(i1 == e1, false);
922 expect(i2 == e1, false);
923 expect(l1 == e1, false);
924 expect(b1 == e1, false);
925
926 expect(d1 == s1, false);
927 expect(d1 == s2, false);
928 expect(d1 == i1, false);
929 expect(d1 == i2, false);
930 expect(d1 == l1, false);
931 expect(d1 == b1, false);
932
933 expect(s1 == d1, false);
934 expect(s2 == d1, false);
935 expect(i1 == d1, false);
936 expect(i2 == d1, false);
937 expect(l1 == d1, false);
938 expect(b1 == d1, false);
939 });
940
941 // Test equality of int and other types (dynamic, non-null)
942 test('Equal int/other (dynamic, non-null)', () {
943 int e1 = 11;
944 dynamic d1 = 11;
945 String s1 = "hello";
946 String s2 = "";
947 int i1 = 3;
948 int i2 = 0;
949 List l1 = new List(3);
950 BluesBrother b1 = new _Norman();
951
952 expect(e1 == s1, false);
953 expect(e1 == s2, false);
954 expect(e1 == i1, false);
955 expect(e1 == i2, false);
956 expect(e1 == l1, false);
957 expect(e1 == b1, false);
958
959 expect(s1 == e1, false);
960 expect(s2 == e1, false);
961 expect(i1 == e1, false);
962 expect(i2 == e1, false);
963 expect(l1 == e1, false);
964 expect(b1 == e1, false);
965
966 expect(d1 == s1, false);
967 expect(d1 == s2, false);
968 expect(d1 == i1, false);
969 expect(d1 == i2, false);
970 expect(d1 == l1, false);
971 expect(d1 == b1, false);
972
973 expect(s1 == d1, false);
974 expect(s2 == d1, false);
975 expect(i1 == d1, false);
976 expect(i2 == d1, false);
977 expect(l1 == d1, false);
978 expect(b1 == d1, false);
979 });
980 });
981
982 group('Object equality', () {
983 // Test equality of two objects, various types, nullable
984 test('Equal object/object (nullable)', () {
985 _Jake e1 = hideNull(new _Jake());
986 _Elwood e2 = hideNull(new _Elwood());
987 dynamic d1 = hideNull(e1);
988 dynamic d2 = hideNull(new _Elwood());
989 Object o1 = hideNull(e1);
990 Object o2 = hideNull(new _Elwood());
991 expect(e1 == e1, true);
992 expect(e1 == d1, true);
993 expect(e1 == o1, true);
994 expect(e1 == e2, false);
995 expect(e1 == o2, false);
996 expect(e1 == d2, false);
997 expect(e1 == e2, false);
998 expect(d1 == e1, true);
999 expect(d1 == d1, true);
1000 expect(d1 == o1, true);
1001 expect(d1 == e2, false);
1002 expect(d1 == d2, false);
1003 expect(d1 == o2, false);
1004 expect(o1 == e1, true);
1005 expect(o1 == d1, true);
1006 expect(o1 == o1, true);
1007 expect(o1 == e2, false);
1008 expect(o1 == d2, false);
1009 expect(o1 == o2, false);
1010 });
1011
1012 // Test equality of two objects, various types, non-nullable
1013 test('Equal object/object (non-null)', () {
1014 _Jake e1 = new _Jake();
1015 _Elwood e2 = new _Elwood();
1016 dynamic d1 = e1;
1017 dynamic d2 = new _Elwood();
1018 Object o1 = e1;
1019 Object o2 = new _Elwood();
1020 expect(e1 == e1, true);
1021 expect(e1 == d1, true);
1022 expect(e1 == o1, true);
1023 expect(e1 == e2, false);
1024 expect(e1 == o2, false);
1025 expect(e1 == d2, false);
1026 expect(e1 == e2, false);
1027 expect(d1 == e1, true);
1028 expect(d1 == d1, true);
1029 expect(d1 == o1, true);
1030 expect(d1 == e2, false);
1031 expect(d1 == d2, false);
1032 expect(d1 == o2, false);
1033 expect(o1 == e1, true);
1034 expect(o1 == d1, true);
1035 expect(o1 == o1, true);
1036 expect(o1 == e2, false);
1037 expect(o1 == d2, false);
1038 expect(o1 == o2, false);
1039 });
1040
1041 // Test equality of object and other types (static, nullable)
1042 test('Equal object/other (static, nullable)', () {
1043 _Jake e1 = hideNull(new _Jake());
1044 String s1 = hideNull("hello");
1045 String s2 = hideNull("");
1046 int i1 = hideNull(3);
1047 int i2 = hideNull(0);
1048 List l1 = hideNull(new List(3));
1049 BluesBrother b1 = hideNull(new _Norman());
1050
1051 expect(e1 == s1, false);
1052 expect(e1 == s2, false);
1053 expect(e1 == i1, false);
1054 expect(e1 == i2, false);
1055 expect(e1 == l1, false);
1056 expect(e1 == b1, false);
1057
1058 expect(s1 == e1, false);
1059 expect(s2 == e1, false);
1060 expect(i1 == e1, false);
1061 expect(i2 == e1, false);
1062 expect(l1 == e1, false);
1063 expect(b1 == e1, false);
1064 });
1065
1066 // Test equality of object and other types (static, non-null)
1067 test('Equal object/other (static, non-null)', () {
1068 _Jake e1 = new _Jake();
1069 String s1 = "hello";
1070 String s2 = "";
1071 int i1 = 3;
1072 int i2 = 0;
1073 List l1 = new List(3);
1074 BluesBrother b1 = new _Norman();
1075
1076 expect(e1 == s1, false);
1077 expect(e1 == s2, false);
1078 expect(e1 == i1, false);
1079 expect(e1 == i2, false);
1080 expect(e1 == l1, false);
1081 expect(e1 == b1, false);
1082
1083 expect(s1 == e1, false);
1084 expect(s2 == e1, false);
1085 expect(i1 == e1, false);
1086 expect(i2 == e1, false);
1087 expect(l1 == e1, false);
1088 expect(b1 == e1, false);
1089 });
1090
1091 // Test equality of object and other types (dynamic, nullable)
1092 test('Equal object/other (dynamic, nullable)', () {
1093 _Jake e1 = hideNull(new _Jake());
1094 dynamic d1 = hideNull(new _Jake());
1095 dynamic s1 = hideNull("hello");
1096 dynamic s2 = hideNull("");
1097 dynamic i1 = hideNull(3);
1098 dynamic i2 = hideNull(0);
1099 dynamic l1 = hideNull(new List(3));
1100 dynamic b1 = hideNull(new _Norman());
1101
1102 expect(e1 == s1, false);
1103 expect(e1 == s2, false);
1104 expect(e1 == i1, false);
1105 expect(e1 == i2, false);
1106 expect(e1 == l1, false);
1107 expect(e1 == b1, false);
1108
1109 expect(s1 == e1, false);
1110 expect(s2 == e1, false);
1111 expect(i1 == e1, false);
1112 expect(i2 == e1, false);
1113 expect(l1 == e1, false);
1114 expect(b1 == e1, false);
1115
1116 expect(d1 == s1, false);
1117 expect(d1 == s2, false);
1118 expect(d1 == i1, false);
1119 expect(d1 == i2, false);
1120 expect(d1 == l1, false);
1121 expect(d1 == b1, false);
1122
1123 expect(s1 == d1, false);
1124 expect(s2 == d1, false);
1125 expect(i1 == d1, false);
1126 expect(i2 == d1, false);
1127 expect(l1 == d1, false);
1128 expect(b1 == d1, false);
1129 });
1130
1131 // Test equality of object and other types (dynamic, non-null)
1132 test('Equal object/other (dynamic, non-null)', () {
1133 _Jake e1 = new _Jake();
1134 dynamic d1 = new _Jake();
1135 String s1 = "hello";
1136 String s2 = "";
1137 int i1 = 3;
1138 int i2 = 0;
1139 List l1 = new List(3);
1140 BluesBrother b1 = new _Norman();
1141
1142 expect(e1 == s1, false);
1143 expect(e1 == s2, false);
1144 expect(e1 == i1, false);
1145 expect(e1 == i2, false);
1146 expect(e1 == l1, false);
1147 expect(e1 == b1, false);
1148
1149 expect(s1 == e1, false);
1150 expect(s2 == e1, false);
1151 expect(i1 == e1, false);
1152 expect(i2 == e1, false);
1153 expect(l1 == e1, false);
1154 expect(b1 == e1, false);
1155
1156 expect(d1 == s1, false);
1157 expect(d1 == s2, false);
1158 expect(d1 == i1, false);
1159 expect(d1 == i2, false);
1160 expect(d1 == l1, false);
1161 expect(d1 == b1, false);
1162
1163 expect(s1 == d1, false);
1164 expect(s2 == d1, false);
1165 expect(i1 == d1, false);
1166 expect(i2 == d1, false);
1167 expect(l1 == d1, false);
1168 expect(b1 == d1, false);
1169 });
1170 });
1171
1172 // Test that null receiver with undefined argument is handled correctly
1173 group('Null/undefined equality', () {
1174 // Test equality of null object and other types
1175 test('Equal object/other (static, null)', () {
1176 BluesBrother n = hideNull(null);
1177 String u1 = getUndefined();
1178 int u2 = getUndefined();
1179 bool u3 = getUndefined();
1180 List u4 = getUndefined();
1181
1182 expect(n == n, true);
1183
1184 expect(n == u1, true);
1185 expect(n == u2, true);
1186 expect(n == u3, true);
1187 expect(n == u4, true);
1188
1189 expect(u1 == n, true);
1190 expect(u2 == n, true);
1191 expect(u3 == n, true);
1192 expect(u4 == n, true);
1193 });
1194
1195 // Test equality of null string and other types
1196 test('Equal String/other (static, null)', () {
1197 BluesBrother u1 = getUndefined();
1198 String n = hideNull(null);
1199 int u2 = getUndefined();
1200 bool u3 = getUndefined();
1201 List u4 = getUndefined();
1202
1203 expect(n == n, true);
1204
1205 expect(n == u1, true);
1206 expect(n == u2, true);
1207 expect(n == u3, true);
1208 expect(n == u4, true);
1209
1210 expect(u1 == n, true);
1211 expect(u2 == n, true);
1212 expect(u3 == n, true);
1213 expect(u4 == n, true);
1214 });
1215
1216 // Test equality of null int and other types
1217 test('Equal int/other (static, null)', () {
1218 BluesBrother u1 = getUndefined();
1219 String u2 = getUndefined();
1220 int n = hideNull(null);
1221 bool u3 = getUndefined();
1222 List u4 = getUndefined();
1223
1224 expect(n == n, true);
1225
1226 expect(n == u1, true);
1227 expect(n == u2, true);
1228 expect(n == u3, true);
1229 expect(n == u4, true);
1230
1231 expect(u1 == n, true);
1232 expect(u2 == n, true);
1233 expect(u3 == n, true);
1234 expect(u4 == n, true);
1235 });
1236
1237 // Test equality of null bool and other types
1238 test('Equal bool/other (static, null)', () {
1239 BluesBrother u1 = getUndefined();
1240 String u2 = getUndefined();
1241 int u3 = getUndefined();
1242 bool n = hideNull(null);
1243 List u4 = getUndefined();
1244
1245 expect(n == n, true);
1246
1247 expect(n == u1, true);
1248 expect(n == u2, true);
1249 expect(n == u3, true);
1250 expect(n == u4, true);
1251
1252 expect(u1 == n, true);
1253 expect(u2 == n, true);
1254 expect(u3 == n, true);
1255 expect(u4 == n, true);
1256 });
1257
1258 // Test equality of null List and other types
1259 test('Equal List/other (static, null)', () {
1260 BluesBrother u1 = getUndefined();
1261 String u2 = getUndefined();
1262 int u3 = getUndefined();
1263 bool u4 = getUndefined();
1264 List n = hideNull(null);
1265
1266 expect(n == n, true);
1267
1268 expect(n == u1, true);
1269 expect(n == u2, true);
1270 expect(n == u3, true);
1271 expect(n == u4, true);
1272
1273 expect(u1 == n, true);
1274 expect(u2 == n, true);
1275 expect(u3 == n, true);
1276 expect(u4 == n, true);
1277 });
1278 });
1279 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/test/browser/language_tests.js ('k') | pkg/dev_compiler/test/codegen_expected/equality_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698