1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Test::More;
my @paras;
package TestParser;
use base qw( Parse::Man );
sub para_P
{
my $self = shift;
my ( $opts ) = @_;
push @paras, "";
}
sub chunk
{
my $self = shift;
my ( $text, %opts ) = @_;
if( $opts{font} ne "R" ) {
$text = "<$opts{font}>$text</$opts{font}>";
}
while( $opts{size} < 0 ) {
$text = "<SMALL>$text</SMALL>";
$opts{size}++;
}
$paras[-1] .= $text;
}
package main;
my $parser = TestParser->new;
undef @paras;
$parser->from_string( <<'EOMAN' ),
Plain text
EOMAN
is_deeply( \@paras,
[ "Plain text" ],
'Unformatted' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.R Roman text
EOMAN
is_deeply( \@paras,
[ "Roman text" ],
'.R' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.B Bold text
EOMAN
is_deeply( \@paras,
[ "<B>Bold text</B>" ],
'.B' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.I Italic text
EOMAN
is_deeply( \@paras,
[ "<I>Italic text</I>" ],
'.I' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.SM "Small text"
EOMAN
is_deeply( \@paras,
[ "<SMALL>Small text</SMALL>" ],
'.SM' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.SM Small text
EOMAN
is_deeply( \@paras,
[ "<SMALL>Small</SMALL>text" ],
'.SM joining 2' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.SM Some small text
EOMAN
is_deeply( \@paras,
[ "Some<SMALL>small</SMALL>text" ],
'.SM joining 3' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.RB roman1 bold roman2
EOMAN
is_deeply( \@paras,
[ "roman1<B>bold</B>roman2" ],
'.BR' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.RB "roman1 " bold " roman2"
EOMAN
is_deeply( \@paras,
[ "roman1 <B>bold</B> roman2" ],
'.BR quoted' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
.RB "roman1 " bold " roman2
EOMAN
is_deeply( \@paras,
[ "roman1 <B>bold</B> roman2" ],
'.BR trailing quote' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
\fRRoman text
EOMAN
is_deeply( \@paras,
[ "Roman text" ],
'\fR' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
\fBBold text
EOMAN
is_deeply( \@paras,
[ "<B>Bold text</B>" ],
'\fB' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
\fIItalic text
EOMAN
is_deeply( \@paras,
[ "<I>Italic text</I>" ],
'\fI' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
\f(CWConstant-width text
EOMAN
is_deeply( \@paras,
[ "<CW>Constant-width text</CW>" ],
'\f(CW' );
undef @paras;
$parser->from_string( <<'EOMAN' ),
\fIitalic\fP roman
EOMAN
is_deeply( \@paras,
[ "<I>italic</I> roman" ],
'\f preserves space' );
done_testing;
|