| 1 | #!./perl
|
|---|
| 2 |
|
|---|
| 3 | print "1..22\n";
|
|---|
| 4 |
|
|---|
| 5 | open (tmp,'>Cmd_while.tmp') || die "Can't create Cmd_while.tmp.";
|
|---|
| 6 | print tmp "tvi925\n";
|
|---|
| 7 | print tmp "tvi920\n";
|
|---|
| 8 | print tmp "vt100\n";
|
|---|
| 9 | print tmp "Amiga\n";
|
|---|
| 10 | print tmp "paper\n";
|
|---|
| 11 | close tmp or die "Could not close: $!";
|
|---|
| 12 |
|
|---|
| 13 | # test "last" command
|
|---|
| 14 |
|
|---|
| 15 | open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
|
|---|
| 16 | while (<fh>) {
|
|---|
| 17 | last if /vt100/;
|
|---|
| 18 | }
|
|---|
| 19 | if (!eof && /vt100/) {print "ok 1\n";} else {print "not ok 1 $_\n";}
|
|---|
| 20 |
|
|---|
| 21 | # test "next" command
|
|---|
| 22 |
|
|---|
| 23 | $bad = '';
|
|---|
| 24 | open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
|
|---|
| 25 | while (<fh>) {
|
|---|
| 26 | next if /vt100/;
|
|---|
| 27 | $bad = 1 if /vt100/;
|
|---|
| 28 | }
|
|---|
| 29 | if (!eof || /vt100/ || $bad) {print "not ok 2\n";} else {print "ok 2\n";}
|
|---|
| 30 |
|
|---|
| 31 | # test "redo" command
|
|---|
| 32 |
|
|---|
| 33 | $bad = '';
|
|---|
| 34 | open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
|
|---|
| 35 | while (<fh>) {
|
|---|
| 36 | if (s/vt100/VT100/g) {
|
|---|
| 37 | s/VT100/Vt100/g;
|
|---|
| 38 | redo;
|
|---|
| 39 | }
|
|---|
| 40 | $bad = 1 if /vt100/;
|
|---|
| 41 | $bad = 1 if /VT100/;
|
|---|
| 42 | }
|
|---|
| 43 | if (!eof || $bad) {print "not ok 3\n";} else {print "ok 3\n";}
|
|---|
| 44 |
|
|---|
| 45 | # now do the same with a label and a continue block
|
|---|
| 46 |
|
|---|
| 47 | # test "last" command
|
|---|
| 48 |
|
|---|
| 49 | $badcont = '';
|
|---|
| 50 | open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
|
|---|
| 51 | line: while (<fh>) {
|
|---|
| 52 | if (/vt100/) {last line;}
|
|---|
| 53 | } continue {
|
|---|
| 54 | $badcont = 1 if /vt100/;
|
|---|
| 55 | }
|
|---|
| 56 | if (!eof && /vt100/) {print "ok 4\n";} else {print "not ok 4\n";}
|
|---|
| 57 | if (!$badcont) {print "ok 5\n";} else {print "not ok 5\n";}
|
|---|
| 58 |
|
|---|
| 59 | # test "next" command
|
|---|
| 60 |
|
|---|
| 61 | $bad = '';
|
|---|
| 62 | $badcont = 1;
|
|---|
| 63 | open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
|
|---|
| 64 | entry: while (<fh>) {
|
|---|
| 65 | next entry if /vt100/;
|
|---|
| 66 | $bad = 1 if /vt100/;
|
|---|
| 67 | } continue {
|
|---|
| 68 | $badcont = '' if /vt100/;
|
|---|
| 69 | }
|
|---|
| 70 | if (!eof || /vt100/ || $bad) {print "not ok 6\n";} else {print "ok 6\n";}
|
|---|
| 71 | if (!$badcont) {print "ok 7\n";} else {print "not ok 7\n";}
|
|---|
| 72 |
|
|---|
| 73 | # test "redo" command
|
|---|
| 74 |
|
|---|
| 75 | $bad = '';
|
|---|
| 76 | $badcont = '';
|
|---|
| 77 | open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
|
|---|
| 78 | loop: while (<fh>) {
|
|---|
| 79 | if (s/vt100/VT100/g) {
|
|---|
| 80 | s/VT100/Vt100/g;
|
|---|
| 81 | redo loop;
|
|---|
| 82 | }
|
|---|
| 83 | $bad = 1 if /vt100/;
|
|---|
| 84 | $bad = 1 if /VT100/;
|
|---|
| 85 | } continue {
|
|---|
| 86 | $badcont = 1 if /vt100/;
|
|---|
| 87 | }
|
|---|
| 88 | if (!eof || $bad) {print "not ok 8\n";} else {print "ok 8\n";}
|
|---|
| 89 | if (!$badcont) {print "ok 9\n";} else {print "not ok 9\n";}
|
|---|
| 90 |
|
|---|
| 91 | close(fh) || die "Can't close Cmd_while.tmp.";
|
|---|
| 92 | unlink 'Cmd_while.tmp' || `/bin/rm Cmd_While.tmp`;
|
|---|
| 93 |
|
|---|
| 94 | #$x = 0;
|
|---|
| 95 | #while (1) {
|
|---|
| 96 | # if ($x > 1) {last;}
|
|---|
| 97 | # next;
|
|---|
| 98 | #} continue {
|
|---|
| 99 | # if ($x++ > 10) {last;}
|
|---|
| 100 | # next;
|
|---|
| 101 | #}
|
|---|
| 102 | #
|
|---|
| 103 | #if ($x < 10) {print "ok 10\n";} else {print "not ok 10\n";}
|
|---|
| 104 |
|
|---|
| 105 | $i = 9;
|
|---|
|
|---|