This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
b9d51f24b6818a417ed52f5d9f5db16da97e45a4
[perl5.git] / ext / Text-Tabs / t / wrap.t
1 #!/usr/bin/perl
2
3 @tests = (split(/\nEND\n/s, <<'DONE'));
4 TEST1
5 This 
6 is
7 a
8 test
9 END
10    This 
11  is
12  a
13  test
14 END
15 TEST2
16 This is a test of a very long line.  It should be broken up and put onto multiple lines.
17 This is a test of a very long line.  It should be broken up and put onto multiple lines.
18
19 This is a test of a very long line.  It should be broken up and put onto multiple lines.
20 END
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.
28 END
29 TEST3
30 This is a test of a very long line.  It should be broken up and put onto multiple lines.
31 END
32    This is a test of a very long line.  It should be broken up and put onto
33  multiple lines.
34 END
35 TEST4
36 This is a test of a very long line.  It should be broken up and put onto multiple lines.
37
38 END
39    This is a test of a very long line.  It should be broken up and put onto
40  multiple lines.
41
42 END
43 TEST5
44 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
45 END
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
49 END
50 TEST6
51 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
52 END
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
57 END
58 TEST7
59 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
60 END
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
65 END
66 TEST8
67 A test of a very very long word.
68 a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
69 END
70    A test of a very very long word.
71  a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
72  4567
73 END
74 TEST9
75 A test of a very very long word.  a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
76 END
77    A test of a very very long word. 
78  a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
79  4567
80 END
81 TEST10
82 my mother once said
83 "never eat paste my darling"
84 would that I heeded
85 END
86    my mother once said
87  "never eat paste my darling"
88  would that I heeded
89 END
90 TEST11
91 This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn
92 END
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
95 END
96 TEST12
97 This
98
99 Has
100
101 Blank
102
103 Lines
104
105 END
106    This
107  
108  Has
109  
110  Blank
111  
112  Lines
113
114 END
115 TEST13 break=\d
116 I saw 3 ships come sailing in
117 END
118    I saw 3 ships come sailing in
119 END
120 TEST14 break=\d
121 the.quick.brown.fox.jumps.over.the.9.lazy.dogs.for.no.good.reason.whatsoever.apparently
122 END
123    the.quick.brown.fox.jumps.over.the.
124  .lazy.dogs.for.no.good.reason.whatsoever.apparently
125 END
126 DONE
127
128
129 $| = 1;
130
131 print "1..", 2 +@tests, "\n";
132
133 use Text::Wrap;
134
135 $rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1;
136
137 $tn = 1;
138
139 @st = @tests;
140 while (@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;
176 while(@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
215 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';
216 my $w = wrap('zzz','yyy',$tw);
217 print (($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 }