| 1 | #!./perl -w
|
|---|
| 2 |
|
|---|
| 3 | BEGIN {
|
|---|
| 4 | chdir 't' if -d 't';
|
|---|
| 5 | @INC = '../lib';
|
|---|
| 6 | }
|
|---|
| 7 |
|
|---|
| 8 | @tests = (split(/\nEND\n/s, <<'DONE'));
|
|---|
| 9 | TEST1
|
|---|
| 10 | This
|
|---|
| 11 | is
|
|---|
| 12 | a
|
|---|
| 13 | test
|
|---|
| 14 | END
|
|---|
| 15 | This
|
|---|
| 16 | is
|
|---|
| 17 | a
|
|---|
| 18 | test
|
|---|
| 19 | END
|
|---|
| 20 | TEST2
|
|---|
| 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.
|
|---|
| 25 | END
|
|---|
| 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.
|
|---|
| 33 | END
|
|---|
| 34 | TEST3
|
|---|
| 35 | This is a test of a very long line. It should be broken up and put onto multiple lines.
|
|---|
| 36 | END
|
|---|
| 37 | This is a test of a very long line. It should be broken up and put onto
|
|---|
| 38 | multiple lines.
|
|---|
| 39 | END
|
|---|
| 40 | TEST4
|
|---|
| 41 | This is a test of a very long line. It should be broken up and put onto multiple lines.
|
|---|
| 42 |
|
|---|
| 43 | END
|
|---|
| 44 | This is a test of a very long line. It should be broken up and put onto
|
|---|
| 45 | multiple lines.
|
|---|
| 46 |
|
|---|
| 47 | END
|
|---|
| 48 | TEST5
|
|---|
| 49 | 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
|
|---|
| 50 | END
|
|---|
| 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
|
|---|
| 54 | END
|
|---|
| 55 | TEST6
|
|---|
| 56 | 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
|
|---|
| 57 | END
|
|---|
| 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
|
|---|
| 62 | END
|
|---|
| 63 | TEST7
|
|---|
| 64 | 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
|
|---|
| 65 | END
|
|---|
| 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
|
|---|
| 70 | END
|
|---|
| 71 | TEST8
|
|---|
| 72 | A test of a very very long word.
|
|---|
| 73 | a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
|
|---|
| 74 | END
|
|---|
| 75 | A test of a very very long word.
|
|---|
| 76 | a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
|
|---|
| 77 | 4567
|
|---|
| 78 | END
|
|---|
| 79 | TEST9
|
|---|
| 80 | A test of a very very long word. a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
|
|---|
| 81 | END
|
|---|
| 82 | A test of a very very long word.
|
|---|
| 83 | a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
|
|---|
| 84 | 4567
|
|---|
| 85 | END
|
|---|
| 86 | TEST10
|
|---|
| 87 | my mother once said
|
|---|
| 88 | "never eat paste my darling"
|
|---|
| 89 | would that I heeded
|
|---|
| 90 | END
|
|---|
| 91 | my mother once said
|
|---|
| 92 | "never eat paste my darling"
|
|---|
| 93 | would that I heeded
|
|---|
| 94 | END
|
|---|
| 95 | TEST11
|
|---|
| 96 | This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn
|
|---|
| 97 | END
|
|---|
| 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
|
|---|
| 100 | END
|
|---|
| 101 | TEST12
|
|---|
| 102 | This
|
|---|
| 103 |
|
|---|
| 104 | Has
|
|---|
| 105 |
|
|---|
| 106 | Blank
|
|---|
| 107 |
|
|---|
| 108 | Lines
|
|---|
| 109 |
|
|---|
| 110 | END
|
|---|
| 111 | This
|
|---|
| 112 |
|
|---|
| 113 | Has
|
|---|
| 114 |
|
|---|
| 115 | Blank
|
|---|
| 116 |
|
|---|
| 117 | Lines
|
|---|
| 118 |
|
|---|
| 119 | END
|
|---|
| 120 | TEST13 break=\d
|
|---|
| 121 | I saw 3 ships come sailing in
|
|---|
| 122 | END
|
|---|
| 123 | I saw 3 ships come sailing in
|
|---|
| 124 | END
|
|---|
| 125 | TEST14 break=\d
|
|---|
| 126 | the.quick.brown.fox.jumps.over.the.9.lazy.dogs.for.no.good.reason.whatsoever.apparently
|
|---|
| 127 | END
|
|---|
| 128 | the.quick.brown.fox.jumps.over.the.
|
|---|
| 129 | .lazy.dogs.for.no.good.reason.whatsoever.apparently
|
|---|
| 130 | END
|
|---|
| 131 | DONE
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 | $| = 1;
|
|---|
| 135 |
|
|---|
| 136 | print "1..", 2 +@tests, "\n";
|
|---|
| 137 |
|
|---|
| 138 | use Text::Wrap;
|
|---|
| 139 |
|
|---|
| 140 | $rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1;
|
|---|
| 141 |
|
|---|
| 142 | $tn = 1;
|
|---|
| 143 |
|
|---|
| 144 | @st = @tests;
|
|---|
| 145 | while (@st) {
|
|---|
| 146 | my $in = shift(@st);
|
|---|
| 147 | my $out = shift(@st);
|
|---|
| 148 |
|
|---|
| 149 | $in =~ s/^TEST(\d+)( break=(.*))?\n//
|
|---|
| 150 | or die "bad TEST header line: $in\n";
|
|---|
| 151 | local $Text::Wrap::break = $3 if defined $3;
|
|---|
| 152 |
|
|---|
| 153 | my $back = wrap(' ', ' ', $in);
|
|---|
| 154 |
|
|---|
| 155 | if ($back eq $out) {
|
|---|
| 156 | print "ok $tn\n";
|
|---|
| 157 | } elsif ($rerun) {
|
|---|
| 158 | my $oi = $in;
|
|---|
| 159 | foreach ($in, $back, $out) {
|
|---|
| 160 | s/\t/^I\t/gs;
|
|---|
| 161 | s/\n/\$\n/gs;
|
|---|
| 162 | }
|
|---|
| 163 | print "------------ input ------------\n";
|
|---|
| 164 | print $in;
|
|---|
| 165 | print "\n------------ output -----------\n";
|
|---|
| 166 | print $back;
|
|---|
| 167 | print "\n------------ expected ---------\n";
|
|---|
| 168 | print $out;
|
|---|
| 169 | print "\n-------------------------------\n";
|
|---|
| 170 | $Text::Wrap::debug = 1;
|
|---|
| 171 | wrap(' ', ' ', $oi);
|
|---|
| 172 | exit(1);
|
|---|
| 173 | } else {
|
|---|
| 174 | print "not ok $tn\n";
|
|---|
| 175 | }
|
|---|
| 176 | $tn++;
|
|---|
| 177 |
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | @st = @tests;
|
|---|
| 181 | while(@st) {
|
|---|
| 182 | my $in = shift(@st);
|
|---|
| 183 | my $out = shift(@st);
|
|---|
| 184 |
|
|---|
| 185 | $in =~ s/^TEST(\d+)( break=(.*))?\n//
|
|---|
| 186 | or die "bad TEST header line: $in\n";
|
|---|
| 187 | local $Text::Wrap::break = $3 if defined $3;
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 | my @in = split("\n", $in, -1);
|
|---|
| 191 | @in = ((map { "$_\n" } @in[0..$#in-1]), $in[-1]);
|
|---|
| 192 |
|
|---|
| 193 | my $back = wrap(' ', ' ', @in);
|
|---|
| 194 |
|
|---|
| 195 | if ($back eq $out) {
|
|---|
| 196 | print "ok $tn\n";
|
|---|
| 197 | } elsif ($rerun) {
|
|---|
| 198 | my $oi = $in;
|
|---|
| 199 | foreach ($in, $back, $out) {
|
|---|
| 200 | s/\t/^I\t/gs;
|
|---|
| 201 | s/\n/\$\n/gs;
|
|---|
| 202 | }
|
|---|
| 203 | print "------------ input2 ------------\n";
|
|---|
| 204 | print $in;
|
|---|
| 205 | print "\n------------ output2 -----------\n";
|
|---|
| 206 | print $back;
|
|---|
| 207 | print "\n------------ expected2 ---------\n";
|
|---|
| 208 | print $out;
|
|---|
| 209 | print "\n-------------------------------\n";
|
|---|
| 210 | $Text::Wrap::debug = 1;
|
|---|
| 211 | wrap(' ', ' ', $oi);
|
|---|
| 212 | exit(1);
|
|---|
| 213 | } else {
|
|---|
| 214 | print "not ok $tn\n";
|
|---|
| 215 | }
|
|---|
| 216 | $tn++;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | $Text::Wrap::huge = 'overflow';
|
|---|
| 220 |
|
|---|
| 221 | my $tw = 'This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn';
|
|---|
| 222 | my $w = wrap('zzz','yyy',$tw);
|
|---|
| 223 | print (($w eq "zzz$tw") ? "ok $tn\n" : "not ok $tn");
|
|---|
| 224 | $tn++;
|
|---|
| 225 |
|
|---|
| 226 | {
|
|---|
| 227 | local $Text::Wrap::columns = 10;
|
|---|
| 228 | local $Text::Wrap::huge = "wrap";
|
|---|
| 229 | print ((wrap("verylongindent", "", "foo") eq "verylongindent\nfoo") ? "ok $tn\n" : "not ok $tn");
|
|---|
| 230 | $tn++;
|
|---|
| 231 | }
|
|---|