"Fossies" - the Fresh Open Source Software Archive

Member "MIME-Types-2.22/t/20types.t" (27 Oct 2021, 2524 Bytes) of package /linux/privat/MIME-Types-2.22.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "20types.t": 2.21_vs_2.22.

    1 #!/usr/bin/env perl
    2 #
    3 # Test reporting warnings, errors and family.
    4 #
    5 
    6 use strict;
    7 use warnings;
    8 
    9 use lib qw(lib t);
   10 
   11 use Test::More;
   12 
   13 use MIME::Types;
   14 my $a = MIME::Types->new;
   15 ok(defined $a);
   16 
   17 my $t = $a->type('multipart/mixed');
   18 isa_ok($t, 'MIME::Type');
   19 is($t->type, 'multipart/mixed');
   20 
   21 # No extensions, but a known, explicit encoding.
   22 $t = $a->type('message/external-body');
   23 ok(not $t->extensions);
   24 is($t->encoding, '8bit');
   25 
   26 $t = $a->type('TEXT/x-RTF');
   27 is($t->type, 'text/rtf');
   28 
   29 my $m = $a->mimeTypeOf('gif');
   30 ok(defined $m);
   31 isa_ok($m, 'MIME::Type');
   32 is($m->type, 'image/gif');
   33 
   34 my $n = $a->mimeTypeOf('GIF');
   35 ok(defined $n);
   36 is($n->type, 'image/gif');
   37 
   38 my $p = $a->mimeTypeOf('my_image.gif');
   39 ok(defined $p);
   40 is($p->type, 'image/gif');
   41 
   42 my $q = $a->mimeTypeOf('windows.doc');
   43 if($^O eq 'VMS')
   44 {   # See MIME::Types, OS Exceptions
   45     is($q->type, 'text/plain');
   46 }
   47 else
   48 {   is($q->type, 'application/msword');
   49 }
   50 is($a->mimeTypeOf('my.lzh')->type, 'application/x-lzh');
   51 
   52 # Generated output may not be stable.
   53 is($a->mimeTypeOf('webm')->type,   'video/x-webm');
   54 is($a->mimeTypeOf('b.webm')->type, 'video/x-webm');
   55 is($a->mimeTypeOf('b.weba')->type, 'audio/x-webm');
   56 is($a->mimeTypeOf('b.webp')->type, 'image/x-webp');
   57 
   58 my $warn;
   59 my $r2 = MIME::Type->new(type => 'text/x-fake2');
   60 {   $SIG{__WARN__} = sub {$warn = join '',@_};
   61     $a->addType($r2);
   62 }
   63 ok(not defined $warn);
   64 
   65 undef $warn;
   66 my $r3 = MIME::Type->new(type => 'x-appl/x-fake3');
   67 {   $SIG{__WARN__} = sub {$warn = join '',@_};
   68     $a->addType($r3);
   69 }
   70 ok(not defined $warn);
   71 
   72 undef $warn;
   73 my $r4 = MIME::Type->new(type => 'x-appl/fake4');
   74 {   $SIG{__WARN__} = sub {$warn = join '',@_};
   75     $a->addType($r4);
   76 }
   77 ok(not defined $warn);
   78 
   79 my $r5a = MIME::Type->new(type => 'some/vnd.vendor');
   80 my $r5b = MIME::Type->new(type => 'some/prs.personal');
   81 my $r5c = MIME::Type->new(type => 'some/x.experimental');
   82 
   83 ok(!$r4 ->isVendor, 'is vendor');
   84 ok( $r5a->isVendor);
   85 ok(!$r5b->isVendor);
   86 ok(!$r5c->isVendor);
   87 
   88 ok(!$r4 ->isPersonal, 'is personal');
   89 ok(!$r5a->isPersonal);
   90 ok( $r5b->isPersonal);
   91 ok(!$r5c->isPersonal);
   92 
   93 ok(!$r4 ->isExperimental, 'is experimental');
   94 ok(!$r5a->isExperimental);
   95 ok(!$r5b->isExperimental);
   96 ok( $r5c->isExperimental);
   97 
   98 my $r6 = $a->type('application/vnd.openxmlformats-officedocument.wordprocessingml.document');
   99 ok($r6, 'type document');
  100 ok($r6->isBinary);
  101 ok(!$r6->isText);
  102 
  103 my $r7 = $a->type('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  104 ok($r7, 'type sheet');
  105 ok($r7->isBinary);
  106 ok(!$r7->isText);
  107 
  108 done_testing;