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

Side by Side Diff: tests/language/exhaustive_for_test.dart

Issue 17553003: Add an exhaustive test of for loops. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 // Dart test program for testing for statement.
5
6 import "package:expect/expect.dart";
7
8 // Test several variations of for loops:
9 // * With or without an initializer.
10 // * With or without a test.
11 // * With or without an update.
12 // * With or without a continue.
13 // * With or without a fall through exit from the body.
14 // * With or without a break.
15
16 // Note that some possibilities are infinite loops and so not tested.
17 // Combinations that do not have a break or a test but do have a
18 // fall through from the body or a continue will never exit the loop.
19
20 // Each loop test function sets a status containing a bit for each part of
21 // the loop that is present, and to clear the bit as that part of the loop
22 // is executed. The test expectation should be 0 (all present parts were
23 // executed), except for a few cases where an update expression is
24 // unreachable due to a break or return in the loop body.
25
26 const int INIT = 1;
27 const int TEST = 2;
28 const int UPDATE = 4;
29 const int CONTINUE = 8;
30 const int FALL = 16;
31 const int BREAK = 32;
32
33 var status;
34
35 void loop0() {
36 status = 0;
37 for(;;) {
38 return;
39 }
40 }
41
42 void loop1() {
43 status = INIT;
44 for(status &= ~INIT;;) {
45 return;
46 }
47 }
48
49 void loop2() {
50 status = TEST;
51 for(; (status &= ~TEST) != 0;) {
52 return;
53 }
54 }
55
56 void loop3() {
57 status = INIT | TEST;
58 for(status &= ~INIT; (status &= ~TEST) != 0;) {
59 return;
60 }
61 }
62
63 void loop4() {
64 status = UPDATE;
65 for(;; status &= ~UPDATE) {
66 return;
67 }
68 }
69
70 void loop5() {
71 status = INIT | UPDATE;
72 for(status &= ~INIT;; status &= ~UPDATE) {
73 return;
74 }
75 }
76
77 void loop6() {
78 status = TEST | UPDATE;
79 for(; (status &= ~TEST) != 0; status &= ~UPDATE) {
80 return;
81 }
82 }
83
84 void loop7() {
85 status = INIT | TEST | UPDATE;
86 for(status &= ~INIT; (status &= ~TEST) != 0; status &= ~UPDATE) {
87 return;
88 }
89 }
90
91 // Infinite loop not tested.
92 void loop8() {
93 status = CONTINUE;
94 for(;;) {
95 status &= ~CONTINUE;
96 continue;
97 }
98 }
99
100 // Infinite loop not tested.
101 void loop9() {
102 status = INIT | CONTINUE;
103 for(status &= ~INIT;;) {
104 status &= ~CONTINUE;
105 continue;
106 }
107 }
108
109 void loop10() {
110 status = TEST | CONTINUE;
111 for(; (status &= ~TEST) != 0;) {
112 status &= ~CONTINUE;
113 continue;
114 }
115 }
116
117 void loop11() {
118 status = INIT | TEST | CONTINUE;
119 for(status &= ~INIT; (status &= ~TEST) != 0;) {
120 status &= ~CONTINUE;
121 continue;
122 }
123 }
124
125 // Infinite loop.
126 void loop12() {
127 status = UPDATE | CONTINUE;
128 for(;; status &= ~UPDATE) {
129 status &= ~CONTINUE;
130 continue;
131 }
132 }
133
134 // Infinite loop.
135 void loop13() {
136 status = INIT | UPDATE | CONTINUE;
137 for(status &= ~INIT;; status &= ~UPDATE) {
138 status &= ~CONTINUE;
139 continue;
140 }
141 }
142
143 void loop14() {
144 status = TEST | UPDATE | CONTINUE;
145 for(; (status &= ~TEST) != 0; status &= ~UPDATE) {
146 status &= ~CONTINUE;
147 continue;
148 }
149 }
150
151 void loop15() {
152 status = INIT | TEST | UPDATE | CONTINUE;
153 for(status &= ~INIT; (status &= ~TEST) != 0; status &= ~UPDATE) {
154 status &= ~CONTINUE;
155 continue;
156 }
157 }
158
159 // Infinite loop.
160 void loop16() {
161 status = FALL;
162 for(;;) {
163 status &= ~FALL;
164 }
165 }
166
167 // Infinite loop.
168 void loop17() {
169 status = INIT | FALL;
170 for(status &= ~INIT;;) {
171 status &= ~FALL;
172 }
173 }
174
175 void loop18() {
176 status = TEST | FALL;
177 for(; (status &= ~TEST) != 0;) {
178 status &= ~FALL;
179 }
180 }
181
182 void loop19() {
183 status = INIT | TEST | FALL;
184 for(status &= ~INIT; (status &= ~TEST) != 0;) {
185 status &= ~FALL;
186 }
187 }
188
189 // Infinite loop.
190 void loop20() {
191 status = UPDATE | FALL;
192 for(;; status &= ~UPDATE) {
193 status &= ~FALL;
194 }
195 }
196
197 // Infinite loop.
198 void loop21() {
199 status = INIT | UPDATE | FALL;
200 for(status &= ~INIT;; status &= ~UPDATE) {
201 status &= ~FALL;
202 }
203 }
204
205 void loop22() {
206 status = TEST | UPDATE | FALL;
207 for(; (status &= ~TEST) != 0; status &= ~UPDATE) {
208 status &= ~FALL;
209 }
210 }
211
212 void loop23() {
213 status = INIT | TEST | UPDATE | FALL;
214 for(status &= ~INIT; (status &= ~TEST) != 0; status &= ~UPDATE) {
215 status &= ~FALL;
216 }
217 }
218
219 // Infinite loop.
220 void loop24() {
221 status = CONTINUE | FALL;
222 for(;;) {
223 if ((status & CONTINUE) == CONTINUE) {
224 status &= ~CONTINUE;
225 continue;
226 }
227 status &= ~FALL;
228 }
229 }
230
231 // Infinite loop.
232 void loop25() {
233 status = INIT | CONTINUE | FALL;
234 for(status &= ~INIT;;) {
235 if ((status & CONTINUE) == CONTINUE) {
236 status &= ~CONTINUE;
237 continue;
238 }
239 status &= ~FALL;
240 }
241 }
242
243 void loop26() {
244 status = TEST | CONTINUE | FALL;
245 for(; (status &= ~TEST) != 0;) {
246 if ((status & CONTINUE) == CONTINUE) {
247 status &= ~CONTINUE;
248 continue;
249 }
250 status &= ~FALL;
251 }
252 }
253
254 void loop27() {
255 status = INIT | TEST | CONTINUE | FALL;
256 for(status &= ~INIT; (status &= ~TEST) != 0;) {
257 if ((status & CONTINUE) == CONTINUE) {
258 status &= ~CONTINUE;
259 continue;
260 }
261 status &= ~FALL;
262 }
263 }
264
265 // Infinite loop.
266 void loop28() {
267 status = UPDATE | CONTINUE | FALL;
268 for(;; status &= ~UPDATE) {
269 if ((status & CONTINUE) == CONTINUE) {
270 status &= ~CONTINUE;
271 continue;
272 }
273 status &= ~FALL;
274 }
275 }
276
277 // Infinite loop.
278 void loop29() {
279 status = INIT | UPDATE | CONTINUE | FALL;
280 for(status &= ~INIT;; status &= ~UPDATE) {
281 if ((status & CONTINUE) == CONTINUE) {
282 status &= ~CONTINUE;
283 continue;
284 }
285 status &= ~FALL;
286 }
287 }
288
289 void loop30() {
290 status = TEST | UPDATE | CONTINUE | FALL;
291 for(; (status &= ~TEST) != 0; status &= ~UPDATE) {
292 if ((status & CONTINUE) == CONTINUE) {
293 status &= ~CONTINUE;
294 continue;
295 }
296 status &= ~FALL;
297 }
298 }
299
300 void loop31() {
301 status = INIT | TEST | UPDATE | CONTINUE | FALL;
302 for(status &= ~INIT; (status &= ~TEST) != 0; status &= ~UPDATE) {
303 if ((status & CONTINUE) == CONTINUE) {
304 status &= ~CONTINUE;
305 continue;
306 }
307 status &= ~FALL;
308 }
309 }
310
311 void loop32() {
312 status = BREAK;
313 for(;;) {
314 status &= ~BREAK;
315 break;
316 }
317 }
318
319 void loop33() {
320 status = INIT | BREAK;
321 for(status &= ~INIT;;) {
322 status &= ~BREAK;
323 break;
324 }
325 }
326
327 void loop34() {
328 status = TEST | BREAK;
329 for(; (status &= ~TEST) != 0;) {
330 status &= ~BREAK;
331 break;
332 }
333 }
334
335 void loop35() {
336 status = INIT | TEST | BREAK;
337 for(status &= ~INIT; (status &= ~TEST) != 0;) {
338 status &= ~BREAK;
339 break;
340 }
341 }
342
343 void loop36() {
344 status = UPDATE | BREAK;
345 for(;; status &= ~UPDATE) {
346 status &= ~BREAK;
347 break;
348 }
349 }
350
351 void loop37() {
352 status = INIT | UPDATE | BREAK;
353 for(status &= ~INIT;; status &= ~UPDATE) {
354 status &= ~BREAK;
355 break;
356 }
357 }
358
359 void loop38() {
360 status = TEST | UPDATE | BREAK;
361 for(; (status &= ~TEST) != 0; status &= ~UPDATE) {
362 status &= ~BREAK;
363 break;
364 }
365 }
366
367 void loop39() {
368 status = INIT | TEST | UPDATE | BREAK;
369 for(status &= ~INIT; (status &= ~TEST) != 0; status &= ~UPDATE) {
370 status &= ~BREAK;
371 break;
372 }
373 }
374
375 void loop40() {
376 status = CONTINUE | BREAK;
377 for(;;) {
378 if ((status & CONTINUE) == CONTINUE) {
379 status &= ~CONTINUE;
380 continue;
381 }
382 status &= ~BREAK;
383 break;
384 }
385 }
386
387 void loop41() {
388 status = INIT | CONTINUE | BREAK;
389 for(status &= ~INIT;;) {
390 if ((status & CONTINUE) == CONTINUE) {
391 status &= ~CONTINUE;
392 continue;
393 }
394 status &= ~BREAK;
395 break;
396 }
397 }
398
399 void loop42() {
400 status = TEST | CONTINUE | BREAK;
401 for(; (status &= ~TEST) != 0;) {
402 if ((status & CONTINUE) == CONTINUE) {
403 status &= ~CONTINUE;
404 continue;
405 }
406 status &= ~BREAK;
407 break;
408 }
409 }
410
411 void loop43() {
412 status = INIT | TEST | CONTINUE | BREAK;
413 for(status &= ~INIT; (status &= ~TEST) != 0;) {
414 if ((status & CONTINUE) == CONTINUE) {
415 status &= ~CONTINUE;
416 continue;
417 }
418 status &= ~BREAK;
419 break;
420 }
421 }
422
423 void loop44() {
424 status = UPDATE | CONTINUE | BREAK;
425 for(;; status &= ~UPDATE) {
426 if ((status & CONTINUE) == CONTINUE) {
427 status &= ~CONTINUE;
428 continue;
429 }
430 status &= ~BREAK;
431 break;
432 }
433 }
434
435 void loop45() {
436 status = INIT | UPDATE | CONTINUE | BREAK;
437 for(status &= ~INIT;; status &= ~UPDATE) {
438 if ((status & CONTINUE) == CONTINUE) {
439 status &= ~CONTINUE;
440 continue;
441 }
442 status &= ~BREAK;
443 break;
444 }
445 }
446
447 void loop46() {
448 status = TEST | UPDATE | CONTINUE | BREAK;
449 for(; (status &= ~TEST) != 0; status &= ~UPDATE) {
450 if ((status & CONTINUE) == CONTINUE) {
451 status &= ~CONTINUE;
452 continue;
453 }
454 status &= ~BREAK;
455 break;
456 }
457 }
458
459 void loop47() {
460 status = INIT | TEST | UPDATE | CONTINUE | BREAK;
461 for(status &= ~INIT; (status &= ~TEST) != 0; status &= ~UPDATE) {
462 if ((status & CONTINUE) == CONTINUE) {
463 status &= ~CONTINUE;
464 continue;
465 }
466 status &= ~BREAK;
467 break;
468 }
469 }
470
471 void loop48() {
472 status = FALL | BREAK;
473 for(;;) {
474 if ((status & FALL) == FALL) {
475 status &= ~FALL;
476 } else {
477 status &= ~BREAK;
478 break;
479 }
480 }
481 }
482
483 void loop49() {
484 status = INIT | FALL | BREAK;
485 for(status &= ~INIT;;) {
486 if ((status & FALL) == FALL) {
487 status &= ~FALL;
488 } else {
489 status &= ~BREAK;
490 break;
491 }
492 }
493 }
494
495 void loop50() {
496 status = TEST | FALL | BREAK;
497 for(; (status &= ~TEST) != 0;) {
498 if ((status & FALL) == FALL) {
499 status &= ~FALL;
500 } else {
501 status &= ~BREAK;
502 break;
503 }
504 }
505 }
506
507 void loop51() {
508 status = INIT | TEST | FALL | BREAK;
509 for(status &= ~INIT; (status &= ~TEST) != 0;) {
510 if ((status & FALL) == FALL) {
511 status &= ~FALL;
512 } else {
513 status &= ~BREAK;
514 break;
515 }
516 }
517 }
518
519 void loop52() {
520 status = UPDATE | FALL | BREAK;
521 for(;; status &= ~UPDATE) {
522 if ((status & FALL) == FALL) {
523 status &= ~FALL;
524 } else {
525 status &= ~BREAK;
526 break;
527 }
528 }
529 }
530
531 void loop53() {
532 status = INIT | UPDATE | FALL | BREAK;
533 for(status &= ~INIT;; status &= ~UPDATE) {
534 if ((status & FALL) == FALL) {
535 status &= ~FALL;
536 } else {
537 status &= ~BREAK;
538 break;
539 }
540 }
541 }
542
543 void loop54() {
544 status = TEST | UPDATE | FALL | BREAK;
545 for(; (status &= ~TEST) != 0; status &= ~UPDATE) {
546 if ((status & FALL) == FALL) {
547 status &= ~FALL;
548 } else {
549 status &= ~BREAK;
550 break;
551 }
552 }
553 }
554
555 void loop55() {
556 status = INIT | TEST | UPDATE | FALL | BREAK;
557 for(status &= ~INIT; (status &= ~TEST) != 0; status &= ~UPDATE) {
558 if ((status & FALL) == FALL) {
559 status &= ~FALL;
560 } else {
561 status &= ~BREAK;
562 break;
563 }
564 }
565 }
566
567 void loop56() {
568 status = CONTINUE | FALL | BREAK;
569 for(;;) {
570 if ((status & CONTINUE) == CONTINUE) {
571 status &= ~CONTINUE;
572 continue;
573 }
574 if ((status & FALL) == FALL) {
575 status &= ~FALL;
576 } else {
577 status &= ~BREAK;
578 break;
579 }
580 }
581 }
582
583 void loop57() {
584 status = INIT | CONTINUE | FALL | BREAK;
585 for(status &= ~INIT;;) {
586 if ((status & CONTINUE) == CONTINUE) {
587 status &= ~CONTINUE;
588 continue;
589 }
590 if ((status & FALL) == FALL) {
591 status &= ~FALL;
592 } else {
593 status &= ~BREAK;
594 break;
595 }
596 }
597 }
598
599 void loop58() {
600 status = TEST | CONTINUE | FALL | BREAK;
601 for(; (status &= ~TEST) != 0;) {
602 if ((status & CONTINUE) == CONTINUE) {
603 status &= ~CONTINUE;
604 continue;
605 }
606 if ((status & FALL) == FALL) {
607 status &= ~FALL;
608 } else {
609 status &= ~BREAK;
610 break;
611 }
612 }
613 }
614
615 void loop59() {
616 status = INIT | TEST | CONTINUE | FALL | BREAK;
617 for(status &= ~INIT; (status &= ~TEST) != 0;) {
618 if ((status & CONTINUE) == CONTINUE) {
619 status &= ~CONTINUE;
620 continue;
621 }
622 if ((status & FALL) == FALL) {
623 status &= ~FALL;
624 } else {
625 status &= ~BREAK;
626 break;
627 }
628 }
629 }
630
631 void loop60() {
632 status = UPDATE | CONTINUE | FALL | BREAK;
633 for(;; status &= ~UPDATE) {
634 if ((status & CONTINUE) == CONTINUE) {
635 status &= ~CONTINUE;
636 continue;
637 }
638 if ((status & FALL) == FALL) {
639 status &= ~FALL;
640 } else {
641 status &= ~BREAK;
642 break;
643 }
644 }
645 }
646
647 void loop61() {
648 status = INIT | UPDATE | CONTINUE | FALL | BREAK;
649 for(status &= ~INIT;; status &= ~UPDATE) {
650 if ((status & CONTINUE) == CONTINUE) {
651 status &= ~CONTINUE;
652 continue;
653 }
654 if ((status & FALL) == FALL) {
655 status &= ~FALL;
656 } else {
657 status &= ~BREAK;
658 break;
659 }
660 }
661 }
662
663 void loop62() {
664 status = TEST | UPDATE | CONTINUE | FALL | BREAK;
665 for(; (status &= ~TEST) != 0; status &= ~UPDATE) {
666 if ((status & CONTINUE) == CONTINUE) {
667 status &= ~CONTINUE;
668 continue;
669 }
670 if ((status & FALL) == FALL) {
671 status &= ~FALL;
672 } else {
673 status &= ~BREAK;
674 break;
675 }
676 }
677 }
678
679 void loop63() {
680 status = INIT | TEST | UPDATE | CONTINUE | FALL | BREAK;
681 for(status &= ~INIT; (status &= ~TEST) != 0; status &= ~UPDATE) {
682 if ((status & CONTINUE) == CONTINUE) {
683 status &= ~CONTINUE;
684 continue;
685 }
686 if ((status & FALL) == FALL) {
687 status &= ~FALL;
688 } else {
689 status &= ~BREAK;
690 break;
691 }
692 }
693 }
694
695 void main() {
696 loop0();
697 Expect.equals(0, status);
698 loop1();
699 Expect.equals(0, status);
700 loop2();
701 Expect.equals(0, status);
702 loop3();
703 Expect.equals(0, status);
704
705 // The next four tests return with status UPDATE because they return
706 // before the update expression is reached.
707 loop4();
708 Expect.equals(UPDATE, status);
709 loop5();
710 Expect.equals(UPDATE, status);
711 loop6();
712 Expect.equals(UPDATE, status);
713 loop7();
714 Expect.equals(UPDATE, status);
715
716 loop10();
717 Expect.equals(0, status);
718 loop11();
719 Expect.equals(0, status);
720 loop14();
721 Expect.equals(0, status);
722 loop15();
723 Expect.equals(0, status);
724 loop18();
725 Expect.equals(0, status);
726 loop19();
727 Expect.equals(0, status);
728 loop22();
729 Expect.equals(0, status);
730 loop23();
731 Expect.equals(0, status);
732 loop26();
733 Expect.equals(0, status);
734 loop27();
735 Expect.equals(0, status);
736 loop30();
737 Expect.equals(0, status);
738 loop31();
739 Expect.equals(0, status);
740 loop32();
741 Expect.equals(0, status);
742 loop33();
743 Expect.equals(0, status);
744 loop34();
745 Expect.equals(0, status);
746 loop35();
747 Expect.equals(0, status);
748
749 // The next four tests return with status UPDATE because they break from
750 // the loop before the update expression is reached.
751 loop36();
752 Expect.equals(4, status);
753 loop37();
754 Expect.equals(4, status);
755 loop38();
756 Expect.equals(4, status);
757 loop39();
758 Expect.equals(4, status);
759
760 loop40();
761 Expect.equals(0, status);
762 loop41();
763 Expect.equals(0, status);
764 loop42();
765 Expect.equals(0, status);
766 loop43();
767 Expect.equals(0, status);
768 loop44();
769 Expect.equals(0, status);
770 loop45();
771 Expect.equals(0, status);
772 loop46();
773 Expect.equals(0, status);
774 loop47();
775 Expect.equals(0, status);
776 loop48();
777 Expect.equals(0, status);
778 loop49();
779 Expect.equals(0, status);
780 loop50();
781 Expect.equals(0, status);
782 loop51();
783 Expect.equals(0, status);
784 loop52();
785 Expect.equals(0, status);
786 loop53();
787 Expect.equals(0, status);
788 loop54();
789 Expect.equals(0, status);
790 loop55();
791 Expect.equals(0, status);
792 loop56();
793 Expect.equals(0, status);
794 loop57();
795 Expect.equals(0, status);
796 loop58();
797 Expect.equals(0, status);
798 loop59();
799 Expect.equals(0, status);
800 loop60();
801 Expect.equals(0, status);
802 loop61();
803 Expect.equals(0, status);
804 loop62();
805 Expect.equals(0, status);
806 loop63();
807 Expect.equals(0, status);
808 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698