File: whatwg-aliases.t

package info (click to toggle)
libencode-perl 3.08-1%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,208 kB
  • sloc: perl: 4,395; ansic: 1,077; makefile: 8
file content (66 lines) | stat: -rw-r--r-- 1,539 bytes parent folder | download | duplicates (3)
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
55
56
57
58
59
60
61
62
63
64
65
66
# This test checks aliases support based on the list in the
# WHATWG Encoding Living Standard
#
# https://encoding.spec.whatwg.org/
#
# The input of this test is the file whatwg-aliases.json downloaded from
# https://encoding.spec.whatwg.org/encodings.json
#
# To run:
#   AUTHOR_TESTING=1 prove -l t/whatwg-aliases.t


use Test::More
    $ENV{AUTHOR_TESTING}
    ? 'no_plan'
    : (skip_all => 'For maintainers only');
use Encode 'find_encoding';
use JSON::PP 'decode_json';
use File::Spec;
use FindBin;

my $encodings = decode_json(do {
    # https://encoding.spec.whatwg.org/encodings.json
    open my $f, '<', File::Spec->catdir($FindBin::Bin, 'whatwg-aliases.json');
    local $/;
    <$f>
});

my %IGNORE = map { $_ => '' } qw(
    replacement
    utf8
);

my %TODO = (
    'ISO-8859-8-I'   => 'Not supported',
    'gb18030'        => 'Not supported',
    '866'            => 'Not supported',
    'x-user-defined' => 'Not supported',
    # ...
);

for my $section (@$encodings) {
    for my $enc (@{$section->{encodings}}) {

	my $name = $enc->{name};

	next if exists $IGNORE{$name};

	local $TODO = $TODO{$name} if exists $TODO{$name};

	my $encoding = find_encoding($name);
	isa_ok($encoding, 'Encode::Encoding', $name);

	for my $label (@{$enc->{labels}}) {
	    local $TODO = $TODO{$label} if exists $TODO{$label};

	    my $e = find_encoding($label);
	    if (isa_ok($e, 'Encode::Encoding', $label)) {
		next if exists $IGNORE{$label};
		is($e->name, $encoding->name, "$label ->name is $name")
	    }
	}
    }
}

done_testing;