9
use File::Compare qw/ compare_text /;
10
use File::Temp qw/ tempfile /;
11
use Path::Tiny qw/ path /;
14
use Pod::Readme::Test;
16
# use Pod::Readme::Test::Kit;
18
my $class = 'Pod::Readme::Filter';
21
isa_ok $prf = $class->new( output_fh => $io, ), 'Pod::Readme::Filter';
24
can_ok( $prf, "cmd_" . $_ ) for qw/ stop start continue plugin /;
26
ok $prf->in_target, 'default in target';
27
is $prf->mode, 'default', 'mode';
29
is $prf->base_dir->stringify, '.', 'base_dir';
33
ok !$prf->cmd_stop, 'cmd_stop';
34
ok !$prf->in_target, 'not in target';
36
ok $prf->cmd_start, 'cmd_start';
37
ok $prf->in_target, 'in target';
39
ok !$prf->cmd_stop, 'cmd_stop';
40
ok !$prf->in_target, 'not in target';
42
ok $prf->cmd_continue, 'cmd_continue';
43
ok $prf->in_target, 'in target';
48
is $out, "=pod\n", 'expected output';
49
is $prf->mode, 'pod', 'mode';
50
ok $prf->in_target, 'in target';
55
filter_lines('=for readme stop');
56
is $prf->mode, 'pod:for', 'mode';
59
is $prf->mode, 'pod', 'mode';
61
is $out, '', 'no output';
62
ok !$prf->in_target, 'not in target';
64
filter_lines( 'This should not be copied.', '', 'Boop!', '' );
66
is $out, '', 'no output';
68
filter_lines('=for readme continue');
69
is $prf->mode, 'pod:for', 'mode';
72
is $prf->mode, 'pod', 'mode';
73
ok $prf->in_target, 'in target';
75
is $out, '', 'no output';
79
filter_lines('=for readme stop');
80
is $prf->mode, 'pod:for', 'mode';
83
is $prf->mode, 'pod', 'mode';
85
is $out, '', 'no output';
87
ok !$prf->in_target, 'not in target';
89
filter_lines( 'This should not be copied.', '', 'Boop!', '' );
91
is $out, '', 'no output';
93
filter_lines('=for readme start');
94
is $prf->mode, 'pod:for', 'mode';
97
is $prf->mode, 'pod', 'mode';
98
ok $prf->in_target, 'in target';
100
is $out, '', 'no output';
105
filter_lines('=for readme plugin noop::invalid');
106
is $prf->mode, 'pod:for', 'mode';
109
qr/Unable to locate plugin 'noop::invalid'/, 'bad plugin';
111
is $prf->mode('pod'), 'pod', 'mode reset';
115
filter_lines('=cut');
116
is $prf->mode, 'default', 'default mode';
119
is $out, '', 'no content';
121
filter_lines('=head1 TEST');
122
is $prf->mode, 'pod', 'pod mode';
125
is $out, "=head1 TEST\n\n", 'expected content';
130
filter_lines( "This should be copied.", '' );
132
is $out, "This should be copied.\n\n", 'output';
137
filter_lines('=begin text');
138
is $prf->mode, 'target:text', 'mode';
139
filter_lines( '', 'Something', '', '=end text', '' );
140
is $out, '', 'no content';
145
filter_lines('=begin readme');
146
is $prf->mode, 'pod:begin', 'mode';
147
filter_lines( '', 'Something', '', '=end readme', '' );
149
like $out, qr/^Something\n/, 'expected content (minimal)';
151
local $TODO = 'extra newline';
152
is $out, "Something\n", 'expected content';
158
filter_lines('=begin readme text');
159
is $prf->mode, 'pod:begin', 'mode';
160
filter_lines( '', 'Something', '', '=end readme', '' );
163
is $out, "=begin text\n\nSomething\n\n=end text\n\n",
170
filter_lines('=begin :readme');
171
is $prf->mode, 'pod:begin', 'mode';
172
filter_lines( '', 'Something', '', '=end :readme', '' );
174
like $out, qr/^Something\n/, 'expected content (minimal)';
176
local $TODO = 'extra newline';
177
is $out, "Something\n", 'expected content';
183
can_ok $prf, qw/ parse_cmd_args /;
186
my $res = $prf->parse_cmd_args( undef, 'arg1', 'no-arg2',
187
'arg3="This is a string"', 'arg4=value', );
195
'arg3' => 'This is a string',
198
'expected parsing of arguments list';
205
$prf->parse_cmd_args( [qw/ arg1 arg2 arg3 /], 'arg1', 'no-arg2',
206
'arg3="This is a string"', 'arg4=value', );
208
qr/Invalid argument key 'arg4'/, 'bad arguments';
213
can_ok $prf, qw/ depends_on /;
214
is_deeply [ $prf->depends_on ], [], 'depends_on';