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