File: multifilter.t

package info (click to toggle)
libpandoc-elements-perl 0.38-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 732 kB
  • sloc: perl: 1,630; makefile: 15; sh: 1
file content (83 lines) | stat: -rw-r--r-- 2,587 bytes parent folder | download | duplicates (3)
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
use strict;
use Test::More;
use Test::Exception;
use Pandoc::Elements;
use Pandoc::Filter::Multifilter qw(find_filter apply_filter);
use IPC::Cmd 'can_run';
use Pandoc;

# used to test ~/.pandoc/filters as default filter location
# this does not work on Windows because of symlinks
my ($PANDOC_SYMLINK) = grep { -d $_ } ('t/.pandoc');

# find_filter( ... )
{
    my @tests = (
        {   input    => ['script/multifilter'],
            expected => ['script/multifilter'],
            name     => 'absolute path',
            skip     => 'MSWin32',
        },
        {   input    => ['t/pandoc/filters/empty.pl'],
            expected => [ 'perl', 't/pandoc/filters/empty.pl' ],
            name     => 'known extension',
        },
        {   input    => ['perl'],
            expected => [ can_run('perl') ],
            name     => 'executable in $PATH',
        },
    );

    local $ENV{HOME} = 't';
    if ( $PANDOC_SYMLINK ) {
        push @tests,
            (
            {   input    => ['empty.pl'],
                expected => [ 'perl', 't/.pandoc/filters/empty.pl' ],
                name     => 'known extension in DATADIR',
            },
            {   input    => ['caps'],
                expected => ['t/.pandoc/filters/caps'],
                name     => 'executable in DATADIR',
                skip     => 'MSWin32',
            },
            );
    }

    while ( my $test = shift @tests ) {
    SKIP: {
            skip 'find_filter: ' . $test->{name} . ' on ' . $^O, 1
                if $^O eq ($test->{skip} || '-');
            my @filter = find_filter( @{ $test->{input} } );
            is_deeply \@filter, $test->{expected}, join ' ', 'find_filter: ' . $test->{name};
        }
    }

    my $notfound = '0c9703d020ded30c97682e812636c9ef';
    throws_ok { find_filter($notfound) } qr/^filter not found: $notfound/;
}

if ( $ENV{RELEASE_TESTING} and pandoc and pandoc->version('1.12') ) {

    my $in = Document {}, [ Para [ Str 'hi' ] ];

    my $out = apply_filter( $in, 'html', find_filter( 'caps', 't/pandoc' ) );
    is $out->string, 'HI', 'apply_filter';

    throws_ok {
        apply_filter( $in, 'html', find_filter( 'empty.pl', 't/pandoc' ) );
    }
    qr{^filter emitted no valid JSON};

    if ( $PANDOC_SYMLINK ) {
        $in->meta( { multifilter => MetaList [ MetaInlines [ Str 'caps' ] ] } );
        local $ENV{HOME} = 't';
        Pandoc::Filter::Multifilter->new->apply($in)->to_json;
        is $in->string, 'HI', 'apply_filter';
    }

} else {
    note "Skipping detailed testing of Pandoc::Filter::Multifilter";
}

done_testing;