File: 002_runthrough.t

package info (click to toggle)
libfile-mmagic-xs-perl 0.09008-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 484 kB
  • sloc: perl: 2,130; ansic: 1,858; makefile: 9; xml: 1
file content (53 lines) | stat: -rw-r--r-- 1,415 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
# perl-test
use strict;
use Test::More;
my %map;
BEGIN
{
    my $file = __FILE__;
    %map = (
        $file             => 'text/plain',
        't/data/test.xml' => 'text/xml',
        't/data/test.rtf' => 'application/rtf'
    );
    plan(tests => (scalar( keys %map ) * 5 + 2) * 2 + 1);
}

BEGIN
{
    use_ok("File::MMagic::XS");
}


foreach my $eol (undef, "\0") {
    local $/ = $eol;
    my $fm = File::MMagic::XS->new;

    foreach my $file (keys %map) {
        my $mime = $map{$file};

        my $got = $fm->get_mime($file);
        is($got, $mime, "$file: expected $mime") or die;
        ok(open(F, $file), "ok to open $file");
        is($fm->fhmagic(\*F), $mime, "$file: expected $mime from fhmagic") or die;

        seek(F, 0, 0);
        my $buf = do { local $/ = undef; <F> };
        my $ref = \$buf;
        is($fm->bufmagic($ref), $mime, "$file: expected $mime from bufmagic");

        if ( $mime eq 'text/plain' ) {
            is( $fm->ascmagic( $buf ), $mime, "$file: expected $mime from ascmagic" );
        } else {
            ok( 1, "$file may be binary, skipping test" );
        }
    }

    $fm->add_magic( "0\tstring\t#\\ perl-test\tapplication/x-perl-test" );
    is( $fm->get_mime( __FILE__ ), 'application/x-perl-test' );

    # check file_ext (rt #35269)
    $fm->add_file_ext('t', 'application/x-perl-test');
    is( $fm->get_mime( __FILE__ ), 'application/x-perl-test' );
}