source: trunk/essentials/dev-lang/perl/t/cmd/while.t@ 3609

Last change on this file since 3609 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 3.4 KB
Line 
1#!./perl
2
3print "1..22\n";
4
5open (tmp,'>Cmd_while.tmp') || die "Can't create Cmd_while.tmp.";
6print tmp "tvi925\n";
7print tmp "tvi920\n";
8print tmp "vt100\n";
9print tmp "Amiga\n";
10print tmp "paper\n";
11close tmp or die "Could not close: $!";
12
13# test "last" command
14
15open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
16while (<fh>) {
17 last if /vt100/;
18}
19if (!eof && /vt100/) {print "ok 1\n";} else {print "not ok 1 $_\n";}
20
21# test "next" command
22
23$bad = '';
24open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
25while (<fh>) {
26 next if /vt100/;
27 $bad = 1 if /vt100/;
28}
29if (!eof || /vt100/ || $bad) {print "not ok 2\n";} else {print "ok 2\n";}
30
31# test "redo" command
32
33$bad = '';
34open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
35while (<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}
43if (!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 = '';
50open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
51line: while (<fh>) {
52 if (/vt100/) {last line;}
53} continue {
54 $badcont = 1 if /vt100/;
55}
56if (!eof && /vt100/) {print "ok 4\n";} else {print "not ok 4\n";}
57if (!$badcont) {print "ok 5\n";} else {print "not ok 5\n";}
58
59# test "next" command
60
61$bad = '';
62$badcont = 1;
63open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
64entry: while (<fh>) {
65 next entry if /vt100/;
66 $bad = 1 if /vt100/;
67} continue {
68 $badcont = '' if /vt100/;
69}
70if (!eof || /vt100/ || $bad) {print "not ok 6\n";} else {print "ok 6\n";}
71if (!$badcont) {print "ok 7\n";} else {print "not ok 7\n";}
72
73# test "redo" command
74
75$bad = '';
76$badcont = '';
77open(fh,'Cmd_while.tmp') || die "Can't open Cmd_while.tmp.";
78loop: 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}
88if (!eof || $bad) {print "not ok 8\n";} else {print "ok 8\n";}
89if (!$badcont) {print "ok 9\n";} else {print "not ok 9\n";}
90
91close(fh) || die "Can't close Cmd_while.tmp.";
92unlink '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;