initial import with basic test
[p5sagit/IO-Pipeline.git] / t / pipeline.t
CommitLineData
d5217b4d 1use strict;
2use warnings FATAL => 'all';
3use IO::Pipeline;
4use Test::More qw(no_plan);
5
6my $source = <<'END';
72010-03-21 16:15:30 1NtNoI-000658-6V Completed
82010-03-21 16:17:29 1NtNlx-00062B-0R Completed
92010-03-21 16:20:37 1NtNtF-0006AE-G6 Completed
102010-03-21 16:28:37 no host name found for IP address 218.108.42.254
112010-03-21 16:28:51 H=(ZTZUWWCRQY) [218.108.42.254] F=<pansiesyd75@setupper.com> rejected RCPT <inline@trout.me.uk>: rejected because 218.108.42.254 is in a black list at zen.spamhaus.org
122010-03-21 16:28:51 unexpected disconnection while reading SMTP command from (ZTZUWWCRQY) [218.108.42.254] (error: Connection reset by peer)
132010-03-21 16:35:57 no host name found for IP address 123.122.231.66
142010-03-21 16:35:59 H=(LFMTSDM) [123.122.231.66] F=<belladonnai6@buybuildanichestore.com> rejected RCPT <tal@fyrestorm.co.uk>: rejected because 123.122.231.66 is in a black list at zen.spamhaus.org
15END
16
17sub input_fh {
18 open my $in, '<', \$source;
19 return $in;
20}
21
22my $out;
23
24my $pipe = input_fh
25 | pmap { [ /^(\S+) (\S+) (.*)$/ ] }
26 | pgrep { $_->[2] =~ /rejected|Completed/ }
27 | pmap { [ @{$_}[0, 1], $_->[2] =~ /rejected/ ? 'Rejected' : 'Completed' ] }
28 | pmap { join(' ', @$_)."\n" }
29 | psink { $out .= $_ };
30
31is($out, <<'END', 'Output ok');
322010-03-21 16:15:30 Completed
332010-03-21 16:17:29 Completed
342010-03-21 16:20:37 Completed
352010-03-21 16:28:51 Rejected
362010-03-21 16:35:59 Rejected
37END