9
".class { border: 1px solid; } a { text-decoration: none; }" => 'text/css',
10
'[% PROCESS Padre %]' => 'text/x-perltt',
11
'#!/bin/bash' => 'application/x-shellscript',
12
'<html><head><title>Padre</title></head></html>' => 'text/html',
13
'=begin pod' => 'application/x-perl6',
14
'use v6;' => 'application/x-perl6',
15
'use strict; sub foo { 1; } my $self = split(/y/,$ENV{foo}));' => 'application/x-perl',
16
"function lua_fct()\n\t--[[This\n\tis\n\ta\ncomment\n\t]]--repeat\nend\n" => 'text/x-lua',
20
'foo.pl' => 'application/x-perl',
21
'bar.p6' => 'application/x-perl6',
22
'style.css' => 'text/css',
23
'index.tt' => 'text/x-perltt',
24
'main.c' => 'text/x-c',
25
'oop.cpp' => 'text/x-c++src',
26
'patch.diff' => 'text/x-patch',
27
'index.html' => 'text/html',
28
'index.htm' => 'text/html',
29
'script.js' => 'application/javascript',
30
'config.php' => 'application/x-php',
31
'form.rb' => 'application/x-ruby',
32
'foo.bar' => 'text/plain',
35
my %existing_test_files = (
36
'broken.bin' => undef, # regression test for ticket #900
37
'lexical_replace_stress_test.pl' => 'application/x-perl',
40
my @files = File::Find::Rule->relative->file->name('*.pm')->in('lib');
42
plan( tests => ( 2 * @files ) + 1
43
+ scalar( keys(%test_texts) )
44
+ scalar( keys(%test_files) )
45
+ scalar( keys(%existing_test_files) ) );
47
use_ok('Padre::MimeTypes');
49
# Fake installed Perl6 plugin
50
Padre::MimeTypes->add_mime_class( 'application/x-perl6', __PACKAGE__ );
52
# All Padre modules should be Perl files and Padre should be able to detect his own files
53
foreach my $file (@files) {
57
my $text = slurp($file);
59
is( Padre::MimeTypes->guess_mimetype( $text, $file ), 'application/x-perl', $file . ' with filename' );
60
is( Padre::MimeTypes->guess_mimetype( $text, '' ), 'application/x-perl', $file . ' without filename' );
63
# Some fixed test texts
64
foreach my $text ( sort( keys(%test_texts) ) ) {
65
is( Padre::MimeTypes->guess_mimetype( $text, '' ), $test_texts{$text}, $test_texts{$text} );
68
# Some fixed test filenames
69
foreach my $file ( sort( keys(%test_files) ) ) {
70
is( Padre::MimeTypes->guess_mimetype( '', $file ), $test_files{$file}, $file );
73
# Some files that actually exist on-disk
74
foreach my $file ( sort keys %existing_test_files ) {
75
my $text = slurp("xt/files/$file");
77
require Padre::Locale;
78
my $encoding = Padre::Locale::encoding_from_string($text);
79
$text = Encode::decode( $encoding, $text );
81
is( Padre::MimeTypes->guess_mimetype( $text, '' ), $existing_test_files{$file}, $file . ' without filename' );
85
######################################################################
90
open my $fh, '<', $file or die $! . ' for ' . $file;