/
10-pod-readme-filter.t
217 lines (162 loc) · 4.6 KB
/
10-pod-readme-filter.t
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
use strict;
use warnings;
use Test::More;
use Test::Deep;
use Test::Exception;
use Cwd;
use File::Compare qw/ compare_text /;
use File::Temp qw/ tempfile /;
use Path::Tiny qw/ path /;
use lib 't/lib';
use Pod::Readme::Test;
# use Pod::Readme::Test::Kit;
my $class = 'Pod::Readme::Filter';
use_ok $class;
isa_ok $prf = $class->new( output_fh => $io, ), 'Pod::Readme::Filter';
{
can_ok( $prf, "cmd_" . $_ ) for qw/ stop start continue plugin /;
ok $prf->in_target, 'default in target';
is $prf->mode, 'default', 'mode';
is $prf->base_dir->stringify, '.', 'base_dir';
}
{
ok !$prf->cmd_stop, 'cmd_stop';
ok !$prf->in_target, 'not in target';
ok $prf->cmd_start, 'cmd_start';
ok $prf->in_target, 'in target';
ok !$prf->cmd_stop, 'cmd_stop';
ok !$prf->in_target, 'not in target';
ok $prf->cmd_continue, 'cmd_continue';
ok $prf->in_target, 'in target';
};
{
filter_lines('=pod');
is $out, "=pod\n", 'expected output';
is $prf->mode, 'pod', 'mode';
ok $prf->in_target, 'in target';
reset_out();
};
{
filter_lines('=for readme stop');
is $prf->mode, 'pod:for', 'mode';
filter_lines('');
is $prf->mode, 'pod', 'mode';
is $out, '', 'no output';
ok !$prf->in_target, 'not in target';
filter_lines( 'This should not be copied.', '', 'Boop!', '' );
is $out, '', 'no output';
filter_lines('=for readme continue');
is $prf->mode, 'pod:for', 'mode';
filter_lines('');
is $prf->mode, 'pod', 'mode';
ok $prf->in_target, 'in target';
is $out, '', 'no output';
};
{
filter_lines('=for readme stop');
is $prf->mode, 'pod:for', 'mode';
filter_lines('');
is $prf->mode, 'pod', 'mode';
is $out, '', 'no output';
ok !$prf->in_target, 'not in target';
filter_lines( 'This should not be copied.', '', 'Boop!', '' );
is $out, '', 'no output';
filter_lines('=for readme start');
is $prf->mode, 'pod:for', 'mode';
filter_lines('');
is $prf->mode, 'pod', 'mode';
ok $prf->in_target, 'in target';
is $out, '', 'no output';
};
{
throws_ok {
filter_lines('=for readme plugin noop::invalid');
is $prf->mode, 'pod:for', 'mode';
filter_lines('');
}
qr/Unable to locate plugin 'noop::invalid'/, 'bad plugin';
is $prf->mode('pod'), 'pod', 'mode reset';
};
{
filter_lines('=cut');
is $prf->mode, 'default', 'default mode';
filter_lines('');
is $out, '', 'no content';
filter_lines('=head1 TEST');
is $prf->mode, 'pod', 'pod mode';
filter_lines('');
is $out, "=head1 TEST\n\n", 'expected content';
reset_out();
};
{
filter_lines( "This should be copied.", '' );
is $out, "This should be copied.\n\n", 'output';
reset_out();
};
{
filter_lines('=begin text');
is $prf->mode, 'target:text', 'mode';
filter_lines( '', 'Something', '', '=end text', '' );
is $out, '', 'no content';
reset_out();
}
{
filter_lines('=begin readme');
is $prf->mode, 'pod:begin', 'mode';
filter_lines( '', 'Something', '', '=end readme', '' );
like $out, qr/^Something\n/, 'expected content (minimal)';
TODO: {
local $TODO = 'extra newline';
is $out, "Something\n", 'expected content';
}
reset_out();
}
{
filter_lines('=begin readme text');
is $prf->mode, 'pod:begin', 'mode';
filter_lines( '', 'Something', '', '=end readme', '' );
TODO: {
is $out, "=begin text\n\nSomething\n\n=end text\n\n",
'expected content';
}
reset_out();
}
{
filter_lines('=begin :readme');
is $prf->mode, 'pod:begin', 'mode';
filter_lines( '', 'Something', '', '=end :readme', '' );
like $out, qr/^Something\n/, 'expected content (minimal)';
TODO: {
local $TODO = 'extra newline';
is $out, "Something\n", 'expected content';
}
reset_out();
}
{
can_ok $prf, qw/ parse_cmd_args /;
lives_ok {
my $res = $prf->parse_cmd_args( undef, 'arg1', 'no-arg2',
'arg3="This is a string"', 'arg4=value', );
note( explain $res);
is_deeply $res,
{
'arg1' => 1,
'arg2' => 0,
'arg3' => 'This is a string',
'arg4' => 'value'
},
'expected parsing of arguments list';
}
'parse_cmd_args';
throws_ok {
my $res =
$prf->parse_cmd_args( [qw/ arg1 arg2 arg3 /], 'arg1', 'no-arg2',
'arg3="This is a string"', 'arg4=value', );
}
qr/Invalid argument key 'arg4'/, 'bad arguments';
}
{
can_ok $prf, qw/ depends_on /;
is_deeply [ $prf->depends_on ], [], 'depends_on';
}
done_testing;