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