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