File: filter.t

package info (click to toggle)
libipc-run-perl 20231003.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 844 kB
  • sloc: perl: 6,255; makefile: 5
file content (112 lines) | stat: -rw-r--r-- 2,182 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
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
#!/usr/bin/perl

=pod

=head1 NAME

filter.t - Test suite for IPC::Run filter scaffolding

=cut

use strict;
use warnings;

BEGIN {
    $|  = 1;
    $^W = 1;
    if ( $ENV{PERL_CORE} ) {
        chdir '../lib/IPC/Run' if -d '../lib/IPC/Run';
        unshift @INC, 'lib', '../..';
        $^X = '../../../t/' . $^X;
    }
}

use Test::More tests => 80;
require './t/lib/Test.pm';
IPC::Run::Test->import();
use IPC::Run qw( :filters :filter_imp );

sub uc_filter {
    my ( $in_ref, $out_ref ) = @_;

    return input_avail && do {
        $$out_ref .= uc($$in_ref);
        $$in_ref = '';
        1;
      }
}

my $string;

sub string_source {
    my ( $in_ref, $out_ref ) = @_;
    return undef unless defined $string;
    $$out_ref .= $string;
    $string = undef;
    return 1;
}

my $accum;

sub accum {
    my ( $in_ref, $out_ref ) = @_;
    return input_avail && do {
        $accum .= $$in_ref;
        $$in_ref = '';
        1;
    };
}

my $op;

## "import" the things we're testing.
*_init_filters = \&IPC::Run::_init_filters;
*_do_filters   = \&IPC::Run::_do_filters;

filter_tests( "filter_tests", "hello world", "hello world" );
filter_tests( "filter_tests []",   [qq(hello world)], [qq(hello world)] );
filter_tests( "filter_tests [] 2", [qw(hello world)], [qw(hello world)] );

filter_tests( "uc_filter", "hello world", "HELLO WORLD", \&uc_filter );

filter_tests(
    "chunking_filter by lines 1",
    "hello 1\nhello 2\nhello 3",
    [ "hello 1\n", "hello 2\n", "hello 3" ],
    new_chunker
);

filter_tests(
    "chunking_filter by lines 2",
    "hello 1\nhello 2\nhello 3",
    [ "hello 1\n", "hello 2\n", "hello 3" ],
    new_chunker
);

filter_tests(
    "chunking_filter by lines 2",
    [ split( /(\s|\n)/, "hello 1\nhello 2\nhello 3" ) ],
    [ "hello 1\n", "hello 2\n", "hello 3" ],
    new_chunker
);

filter_tests(
    "chunking_filter by an odd separator",
    "hello world",
    "hello world",
    new_chunker('odd separator')
);

filter_tests(
    "chunking_filter 2",
    "hello world",
    [ 'hello world' =~ m/(.)/g ],
    new_chunker(qr/./)
);

filter_tests(
    "appending_filter",
    [qw( 1 2 3 )],
    [qw( 1a 2a 3a )],
    new_appender("a")
);