App-sdview
view release on metacpan or search on metacpan
t/12parser-man.t view on Meta::CPAN
#!/usr/bin/perl
use v5.14;
use warnings;
use Test2::V0;
use App::sdview::Parser::Man;
my $parser = App::sdview::Parser::Man->new;
isa_ok( $parser, [ "App::sdview::Parser::Man" ], '$parser' );
ok( App::sdview::Parser::Man->can_parse_file( "Example.3" ), 'Parser can handle .3 file' );
ok( App::sdview::Parser::Man->can_parse_file( "Example.3.gz" ), 'Parser can handle .3.gz file' );
subtest "Basic" => sub {
my @p = App::sdview::Parser::Man->new->parse_string( <<"EOMAN" );
.SH Heading
The heading paragraph here.
.SS Content
The content with \\fBbold\\fP and \\f(CWcode\\fP in it.
EOMAN
is( scalar @p, 4, 'Received 4 paragraphs' );
is( $p[0]->type, "head1", 'p[0] type' );
is( $p[0]->text, "Heading", 'p[0] text' );
is( $p[1]->type, "plain", 'p[1] type' );
is( $p[1]->text, "The heading paragraph here.", 'p[1] text' );
is( $p[2]->type, "head2", 'p[2] type' );
is( $p[2]->text, "Content", 'p[2] text' );
is( $p[3]->type, "plain", 'p[3] type' );
is( $p[3]->text, "The content with bold and code in it.", 'p[3] text' );
is( [ sort $p[3]->text->tagnames ], [qw( bold monospace )], 'p[3] tags' );
};
subtest "Formatting" => sub {
my @p = App::sdview::Parser::Man->new->parse_string( <<"EOMAN" );
.PP
.B bold
\\fBbold\\fP
.PP
.I italic
\\fIitalic\\fP
.PP
\\f(CWcode->with->arrows\\fP
EOMAN
is( scalar @p, 3, 'Received 3 paragraphs' );
is( $p[0]->text, "bold bold", 'bold text' );
ok( $p[0]->text->get_tag_at( 0, "bold" ), 'bold tag' );
is( $p[1]->text, "italic italic", 'italic text' );
ok( $p[1]->text->get_tag_at( 0, "italic" ), 'italic tag' );
is( $p[2]->text, "code->with->arrows", 'code text' );
ok( $p[2]->text->get_tag_at( 0, "monospace" ), 'code tag' );
};
subtest "Verbatim trimming" => sub {
my @p = App::sdview::Parser::Man->new->parse_string( <<"EOMAN" );
EXAMPLE
.EX
use v5.14;
use warnings;
say "Hello, world";
.EE
EOMAN
is( scalar @p, 2, 'Received 2 paragraphs' );
is( $p[0]->text, "EXAMPLE", 'p[0] text' );
is( $p[1]->text, qq(use v5.14;\nuse warnings;\nsay "Hello, world";), 'p[1] text' );
};
subtest "Indented" => sub {
my @p = App::sdview::Parser::Man->new->parse_string( <<"EOMAN" );
.RS 4
This plain paragraph is indented
.RE
EOMAN
is( scalar @p, 1, 'Received 1 paragraphs' );
is( $p[0]->type, "plain", 'p[0] type' );
is( $p[0]->indent, 4, 'p[0] indent' );
is( $p[0]->text, "This plain paragraph is indented", 'p[0] text' );
};
subtest "Bullet lists" => sub {
my @p = App::sdview::Parser::Man->new->parse_string( <<"EOMAN" );
.IP \\(bu 4
First
.IP \\(bu
Second
.IP \\(bu 4
Third
EOMAN
is( scalar @p, 1, 'Received 1 paragraph' );
is( $p[0]->type, "list-bullet", 'p[0] type' );
is( $p[0]->indent, 4, 'p[0] indent' );
my @items = $p[0]->items;
is( scalar @items, 3, '3 items' );
is( $items[0]->type, "item", 'items[0] type' );
is( $items[0]->text, "First", 'items[0] text' );
( run in 1.111 second using v1.01-cache-2.11-cpan-39bf76dae61 )