"Fossies" - the Fresh Open Source Software Archive

Member "MIME-Types-2.22/t/30export.t" (9 Dec 2020, 2220 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.

    1 #!/usr/bin/env perl
    2 #
    3 # Test exported interface.
    4 # Tests originally by Jeff Okamato
    5 #
    6 
    7 use Test::More;
    8 use strict;
    9 
   10 use lib qw(. t);
   11 
   12 BEGIN {plan tests => 40}
   13 
   14 use MIME::Types;
   15 
   16 #
   17 # These tests assume you want an array returned
   18 #
   19 
   20 my ($mt, $cte) = MIME::Types::by_suffix("Pdf");
   21 is($mt, "application/pdf");
   22 is($cte, "base64");
   23 
   24 ($mt, $cte) = MIME::Types::by_suffix("foo.Pdf");
   25 is($mt, "application/pdf");
   26 is($cte, "base64");
   27 
   28 ($mt, $cte) = MIME::Types::by_suffix("flurfl");
   29 is($mt, "");
   30 is($cte, "");
   31 
   32 #pkcs7-mime          p7m,p7c
   33 
   34 my @c = MIME::Types::by_mediatype("pkcs7-mime");
   35 cmp_ok(scalar @c, '==', 2);
   36 cmp_ok(scalar @{$c[0]}, '>', 2);
   37 is($c[0]->[0], "p7m");
   38 is($c[0]->[1], "application/pkcs7-mime");
   39 is($c[0]->[2], "base64");
   40 cmp_ok(scalar @{$c[1]}, '>', 2);
   41 is($c[1]->[0], "p7c");
   42 is($c[1]->[1], "application/pkcs7-mime");
   43 is($c[1]->[2], "base64");
   44 
   45 @c = MIME::Types::by_mediatype("Application/pDF");
   46 cmp_ok(scalar @c, '<', 2);
   47 cmp_ok(scalar @{$c[0]}, '==', 3);
   48 is($c[0]->[0], "pdf");
   49 is($c[0]->[1], "application/pdf");
   50 is($c[0]->[2], "base64");
   51 
   52 @c = MIME::Types::by_mediatype("e");
   53 cmp_ok(scalar @c, '>', 1);
   54 
   55 @c = MIME::Types::by_mediatype("xyzzy");
   56 cmp_ok(scalar @c, '==', 0);
   57 
   58 #
   59 # These tests assume you want an array reference returned
   60 #
   61 
   62 my $aref = MIME::Types::by_suffix("Pdf");
   63 is($aref->[0], "application/pdf");
   64 is($aref->[1], "base64");
   65 
   66 $aref = MIME::Types::by_suffix("foo.Pdf");
   67 is($aref->[0], "application/pdf");
   68 is($aref->[1], "base64");
   69 
   70 $aref = MIME::Types::by_suffix("flurfl");
   71 is($aref->[0], "");
   72 is($aref->[1], "");
   73 
   74 $aref = MIME::Types::by_mediatype(qr!/zip!);
   75 cmp_ok(scalar @$aref, '==', 1);
   76 #use Data::Dumper;
   77 #warn Dumper $aref;
   78 is($aref->[0]->[0], "zip");
   79 is($aref->[0]->[1], "application/zip");
   80 is($aref->[0]->[2], "base64");
   81 
   82 $aref = MIME::Types::by_mediatype("Application/pDF");
   83 cmp_ok(scalar @$aref, '==', 1);
   84 is($aref->[0]->[0], "pdf");
   85 is($aref->[0]->[1], "application/pdf");
   86 is($aref->[0]->[2], "base64");
   87 
   88 $aref = MIME::Types::by_mediatype("e");
   89 cmp_ok(scalar @$aref, '>', 1);
   90 
   91 $aref = MIME::Types::by_mediatype("xyzzy");
   92 cmp_ok(scalar @$aref, '==', 0);
   93 
   94 $aref = MIME::Types::by_suffix("foo.tsv");
   95 is($aref->[0], "text/tab-separated-values");
   96 is($aref->[1], "quoted-printable");