File: new.t

package info (click to toggle)
libpod-markdown-perl 3.101000-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 444 kB
  • sloc: perl: 1,000; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download | duplicates (2)
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
# vim: set ts=2 sts=2 sw=2 expandtab smarttab:
use strict;
use warnings;
use lib 't/lib';
use MarkdownTests;

sub test_args {
  my $desc = pop;
  my $args = shift || {};
  my %exp = (
    man_url_prefix           => $Pod::Markdown::URL_PREFIXES{man},
    perldoc_url_prefix       => $Pod::Markdown::URL_PREFIXES{metacpan},
    perldoc_fragment_format  => 'metacpan',
    markdown_fragment_format => 'markdown',
    @_ ? %{ $_[0] } : ()
  );
  my $parser = Pod::Markdown->new(%$args);

  foreach my $attr ( sort keys %exp ){
    is $parser->$attr, $exp{$attr}, "$desc: $attr";
  }
}

test_args 'Default attributes';

foreach my $site ( qw( metacpan sco ) ){
  test_args
    { perldoc_url_prefix => $site },
    {
      perldoc_url_prefix => $Pod::Markdown::URL_PREFIXES{$site},
      perldoc_fragment_format => $site,
    },
    "Set perldoc_url_prefix to $site; get matching fragment format";
}

foreach my $format ( map { 'pod_simple_' . $_ } qw( xhtml html ) ){
  test_args
    { perldoc_fragment_format => $format },
    { perldoc_fragment_format => $format },
    "Explicit format $format";
}

foreach my $fragtype ( map { $_ . '_fragment_format' } qw( perldoc markdown ) ){
  my $sub = sub { 'blah' };
  test_args
    { $fragtype => $sub },
    { $fragtype => $sub },
    "Pass a code ref for $fragtype";
}

test_args
  {
    markdown_fragment_format => 'pod_simple_html',
    perldoc_fragment_format  => 'markdown',
  },
  {
    markdown_fragment_format => 'pod_simple_html',
    perldoc_fragment_format  => 'markdown',
  },
  'Values are interchangeable';


# TODO: Change this to an error after a sufficient amount of time.
like warning { Pod::Markdown->new(unknown_arg => 1); },
  qr/unknown_arg/, 'unknown arg throws a warning';

like warning { Pod::Markdown->new(encoding => 'oops'); },
  qr/encoding/, 'method that is not a rw attribute throws a warning';

done_testing;