xref: /openbsd-src/gnu/usr.bin/perl/cpan/Text-Tabs/t/wrap.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1*256a93a4Safresh1use strict; use warnings;
2b39c5158Smillert
3*256a93a4Safresh1BEGIN { require './t/lib/ok.pl' }
4*256a93a4Safresh1use Text::Wrap;
5*256a93a4Safresh1
6*256a93a4Safresh1my @tests = (split(/\nEND\n/s, <<'DONE'));
7b39c5158SmillertTEST1
8b39c5158SmillertThis
9b39c5158Smillertis
10b39c5158Smillerta
11b39c5158Smillerttest
12b39c5158SmillertEND
13b39c5158Smillert   This
14b39c5158Smillert is
15b39c5158Smillert a
16b39c5158Smillert test
17b39c5158SmillertEND
18b39c5158SmillertTEST2
19b39c5158SmillertThis is a test of a very long line.  It should be broken up and put onto multiple lines.
20b39c5158SmillertThis is a test of a very long line.  It should be broken up and put onto multiple lines.
21b39c5158Smillert
22b39c5158SmillertThis is a test of a very long line.  It should be broken up and put onto multiple lines.
23b39c5158SmillertEND
24b39c5158Smillert   This is a test of a very long line.	It should be broken up and put onto
25b39c5158Smillert multiple lines.
26b39c5158Smillert This is a test of a very long line.  It should be broken up and put onto
27b39c5158Smillert multiple lines.
28b39c5158Smillert
29b39c5158Smillert This is a test of a very long line.  It should be broken up and put onto
30b39c5158Smillert multiple lines.
31b39c5158SmillertEND
32b39c5158SmillertTEST3
33b39c5158SmillertThis is a test of a very long line.  It should be broken up and put onto multiple lines.
34b39c5158SmillertEND
35b39c5158Smillert   This is a test of a very long line.	It should be broken up and put onto
36b39c5158Smillert multiple lines.
37b39c5158SmillertEND
38b39c5158SmillertTEST4
39b39c5158SmillertThis is a test of a very long line.  It should be broken up and put onto multiple lines.
40b39c5158Smillert
41b39c5158SmillertEND
42b39c5158Smillert   This is a test of a very long line.	It should be broken up and put onto
43b39c5158Smillert multiple lines.
44b39c5158Smillert
45b39c5158SmillertEND
46b39c5158SmillertTEST5
47b39c5158SmillertThis 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
48b39c5158SmillertEND
49b39c5158Smillert   This is a test of a very long line. It should be broken up and put onto
50b39c5158Smillert multiple This is a test of a very long line. It should be broken up and
51b39c5158Smillert put
52b39c5158SmillertEND
53b39c5158SmillertTEST6
54b39c5158Smillert11111111 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
55b39c5158SmillertEND
56b39c5158Smillert   11111111 22222222 33333333 44444444 55555555 66666666 77777777 888888888
57b39c5158Smillert 999999999 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffff
58b39c5158Smillert gggggggg hhhhhhhh iiiiiiii jjjjjjjj kkkkkkkk llllllll mmmmmmmmm nnnnnnnnn
59b39c5158Smillert ooooooooo ppppppppp qqqqqqqqq rrrrrrrrr sssssssss
60b39c5158SmillertEND
61b39c5158SmillertTEST7
62b39c5158Smillertc3t1d0s6 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
63b39c5158SmillertEND
64b39c5158Smillert   c3t1d0s6 c4t1d0s6 c5t1d0s6 c6t1d0s6 c7t1d0s6 c8t1d0s6 c9t1d0s6 c10t1d0s6
65b39c5158Smillert c11t1d0s6 c12t1d0s6 c13t1d0s6 c14t1d0s6 c15t1d0s6 c16t1d0s6 c3t1d0s0
66b39c5158Smillert c4t1d0s0 c5t1d0s0 c6t1d0s0 c7t1d0s0 c8t1d0s0 c9t1d0s0 c10t1d0s0 c11t1d0s0
67b39c5158Smillert c12t1d0s0 c13t1d0s0 c14t1d0s0 c15t1d0s0 c16t1d0s0
68b39c5158SmillertEND
69b39c5158SmillertTEST8
70b39c5158SmillertA test of a very very long word.
71b39c5158Smillerta123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
72b39c5158SmillertEND
73b39c5158Smillert   A test of a very very long word.
74b39c5158Smillert a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
75b39c5158Smillert 4567
76b39c5158SmillertEND
77b39c5158SmillertTEST9
78b39c5158SmillertA test of a very very long word.  a123456789b123456789c123456789d123456789e123456789f123456789g123456789g1234567
79b39c5158SmillertEND
80b39c5158Smillert   A test of a very very long word.
81b39c5158Smillert a123456789b123456789c123456789d123456789e123456789f123456789g123456789g123
82b39c5158Smillert 4567
83b39c5158SmillertEND
84b39c5158SmillertTEST10
85b39c5158Smillertmy mother once said
86b39c5158Smillert"never eat paste my darling"
87b39c5158Smillertwould that I heeded
88b39c5158SmillertEND
89b39c5158Smillert   my mother once said
90b39c5158Smillert "never eat paste my darling"
91b39c5158Smillert would that I heeded
92b39c5158SmillertEND
93b39c5158SmillertTEST11
94b39c5158SmillertThis_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn
95b39c5158SmillertEND
96b39c5158Smillert   This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_pr
97b39c5158Smillert ogram_does_not_crash_and_burn
98b39c5158SmillertEND
99b39c5158SmillertTEST12
100b39c5158SmillertThis
101b39c5158Smillert
102b39c5158SmillertHas
103b39c5158Smillert
104b39c5158SmillertBlank
105b39c5158Smillert
106b39c5158SmillertLines
107b39c5158Smillert
108b39c5158SmillertEND
109b39c5158Smillert   This
110b39c5158Smillert
111b39c5158Smillert Has
112b39c5158Smillert
113b39c5158Smillert Blank
114b39c5158Smillert
115b39c5158Smillert Lines
116b39c5158Smillert
117b39c5158SmillertEND
118b39c5158SmillertTEST13 break=\d
119b39c5158SmillertI saw 3 ships come sailing in
120b39c5158SmillertEND
121b39c5158Smillert   I saw 3 ships come sailing in
122b39c5158SmillertEND
123b39c5158SmillertTEST14 break=\d
124b39c5158Smillertthe.quick.brown.fox.jumps.over.the.9.lazy.dogs.for.no.good.reason.whatsoever.apparently
125b39c5158SmillertEND
126b39c5158Smillert   the.quick.brown.fox.jumps.over.the.
127b39c5158Smillert .lazy.dogs.for.no.good.reason.whatsoever.apparently
128b39c5158SmillertEND
129b39c5158SmillertDONE
130b39c5158Smillert
131b39c5158Smillert
132b39c5158Smillertprint "1..", 2 +@tests, "\n";
133b39c5158Smillert
134*256a93a4Safresh1my @st;
135b39c5158Smillert
136b39c5158Smillert@st = @tests;
137b39c5158Smillertwhile (@st) {
138b39c5158Smillert	my $in = shift(@st);
139b39c5158Smillert	my $out = shift(@st);
140b39c5158Smillert
141b39c5158Smillert	$in =~ s/^TEST(\d+)( break=(.*))?\n//
142b39c5158Smillert	    or die "bad TEST header line: $in\n";
143b39c5158Smillert	local $Text::Wrap::break = $3 if defined $3;
144b39c5158Smillert
145b39c5158Smillert	my $back = wrap('   ', ' ', $in);
146b39c5158Smillert
147*256a93a4Safresh1	ok( $back eq $out );
148b39c5158Smillert
149b39c5158Smillert}
150b39c5158Smillert
151b39c5158Smillert@st = @tests;
152b39c5158Smillertwhile(@st) {
153b39c5158Smillert	my $in = shift(@st);
154b39c5158Smillert	my $out = shift(@st);
155b39c5158Smillert
156b39c5158Smillert	$in =~ s/^TEST(\d+)( break=(.*))?\n//
157b39c5158Smillert	    or die "bad TEST header line: $in\n";
158b39c5158Smillert	local $Text::Wrap::break = $3 if defined $3;
159b39c5158Smillert
160b39c5158Smillert	my @in = split("\n", $in, -1);
161b39c5158Smillert	@in = ((map { "$_\n" } @in[0..$#in-1]), $in[-1]);
162b39c5158Smillert
163b39c5158Smillert	my $back = wrap('   ', ' ', @in);
164b39c5158Smillert
165*256a93a4Safresh1	ok( $back eq $out );
166b39c5158Smillert}
167b39c5158Smillert
168b39c5158Smillert$Text::Wrap::huge = 'overflow';
169b39c5158Smillert
170b39c5158Smillertmy $tw = 'This_is_a_word_that_is_too_long_to_wrap_we_want_to_make_sure_that_the_program_does_not_crash_and_burn';
171b39c5158Smillertmy $w = wrap('zzz','yyy',$tw);
172*256a93a4Safresh1ok( $w eq "zzz$tw" );
173b39c5158Smillert
174b39c5158Smillert{
175b39c5158Smillert    local $Text::Wrap::columns = 10;
176b39c5158Smillert    local $Text::Wrap::huge = "wrap";
177*256a93a4Safresh1    ok( wrap( 'verylongindent', '', 'foo' ) eq "verylongindent\nfoo" );
178b39c5158Smillert}
179