File: meta.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 (111 lines) | stat: -rw-r--r-- 1,659 bytes parent folder | download | duplicates (6)
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
# vim: set ts=2 sts=2 sw=2 expandtab smarttab:
use strict;
use warnings;
use lib 't/lib';
use MarkdownTests;

my @tests;

push @tests, ['name',
<<POD,
=head1 NAME

who - cares
POD
<<MKDN];
[[meta title="who - cares"]]

# NAME

who - cares
MKDN

push @tests, ['author',
<<POD,
=head1 AUTHOR

me, myself, and i
POD
<<MKDN];
[[meta author="me, myself, and i"]]

# AUTHOR

me, myself, and i
MKDN

push @tests, ['none',
<<POD,
=head1 NAME

fooey - barish

=head1 AUTHOR

Foo Bar, Jr.

=head1 THE

end
POD
<<MKDN];
# NAME

fooey - barish

# AUTHOR

Foo Bar, Jr.

# THE

end
MKDN

{
  my (undef, $pod, $mkdn) = @{ $tests[-1] };
  $mkdn = <<MKDN . $mkdn;
[[meta title="fooey - barish"]]
[[meta author="Foo Bar, Jr."]]

MKDN

  push @tests, [ 'name, author', $pod, $mkdn ];
}

plan tests => scalar @tests * 3;

foreach my $test ( @tests ) {
  as_markdown_with_meta(@$test);
  output_string_include_meta_tags(@$test);
  both(@$test);
}

sub as_markdown_with_meta {
  my ($desc, $pod, $exp, $use_attr) = @_;

  my $parser = Pod::Markdown->new(
    include_meta_tags => $use_attr,
  );
  $parser->parse_from_filehandle( io_string($pod) );
  my $markdown = $parser->as_markdown(with_meta => ($desc ne 'none'));

  my $prefix = $use_attr ? 'both' : 'with_meta';
  eq_or_diff $markdown, $exp, "${prefix}: $desc";
}

sub output_string_include_meta_tags {
  my ($desc, $pod, $exp) = @_;

  my $parser = Pod::Markdown->new(
    include_meta_tags => ($desc ne 'none'),
  );
  $parser->output_string(\(my $markdown));
  $parser->parse_string_document($pod);

  eq_or_diff $markdown, $exp, "include_meta_tags: $desc";
}

sub both {
  as_markdown_with_meta(@_, $_[0] ne 'none');
}