File: parse-mime.t

package info (click to toggle)
libparse-mime-perl 1.006-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 108 kB
  • sloc: perl: 118; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,265 bytes parent folder | download
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
use strict; use warnings;

use Test::More;
use JSON::PP 'decode_json';
use Parse::MIME ':all';

my $fixtures = decode_json do {
	chdir 't' or die "Couldn't chdir to t: $!\n";
	open my $fh, '<', 'fixtures.json' or die "Couldn't open fixtures: $!\n";
	local $/;
	readline $fh;
};

my $tests;
$tests += $_ for
	map +( ref eq 'HASH' ? 0+keys %$_ : 0+@$_ ),
	map +( ref eq 'HASH' ? $_ : map $_->{'testcases'}, @$_ ),
	values %$fixtures;

plan tests => $tests;

while ( my ( $mime, $parsed ) = each %{ $fixtures->{'parse_mime_type'} } ) {
	is_deeply [ parse_mime_type $mime ], $parsed, "parse_mime_type: $mime";
}

while ( my ( $range, $parsed ) = each %{ $fixtures->{'parse_media_range'} } ) {
	is_deeply [ parse_media_range $range ], $parsed, "parse_media_range: $range";
}

for my $group ( @{ $fixtures->{'quality'} } ) {
	my $accept = $group->{'accept'};
	while ( my ( $type, $quality ) = each %{ $group->{'testcases'} } ) {
		is quality( $type, $accept ), $quality, "quality: $type";
	}
}

for my $group ( @{ $fixtures->{'best_match'} } ) {
	my $mime_types_supported = $group->{'supported'};
	for my $case ( @{ $group->{'testcases'} } ) {
		my ( $range, $result, $desc ) = @$case;
		is best_match( $mime_types_supported, $range ), $result, "best_match: $desc";
	}
}