Update to podlators 2.3.0
[p5sagit/p5-mst-13.2.git] / cpan / podlators / t / termcap.t
1 #!/usr/bin/perl -w
2 #
3 # termcap.t -- Additional specialized tests for Pod::Text::Termcap.
4 #
5 # Copyright 2002, 2004, 2006, 2009 by Russ Allbery <rra@stanford.edu>
6 #
7 # This program is free software; you may redistribute it and/or modify it
8 # under the same terms as Perl itself.
9
10 BEGIN {
11     chdir 't' if -d 't';
12     if ($ENV{PERL_CORE}) {
13         @INC = '../lib';
14     }
15     unshift (@INC, '../blib/lib');
16     $| = 1;
17 }
18
19 use strict;
20
21 use Test::More tests => 4;
22 BEGIN { use_ok ('Pod::Text::Termcap') }
23
24 # Hard-code a few values to try to get reproducible results.
25 $ENV{COLUMNS} = 80;
26 $ENV{TERM} = 'xterm';
27 $ENV{TERMCAP} = 'xterm:co=80:do=^J:md=\E[1m:us=\E[4m:me=\E[m';
28
29 my $parser = Pod::Text::Termcap->new;
30 isa_ok ($parser, 'Pod::Text::Termcap', 'Parser module');
31 my $n = 1;
32 while (<DATA>) {
33     next until $_ eq "###\n";
34     open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n";
35     while (<DATA>) {
36         last if $_ eq "###\n";
37         print TMP $_;
38     }
39     close TMP;
40     open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
41     $parser->parse_from_file ('tmp.pod', \*OUT);
42     close OUT;
43     open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
44     my $output;
45     {
46         local $/;
47         $output = <TMP>;
48     }
49     close TMP;
50     1 while unlink ('tmp.pod', 'out.tmp');
51     my $expected = '';
52     while (<DATA>) {
53         last if $_ eq "###\n";
54         $expected .= $_;
55     }
56     is ($output, $expected, "Output correct for test $n");
57     $n++;
58 }
59
60 # Below the marker are bits of POD and corresponding expected output.  This is
61 # used to test specific features or problems with Pod::Text::Termcap.  The
62 # input and output are separated by lines containing only ###.
63
64 __DATA__
65
66 ###
67 =head1 WRAPPING
68
69 B<I<Do>> I<B<not>> B<I<include>> B<I<formatting codes when>> B<I<wrapping>>.
70 ###
71 \e[1mWRAPPING\e[m
72     \e[1m\e[4mDo\e[m\e[m \e[4m\e[1mnot\e[m\e[m \e[1m\e[4minclude\e[m\e[m \e[1m\e[4mformatting codes when\e[m\e[m \e[1m\e[4mwrapping\e[m\e[m.
73
74 ###
75
76 ###
77 =head1 TAG WIDTH
78
79 =over 10
80
81 =item 12345678
82
83 A
84
85 =item B<12345678>
86
87 B
88
89 =item 1
90
91 C
92
93 =item B<1>
94
95 D
96
97 =back
98 ###
99 \e[1mTAG WIDTH\e[m
100     12345678  A
101
102     \e[1m12345678\e[m  B
103
104     1         C
105
106     \e[1m1\e[m         D
107
108 ###