This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sarathy's clear_pmop patch with Radu Greab's fix,
[perl5.git] / t / lib / textwrap.t
CommitLineData
9a09eeb5 1#!./perl -w
1a3850a5
GA
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
1a3850a5
GA
6}
7
9a09eeb5
DMS
8@tests = (split(/\nEND\n/s, <<DONE));
9TEST1
10This
11is
12a
13test
14END
15 This
16 is
17 a
18 test
19END
20TEST2
21This is a test of a very long line. It should be broken up and put onto multiple lines.
22This is a test of a very long line. It should be broken up and put onto multiple lines.
1a3850a5 23
9a09eeb5
DMS
24This is a test of a very long line. It should be broken up and put onto multiple lines.
25END
26 This is a test of a very long line. It should be broken up and put onto
27 multiple lines.
28 This is a test of a very long line. It should be broken up and put onto
29 multiple lines.
30
31 This is a test of a very long line. It should be broken up and put onto
32 multiple lines.
33END
34TEST3
35This is a test of a very long line. It should be broken up and put onto multiple lines.
36END
37 This is a test of a very long line. It should be broken up and put onto
38 multiple lines.
39END
40TEST4
41This is a test of a very long line. It should be broken up and put onto multiple lines.
1a3850a5 42
9a09eeb5
DMS
43END
44 This is a test of a very long line. It should be broken up and put onto
45 multiple lines.
1a3850a5 46
9a09eeb5
DMS
47END
48TEST5
49This is a test of a very long line. It should be broken up and put onto multiple This is a test of a very long line. It should be broken up and put
50END
51 This is a test of a very long line. It should be broken up and put onto
52 multiple This is a test of a very long line. It should be broken up and
53 put
54END
55TEST6
5611111111 22222222 33333333 44444444 55555555 66666666 77777777 888888888 999999999 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffff gggggggg hhhhhhhh iiiiiiii jjjjjjjj kkkkkkkk llllllll mmmmmmmmm nnnnnnnnn ooooooooo ppppppppp qqqqqqqqq rrrrrrrrr sssssssss
57END
58 11111111 22222222 33333333 44444444 55555555 66666666 77777777 888888888
59 999999999 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffff
60 gggggggg hhhhhhhh iiiiiiii jjjjjjjj kkkkkkkk llllllll mmmmmmmmm nnnnnnnnn
61 ooooooooo ppppppppp qqqqqqqqq rrrrrrrrr sssssssss
62END
63TEST7
64c3t1d0s6 c4t1d0s6 c5t1d0s6 c6t1d0s6 c7t1d0s6 c8t1d0s6 c9t1d0s6 c10t1d0s6 c11t1d0s6 c12t1d0s6 c13t1d0s6 c14t1d0s6 c15t1d0s6 c16t1d0s6 c3t1d0s0 c4t1d0s0 c5t1d0s0 c6t1d0s0 c7t1d0s0 c8t1d0s0 c9t1d0s0 c10t1d0s0 c11t1d0s0 c12t1d0s0 c13t1d0s0 c14t1d0s0 c15t1d0s0 c16t1d0s0
65END
66 c3t1d0s6 c4t1d0s6 c5t1d0s6 c6t1d0s6 c7t1d0s6 c8t1d0s6 c9t1d0s6 c10t1d0s6
67 c11t1d0s6 c12t1d0s6 c13t1d0s6 c14t1d0s6 c15t1d0s6 c16t1d0s6 c3t1d0s0
68 c4t1d0s0 c5t1d0s0 c6t1d0s0 c7t1d0s0 c8t1d0s0 c9t1d0s0 c10t1d0s0 c11t1d0s0
69 c12t1d0s0 c13t1d0s0 c14t1d0s0 c15t1d0s0 c16t1d0s0
70END
71TEST8
72A test of a very very long word.
73a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
74END
75 A test of a very very long word.
76 a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
77 4567
78END
79TEST9
80A test of a very very long word. a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
81END
82 A test of a very very long word.
83 a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
84 4567
85END
3e2ea5df
JH
86TEST10
87my mother once said
88"never eat paste my darling"
89would that I heeded
90END
91 my mother once said
92 "never eat paste my darling"
93 would that I heeded
94END
95TEST11
96This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn
97END
98 This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_pr
99 ogram_does_not_crash_and_burn
100END
101TEST12
102This
103
104Has
105
106Blank
107
108Lines
109
110END
111 This
112
113 Has
114
115 Blank
116
117 Lines
118
119END
9a09eeb5 120DONE
1a3850a5 121
1a3850a5 122
9a09eeb5 123$| = 1;
1a3850a5 124
3e2ea5df 125print "1..", 1 +@tests, "\n";
1a3850a5 126
9a09eeb5 127use Text::Wrap;
1a3850a5 128
9a09eeb5 129$rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1;
1a3850a5 130
9a09eeb5 131$tn = 1;
3e2ea5df
JH
132
133@st = @tests;
134while (@st) {
135 my $in = shift(@st);
136 my $out = shift(@st);
1a3850a5 137
9a09eeb5
DMS
138 $in =~ s/^TEST(\d+)?\n//;
139
9ee2bb1a 140 my $back = wrap(' ', ' ', $in);
9a09eeb5 141
9ee2bb1a
JH
142 if ($back eq $out) {
143 print "ok $tn\n";
144 } elsif ($rerun) {
145 my $oi = $in;
146 foreach ($in, $back, $out) {
147 s/\t/^I\t/gs;
148 s/\n/\$\n/gs;
149 }
150 print "------------ input ------------\n";
151 print $in;
152 print "\n------------ output -----------\n";
153 print $back;
154 print "\n------------ expected ---------\n";
155 print $out;
156 print "\n-------------------------------\n";
157 $Text::Wrap::debug = 1;
158 wrap(' ', ' ', $oi);
159 exit(1);
160 } else {
161 print "not ok $tn\n";
162 }
163 $tn++;
3e2ea5df
JH
164
165}
166
167@st = @tests;
168while(@st) {
169 my $in = shift(@st);
170 my $out = shift(@st);
171
172 $in =~ s/^TEST(\d+)?\n//;
173
174 my @in = split("\n", $in, -1);
175 @in = ((map { "$_\n" } @in[0..$#in-1]), $in[-1]);
176
177 my $back = wrap(' ', ' ', @in);
178
179 if ($back eq $out) {
180 print "ok $tn\n";
181 } elsif ($rerun) {
182 my $oi = $in;
183 foreach ($in, $back, $out) {
184 s/\t/^I\t/gs;
185 s/\n/\$\n/gs;
186 }
187 print "------------ input2 ------------\n";
188 print $in;
189 print "\n------------ output2 -----------\n";
190 print $back;
191 print "\n------------ expected2 ---------\n";
192 print $out;
193 print "\n-------------------------------\n";
194 $Text::Wrap::debug = 1;
195 wrap(' ', ' ', $oi);
196 exit(1);
197 } else {
198 print "not ok $tn\n";
199 }
200 $tn++;
9a09eeb5 201}
3e2ea5df
JH
202
203$Text::Wrap::huge = 'overflow';
204
205my $tw = 'This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn';
206my $w = wrap('zzz','yyy',$tw);
207print (($w eq "zzz$tw") ? "ok $tn\n" : "not ok $tn");
208$tn++;
209