This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make the test more portable.
[perl5.git] / t / lib / textwrap.t
CommitLineData
9a09eeb5 1#!./perl -w
1a3850a5
GA
2
3BEGIN {
4 chdir 't' if -d 't';
93430cb4 5 unshift @INC, '../lib';
1a3850a5 6}
644a2880 7use Text::Wrap qw(&wrap);
1a3850a5 8
9a09eeb5
DMS
9@tests = (split(/\nEND\n/s, <<DONE));
10TEST1
11This
12is
13a
14test
15END
16 This
17 is
18 a
19 test
20END
21TEST2
22This is a test of a very long line. It should be broken up and put onto multiple lines.
23This is a test of a very long line. It should be broken up and put onto multiple lines.
1a3850a5 24
9a09eeb5
DMS
25This is a test of a very long line. It should be broken up and put onto multiple lines.
26END
27 This is a test of a very long line. It should be broken up and put onto
28 multiple lines.
29 This is a test of a very long line. It should be broken up and put onto
30 multiple lines.
31
32 This is a test of a very long line. It should be broken up and put onto
33 multiple lines.
34END
35TEST3
36This is a test of a very long line. It should be broken up and put onto multiple lines.
37END
38 This is a test of a very long line. It should be broken up and put onto
39 multiple lines.
40END
41TEST4
42This is a test of a very long line. It should be broken up and put onto multiple lines.
1a3850a5 43
9a09eeb5
DMS
44END
45 This is a test of a very long line. It should be broken up and put onto
46 multiple lines.
1a3850a5 47
9a09eeb5
DMS
48END
49TEST5
50This 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
51END
52 This is a test of a very long line. It should be broken up and put onto
53 multiple This is a test of a very long line. It should be broken up and
54 put
55END
56TEST6
5711111111 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
58END
59 11111111 22222222 33333333 44444444 55555555 66666666 77777777 888888888
60 999999999 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffff
61 gggggggg hhhhhhhh iiiiiiii jjjjjjjj kkkkkkkk llllllll mmmmmmmmm nnnnnnnnn
62 ooooooooo ppppppppp qqqqqqqqq rrrrrrrrr sssssssss
63END
64TEST7
65c3t1d0s6 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
66END
67 c3t1d0s6 c4t1d0s6 c5t1d0s6 c6t1d0s6 c7t1d0s6 c8t1d0s6 c9t1d0s6 c10t1d0s6
68 c11t1d0s6 c12t1d0s6 c13t1d0s6 c14t1d0s6 c15t1d0s6 c16t1d0s6 c3t1d0s0
69 c4t1d0s0 c5t1d0s0 c6t1d0s0 c7t1d0s0 c8t1d0s0 c9t1d0s0 c10t1d0s0 c11t1d0s0
70 c12t1d0s0 c13t1d0s0 c14t1d0s0 c15t1d0s0 c16t1d0s0
71END
72TEST8
73A test of a very very long word.
74a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
75END
76 A test of a very very long word.
77 a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
78 4567
79END
80TEST9
81A test of a very very long word. a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
82END
83 A test of a very very long word.
84 a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
85 4567
86END
87DONE
1a3850a5 88
1a3850a5 89
9a09eeb5 90$| = 1;
1a3850a5 91
555834d1 92print "1..", @tests/2, "\n";
1a3850a5 93
9a09eeb5 94use Text::Wrap;
1a3850a5 95
9a09eeb5 96$rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1;
1a3850a5 97
9a09eeb5
DMS
98$tn = 1;
99while (@tests) {
100 my $in = shift(@tests);
101 my $out = shift(@tests);
1a3850a5 102
9a09eeb5
DMS
103 $in =~ s/^TEST(\d+)?\n//;
104
105 my $back = wrap(' ', ' ', $in);
106
107 if ($back eq $out) {
108 print "ok $tn\n";
109 } elsif ($rerun) {
110 my $oi = $in;
111 foreach ($in, $back, $out) {
112 s/\t/^I\t/gs;
113 s/\n/\$\n/gs;
114 }
115 print "------------ input ------------\n";
116 print $in;
117 print "\n------------ output -----------\n";
118 print $back;
119 print "\n------------ expected ---------\n";
120 print $out;
121 print "\n-------------------------------\n";
122 $Text::Wrap::debug = 1;
123 wrap(' ', ' ', $oi);
124 exit(1);
125 } else {
126 print "not ok $tn\n";
127 }
128 $tn++;
129}