| 1 |
use strict; |
| 2 |
use Test::More; |
| 3 |
use Pandoc::Elements; |
| 4 |
use Pandoc; |
| 5 |
use Pod::Simple::Pandoc; |
| 6 |
use Pod::Pandoc::Modules; |
| 7 |
use Test::Exception; |
| 8 |
|
| 9 |
plan skip_all => 'pandoc not available' unless pandoc; |
| 10 |
|
| 11 |
my $parser = Pod::Simple::Pandoc->new; |
| 12 |
|
| 13 |
# add |
| 14 |
{ |
| 15 |
my $modules = Pod::Pandoc::Modules->new; |
| 16 |
my $name = 'Pod::Simple::Pandoc'; |
| 17 |
my $file = 'lib/Pod/Simple/Pandoc.pm'; |
| 18 |
my $doc = $parser->parse_file($file); |
| 19 |
ok $modules->add( $name => $doc ), 'add'; |
| 20 |
is $modules->{$name}, $doc, 'added'; |
| 21 |
|
| 22 |
ok !$modules->add( $name => $parser->parse_file('script/pod2pandoc') ); |
| 23 |
is $modules->{$name}, $doc, 'add doesn\'t override'; |
| 24 |
|
| 25 |
$file = 't/examples/Pandoc.pod'; |
| 26 |
ok $modules->add( $name => $parser->parse_file($file) ), 'add'; |
| 27 |
is $modules->{$name}->metavalue('file'), $file, '.pod overrides .pm'; |
| 28 |
is $modules->{$name}->metavalue('title'), $name, 'title without NAME'; |
| 29 |
} |
| 30 |
|
| 31 |
# constructor |
| 32 |
my $modules = Pod::Pandoc::Modules->new({ |
| 33 |
'Pod::Simple::Pandoc' => $parser->parse_file('lib/Pod/Simple/Pandoc.pm') |
| 34 |
}); |
| 35 |
|
| 36 |
# index |
| 37 |
sub is_index { |
| 38 |
my ( $name, $opt, $meta, $url, $title ) = @_; |
| 39 |
|
| 40 |
is_deeply $modules->index(%$opt), |
| 41 |
Document( $meta, [ |
| 42 |
DefinitionList [ [ |
| 43 |
[ |
| 44 |
Link attributes {}, |
| 45 |
[ Str 'Pod::Simple::Pandoc' ], |
| 46 |
[ $url, $title ] |
| 47 |
], |
| 48 |
[ [ Plain [ Str 'convert Pod to Pandoc document model' ] ] ] |
| 49 |
] ] |
| 50 |
]), $name; |
| 51 |
} |
| 52 |
|
| 53 |
is_index( |
| 54 |
'index (default)', |
| 55 |
{}, {}, |
| 56 |
'Pod-Simple-Pandoc.html', 'Pod::Simple::Pandoc' |
| 57 |
); |
| 58 |
|
| 59 |
is_index( |
| 60 |
'index (wiki & title)', |
| 61 |
{ wiki => 1, title => 'test' }, { title => MetaString 'test' }, |
| 62 |
'Pod-Simple-Pandoc', 'wikilink' |
| 63 |
); |
| 64 |
|
| 65 |
|
| 66 |
done_testing; |