File: 01type.t

package info (click to toggle)
libfile-type-webimages-perl 1.01-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 104 kB
  • sloc: perl: 128; makefile: 2
file content (54 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w
use strict;

use lib './lib','../lib';

use File::Type::WebImages;
use Test::More 'no_plan';

=for testing

Set up a list of files to test.

=cut

my $types = {
  "files/blank.jpg" => "image/jpeg",
  "files/blank.png" => "image/png",
  "files/blank.gif"  => "image/gif",
  "files/blank.bmp"  => "image/bmp",
};

=for testing

Initialise the object.

=cut

=for testing

Loop over the objects, testing each both ways.

=cut

for my $filename (sort keys %$types) {
  my $mimetype = $types->{$filename};
  is(File::Type::WebImages::checktype_filename("t/$filename"), $mimetype, "check file $filename");
  my $data = read_file("t/$filename") || die;
  is(File::Type::WebImages::checktype_contents($data), $mimetype, "check data $filename");
}

# edge cases
is(File::Type::WebImages::checktype_contents(undef) , undef , "checktype_contents(undef) returns undef");
is(File::Type::WebImages::checktype_contents('')    , undef , "checktype_contents('') returns undef");

sub read_file {
  my $file = shift;

  local $/ = undef;
  open FILE, $file or die "Can't open file $file: $!";
  my $data = <FILE>;
  close FILE;
  
  return $data;
}