More documentation for the regexp context stack.
[p5sagit/p5-mst-13.2.git] / t / lib / textwrap.t
CommitLineData
9a09eeb5 1#!./perl -w
1a3850a5 2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
1a3850a5 6}
1f47e8e2 7use Text::Wrap qw(&wrap);
1a3850a5 8
9a09eeb5 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 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 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 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
0110aa01 87TEST10
88my mother once said
89"never eat paste my darling"
90would that I heeded
91END
92 my mother once said
93 "never eat paste my darling"
94 would that I heeded
95END
9a09eeb5 96DONE
1a3850a5 97
1a3850a5 98
9a09eeb5 99$| = 1;
1a3850a5 100
0110aa01 101print "1..". @tests . "\n";
1a3850a5 102
9a09eeb5 103use Text::Wrap;
1a3850a5 104
9a09eeb5 105$rerun = $ENV{'PERL_DL_NONLAZY'} ? 0 : 1;
1a3850a5 106
9a09eeb5 107$tn = 1;
108while (@tests) {
109 my $in = shift(@tests);
110 my $out = shift(@tests);
1a3850a5 111
9a09eeb5 112 $in =~ s/^TEST(\d+)?\n//;
113
0110aa01 114 # Make sure split() doesn't drop trailing empty sets.
115 my @in = split("\n", $in, -1);
116 @in = ((map { "$_\n" } @in[0..$#in-1]), $in[-1]);
117
118 # We run wrap() both with a string and a list to test its
119 # line joining logic.
120 foreach my $back (wrap(' ', ' ', @in),
121 wrap(' ', ' ', $in) ) {
9a09eeb5 122
0110aa01 123 if ($back eq $out) {
124 print "ok $tn\n";
125 } elsif ($rerun) {
126 my $oi = $in;
127 foreach ($in, $back, $out) {
128 s/\t/^I\t/gs;
129 s/\n/\$\n/gs;
130 }
131 print "------------ input ------------\n";
132 print $in;
133 print "\n------------ output -----------\n";
134 print $back;
135 print "\n------------ expected ---------\n";
136 print $out;
137 print "\n-------------------------------\n";
138 $Text::Wrap::debug = 1;
139 wrap(' ', ' ', $oi);
140 exit(1);
141 } else {
142 print "not ok $tn\n";
143 }
144 $tn++;
145 }
9a09eeb5 146}