summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorbeatrice <beatrice@dangofactory.net>2026-11-22 20:01:32 +0900
committerbeatrice <beatrice@dangofactory.net>2026-11-22 20:01:32 +0900
commit34d8a1931452210c27180b244ec56bbc7ff5c431 (patch)
tree8b8a15a2c32937675be1c58bb79ed8344a2f12b8 /t
downloadFile-MMagic-master.tar.gz
File-MMagic-master.zip
Import File-MMagic-1.30.tar.gzHEADlocal/File-MMagicmaster
Diffstat (limited to 't')
-rw-r--r--t/01-selfcheck.t13
-rw-r--r--t/02-extmagic.t14
-rw-r--r--t/03-typecheck.t19
-rw-r--r--t/04-string-mod.t19
-rw-r--r--t/05-subclass.t13
-rw-r--r--t/06-conthook.t19
-rw-r--r--t/07-contents.t14
-rw-r--r--t/test-magic1
-rw-r--r--t/test.html7
9 files changed, 119 insertions, 0 deletions
diff --git a/t/01-selfcheck.t b/t/01-selfcheck.t
new file mode 100644
index 0000000..46c1fbd
--- /dev/null
+++ b/t/01-selfcheck.t
@@ -0,0 +1,13 @@
+# perl-test
+# $Id: 01-selfcheck.t 182 2003-11-21 02:25:52Z knok $
+
+use strict;
+use Test;
+
+BEGIN { plan tests => 1 };
+
+use File::MMagic;
+
+my $magic = File::MMagic->new();
+my $ret = $magic->checktype_filename('t/01-selfcheck.t');
+ok($ret eq 'text/plain');
diff --git a/t/02-extmagic.t b/t/02-extmagic.t
new file mode 100644
index 0000000..6c453e1
--- /dev/null
+++ b/t/02-extmagic.t
@@ -0,0 +1,14 @@
+# perl-test
+# $Id: 02-extmagic.t 182 2003-11-21 02:25:52Z knok $
+
+use strict;
+use Test;
+
+BEGIN { plan tests => 1 };
+
+use File::MMagic;
+
+my $magic = File::MMagic->new();
+$magic->addMagicEntry("0\tstring\t#\\ perl-test\tapplication/x-perl-test");
+my $ret = $magic->checktype_filename('t/02-extmagic.t');
+ok($ret eq 'application/x-perl-test');
diff --git a/t/03-typecheck.t b/t/03-typecheck.t
new file mode 100644
index 0000000..fd7566a
--- /dev/null
+++ b/t/03-typecheck.t
@@ -0,0 +1,19 @@
+# perl-test
+# $Id: 03-typecheck.t 182 2003-11-21 02:25:52Z knok $
+
+use strict;
+use Test;
+
+BEGIN { plan tests => 2 };
+
+use File::MMagic;
+
+my $dir = -d 't' ? 't/' : '';
+
+
+my $m1 = File::MMagic->new();
+my $ret = $m1->checktype_filename($dir . 'test.html');
+ok($ret eq 'text/html');
+my $m2 = new File::MMagic;
+$ret = $m2->checktype_filename($dir . 'test.html');
+ok($ret eq 'text/html');
diff --git a/t/04-string-mod.t b/t/04-string-mod.t
new file mode 100644
index 0000000..80bdf5e
--- /dev/null
+++ b/t/04-string-mod.t
@@ -0,0 +1,19 @@
+# perl-test
+# $Id: 04-string-mod.t 187 2005-07-29 05:55:40Z knok $
+
+use strict;
+use Test;
+
+BEGIN { plan tests => 2 };
+
+use File::MMagic;
+
+my $dir = -d 't' ? 't/' : '';
+
+
+my $m1 = File::MMagic->new($dir . 'test-magic');
+my $ret = $m1->checktype_filename($dir . 'test.html');
+ok($ret eq 'text/html');
+my $m2 = File::MMagic->new();
+$ret = $m2->checktype_filename($dir . 'test.html');
+ok($ret eq 'text/html');
diff --git a/t/05-subclass.t b/t/05-subclass.t
new file mode 100644
index 0000000..8a07638
--- /dev/null
+++ b/t/05-subclass.t
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+my $mm = Example::Module->new();
+isa_ok( $mm, 'Example::Module', 'subclassed object' );
+isa_ok( $mm, 'File::MMagic', 'subclassed object' );
+is( $mm->checktype_filename(), 'foo/bar', 'override method' );
+
+package Example::Module;
+use base qw( File::MMagic );
+
+sub checktype_filename { 'foo/bar' }
diff --git a/t/06-conthook.t b/t/06-conthook.t
new file mode 100644
index 0000000..a7c3cdd
--- /dev/null
+++ b/t/06-conthook.t
@@ -0,0 +1,19 @@
+# perl-test
+# $Id$
+
+use strict;
+use Test;
+
+BEGIN { plan tests => 1 };
+
+use File::MMagic;
+
+my $ans = "text/plain; conthook";
+my $magic = File::MMagic->new();
+$magic->addContainerHook($ans, sub {
+ my $self = shift;
+ my $data = shift;
+ return "text/plain; conthook" if $data =~ /conthook/;
+ return ""; });
+my $ret = $magic->checktype_container('text conthook');
+ok($ret eq $ans);
diff --git a/t/07-contents.t b/t/07-contents.t
new file mode 100644
index 0000000..0517661
--- /dev/null
+++ b/t/07-contents.t
@@ -0,0 +1,14 @@
+# perl-test
+# $Id$
+
+use strict;
+use Test;
+
+BEGIN { plan tests => 1 };
+
+use File::MMagic;
+
+my $ans = "text/plain";
+my $magic = File::MMagic->new();
+my $ret = $magic->checktype_contents('text conthook');
+ok($ret eq $ans);
diff --git a/t/test-magic b/t/test-magic
new file mode 100644
index 0000000..0fbde89
--- /dev/null
+++ b/t/test-magic
@@ -0,0 +1 @@
+0 string/cB \<!DOCTYPE\ html text/html
diff --git a/t/test.html b/t/test.html
new file mode 100644
index 0000000..bd2b710
--- /dev/null
+++ b/t/test.html
@@ -0,0 +1,7 @@
+<html>
+<head>
+</head>
+<body>
+A test file
+</body>
+</html>