This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Build Text::Tabs before running mktables, as it needs it
[perl5.git] / ext / Text-Tabs / t / sep.t
1 #!/usr/bin/perl -I.
2
3 @tests = (split(/\nEND\n/s, <<DONE));
4 TEST1
5 This 
6 is
7 a
8 test
9 END
10    This = is= a= test
11 END
12 TEST2
13 This is a test of a very long line.  It should be broken up and put onto multiple lines.
14 This is a test of a very long line.  It should be broken up and put onto multiple lines.
15
16 This is a test of a very long line.  It should be broken up and put onto multiple lines.
17 END
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.
19 END
20 TEST3
21 This is a test of a very long line.  It should be broken up and put onto multiple lines.
22 END
23    This is a test of a very long line.  It should be broken up and put onto= multiple lines.
24 END
25 TEST4
26 This is a test of a very long line.  It should be broken up and put onto multiple lines.
27
28 END
29    This is a test of a very long line.  It should be broken up and put onto= multiple lines.
30
31 END
32 TEST5
33 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
34 END
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
36 END
37 TEST6
38 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
39 END
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
41 END
42 TEST7
43 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
44 END
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
46 END
47 TEST8
48 A test of a very very long word.
49 a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
50 END
51    A test of a very very long word.= a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123= 4567
52 END
53 TEST9
54 A test of a very very long word.  a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
55 END
56    A test of a very very long word. = a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123= 4567
57 END
58 TEST10
59 my mother once said
60 "never eat paste my darling"
61 would that I heeded
62 END
63    my mother once said= "never eat paste my darling"= would that I heeded
64 END
65 TEST11
66 This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn
67 END
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
69 END
70 TEST12
71 This
72
73 Has
74
75 Blank
76
77 Lines
78
79 END
80    This= = Has= = Blank= = Lines
81
82 END
83 DONE
84
85
86 $| = 1;
87
88 print "1..", 1 +@tests, "\n";
89
90 use Text::Wrap;
91 $Text::Wrap::separator = '=';
92
93 $rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1;
94
95 $tn = 1;
96
97 @st = @tests;
98 while (@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;
132 while(@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
169 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';
170 my $w = wrap('zzz','yyy',$tw);
171 print (($w eq "zzz$tw") ? "ok $tn\n" : "not ok $tn");
172 $tn++;
173