Actually note that Shell.pm is deprecated for 5.13 and 5.14, so we can
[p5sagit/p5-mst-13.2.git] / cpan / podlators / t / color.t
1 #!/usr/bin/perl -w
2 #
3 # color.t -- Additional specialized tests for Pod::Text::Color.
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;
22
23 # Skip this test if Term::ANSIColor isn't available.
24 eval { require Term::ANSIColor };
25 if ($@) {
26     plan skip_all => 'Term::ANSIColor required for Pod::Text::Color';
27 } else {
28     plan tests => 4;
29 }
30 require_ok ('Pod::Text::Color');
31
32 # Load tests from the data section below, write the POD to a temporary file,
33 # convert it, and compare to the expected output.
34 my $parser = Pod::Text::Color->new;
35 isa_ok ($parser, 'Pod::Text::Color', 'Parser object');
36 my $n = 1;
37 while (<DATA>) {
38     next until $_ eq "###\n";
39     open (TMP, '> tmp.pod') or die "Cannot create tmp.pod: $!\n";
40     while (<DATA>) {
41         last if $_ eq "###\n";
42         print TMP $_;
43     }
44     close TMP;
45     open (OUT, '> out.tmp') or die "Cannot create out.tmp: $!\n";
46     $parser->parse_from_file ('tmp.pod', \*OUT);
47     close OUT;
48     open (TMP, 'out.tmp') or die "Cannot open out.tmp: $!\n";
49     my $output;
50     {
51         local $/;
52         $output = <TMP>;
53     }
54     close TMP;
55     1 while unlink ('tmp.pod', 'out.tmp');
56     my $expected = '';
57     while (<DATA>) {
58         last if $_ eq "###\n";
59         $expected .= $_;
60     }
61     is ($output, $expected, "Output correct for test $n");
62     $n++;
63 }
64
65 # Below the marker are bits of POD and corresponding expected output.  This is
66 # used to test specific features or problems with Pod::Text::Color.  The input
67 # and output are separated by lines containing only ###.
68
69 __DATA__
70
71 ###
72 =head1 WRAPPING
73
74 B<I<Do>> I<B<not>> B<I<include>> B<I<formatting codes when>> B<I<wrapping>>.
75 ###
76 \e[1mWRAPPING\e[0m
77     \e[1m\e[33mDo\e[0m\e[0m \e[33m\e[1mnot\e[0m\e[0m \e[1m\e[33minclude\e[0m\e[0m \e[1m\e[33mformatting codes when\e[0m\e[0m \e[1m\e[33mwrapping\e[0m\e[0m.
78
79 ###
80
81 ###
82 =head1 TAG WIDTH
83
84 =over 10
85
86 =item 12345678
87
88 A
89
90 =item B<12345678>
91
92 B
93
94 =item 1
95
96 C
97
98 =item B<1>
99
100 D
101
102 =back
103 ###
104 \e[1mTAG WIDTH\e[0m
105     12345678  A
106
107     \e[1m12345678\e[0m  B
108
109     1         C
110
111     \e[1m1\e[0m         D
112
113 ###