Version bump.
[librarian.git] / librarian / font-optimizer / t / subsetter.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More qw(no_plan);
7
8 use lib 'ext/Font-TTF/lib';
9 use Font::Subsetter;
10 use Unicode::Normalize;
11
12 # Test that we include characters needed for strings converted to NFC
13 for my $str (
14     "i",
15     "\xec",
16     "i\x{0300}",
17     "\x{0300}i",
18     "\x{03b9}\x{0308}\x{0301}", # iota, combining diaeresis, combining acute
19     "s\x{0323}\x{0307}", # s, combining dot below, combining dot above
20     "s\x{0307}\x{0323}", # s, combining dot above, combining dot below
21     "\x{1e61}\x{0323}", # s with dot above, combining dot below
22     "\x{1e63}\x{0307}", # s with dot below, combining dot above
23     "\x{212b}", # angstrom
24 ) {
25     my $subsetter = new Font::Subsetter;
26     my %chars = $subsetter->expand_wanted_chars($str);
27     for (map ord, split //, $str) {
28         ok($chars{$_}, "char ".(sprintf '%04x', $_)." in string '".(join ' ', map { sprintf '%04x', $_ } unpack 'U*', $str)."'");
29     }
30     for (map ord, split //, Unicode::Normalize::NFC($str)) {
31         ok($chars{$_}, "NFC char ".(sprintf '%04x', $_)." in string '".(join ' ', map { sprintf '%04x', $_ } unpack 'U*', $str)."'");
32     }
33 }
34
35 # Test that spurious characters aren't included
36 for my $str (
37     "a\xec",
38 ) {
39     my $subsetter = new Font::Subsetter;
40     my %chars = $subsetter->expand_wanted_chars($str);
41     my %exp;
42     $exp{$_} = 1 for map ord, split //, $str;
43     $exp{$_} = 1 for map ord, split //, Unicode::Normalize::NFC($str);
44     for (sort keys %chars) {
45         ok($exp{$_}, "expected char ".(sprintf '%04x', $_)." from string '".(join ' ', map { sprintf '%04x', $_ } unpack 'U*', $str)."'");
46     }
47 }