1#!/usr/bin/perl -I. 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= multiple lines. 22 This is a test of a very long line. It should be broken up and put onto= multiple lines. 23 24 This is a test of a very long line. It should be broken up and put onto= multiple lines. 25END 26TEST3 27This is a test of a very long line. It should be broken up and put onto multiple lines. 28END 29 This is a test of a very long line. It should be broken up and put onto= multiple lines. 30END 31TEST4 32This is a test of a very long line. It should be broken up and put onto multiple lines. 33 34END 35 This is a test of a very long line. It should be broken up and put onto= multiple lines. 36 37END 38TEST5 39This 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 40END 41 This 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 42END 43TEST6 4411111111 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 45END 46 11111111 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 47END 48TEST7 49c3t1d0s6 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 50END 51 c3t1d0s6 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 52END 53TEST8 54A test of a very very long word. 55a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567 56END 57 A test of a very very long word. 58 a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123= 4567 59END 60TEST9 61A test of a very very long word. a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567 62END 63 A test of a very very long word. = a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123= 4567 64END 65TEST10 66my mother once said 67"never eat paste my darling" 68would that I heeded 69END 70 my mother once said 71 "never eat paste my darling" 72 would that I heeded 73END 74TEST11 75This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn 76END 77 This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_pr= ogram_does_not_crash_and_burn 78END 79TEST12 80This 81 82Has 83 84Blank 85 86Lines 87 88END 89 This 90 91 Has 92 93 Blank 94 95 Lines 96 97END 98DONE 99 100 101$| = 1; 102 103print "1..", 1 +@tests, "\n"; 104 105use Text::Wrap; 106$Text::Wrap::separator2 = '='; 107 108$rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1; 109 110$tn = 1; 111 112@st = @tests; 113while (@st) { 114 my $in = shift(@st); 115 my $out = shift(@st); 116 117 $in =~ s/^TEST(\d+)?\n//; 118 119 my $back = wrap(' ', ' ', $in); 120 121 if ($back eq $out) { 122 print "ok $tn\n"; 123 } elsif ($rerun) { 124 my $oi = $in; 125 foreach ($in, $back, $out) { 126 s/\t/^I\t/gs; 127 s/\n/\$\n/gs; 128 } 129 print "------------ input ------------\n"; 130 print $in; 131 print "\n------------ output -----------\n"; 132 print $back; 133 print "\n------------ expected ---------\n"; 134 print $out; 135 print "\n-------------------------------\n"; 136 $Text::Wrap::debug = 1; 137 wrap(' ', ' ', $oi); 138 exit(1); 139 } else { 140 print "not ok $tn\n"; 141 } 142 $tn++; 143 144} 145 146@st = @tests; 147while(@st) { 148 my $in = shift(@st); 149 my $out = shift(@st); 150 151 $in =~ s/^TEST(\d+)?\n//; 152 153 my @in = split("\n", $in, -1); 154 @in = ((map { "$_\n" } @in[0..$#in-1]), $in[-1]); 155 156 my $back = wrap(' ', ' ', @in); 157 158 if ($back eq $out) { 159 print "ok $tn\n"; 160 } elsif ($rerun) { 161 my $oi = $in; 162 foreach ($in, $back, $out) { 163 s/\t/^I\t/gs; 164 s/\n/\$\n/gs; 165 } 166 print "------------ input2 ------------\n"; 167 print $in; 168 print "\n------------ output2 -----------\n"; 169 print $back; 170 print "\n------------ expected2 ---------\n"; 171 print $out; 172 print "\n-------------------------------\n"; 173 $Text::Wrap::debug = 1; 174 wrap(' ', ' ', $oi); 175 exit(1); 176 } else { 177 print "not ok $tn\n"; 178 } 179 $tn++; 180} 181 182$Text::Wrap::huge = 'overflow'; 183 184my $tw = 'This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn'; 185my $w = wrap('zzz','yyy',$tw); 186print (($w eq "zzz$tw") ? "ok $tn\n" : "not ok $tn"); 187$tn++; 188 189