Re-enable disabled emoji tests
Since Ib68f803c6adfb41db70f7319b7736d17cdbb6ec2 updates the emoji
data to version 4.0 beta, we can now re-enable the disabled emoji
tests.
Also fix some style issues, update data file parsing method to handle
the new emoji format, add UN to unsupported flags, and do a little
refactoring.
Bug: 26187231
Change-Id: I441fdfed68381d08e5e0b3af91e94bfae742eef6
diff --git a/tools/fonts/fontchain_lint.py b/tools/fonts/fontchain_lint.py
index 1dd53a9..bbac83c 100755
--- a/tools/fonts/fontchain_lint.py
+++ b/tools/fonts/fontchain_lint.py
@@ -256,8 +256,8 @@
def check_emoji_coverage(all_emoji, equivalent_emoji):
- emoji_font = get_emoji_font()
- check_emoji_font_coverage(emoji_font, all_emoji, equivalent_emoji)
+ emoji_font = get_emoji_font()
+ check_emoji_font_coverage(emoji_font, all_emoji, equivalent_emoji)
def get_emoji_font():
@@ -274,15 +274,12 @@
assert sequence in coverage, (
'%s is not supported in the emoji font.' % printable(sequence))
- # disable temporarily - we cover more than this
- """
for sequence in coverage:
if sequence in {0x0000, 0x000D, 0x0020}:
# The font needs to support a few extra characters, which is OK
continue
assert sequence in all_emoji, (
'Emoji font should not support %s.' % printable(sequence))
- """
for first, second in sorted(equivalent_emoji.items()):
assert coverage[first] == coverage[second], (
@@ -290,8 +287,6 @@
printable(first),
printable(second)))
- # disable temporarily - some equivalent sequences we don't even know about
- """
for glyph in set(coverage.values()):
maps_to_glyph = [seq for seq in coverage if coverage[seq] == glyph]
if len(maps_to_glyph) > 1:
@@ -307,7 +302,7 @@
'The sequences %s should not result in the same glyph %s' % (
printable(equivalent_seqs),
glyph))
- """
+
def check_emoji_defaults(default_emoji):
missing_text_chars = _emoji_properties['Emoji'] - default_emoji
@@ -342,7 +337,8 @@
0x2764, # HEAVY BLACK HEART
}
assert missing_text_chars == set(), (
- 'Text style version of some emoji characters are missing: ' + repr(missing_text_chars))
+ 'Text style version of some emoji characters are missing: ' +
+ repr(missing_text_chars))
# Setting reverse to true returns a dictionary that maps the values to sets of
@@ -362,7 +358,7 @@
if not line:
continue
- chars, prop = line.split(';')
+ chars, prop = line.split(';')[:2]
chars = chars.strip()
prop = prop.strip()
@@ -424,16 +420,6 @@
path.join(ucd_path, 'emoji-zwj-sequences.txt'))
- # add in UN flag
- UN_seq = flag_sequence('UN')
- _emoji_sequences[UN_seq] = 'Emoji_Flag_Sequence'
-
-
- # add in UN flag
- UN_seq = flag_sequence('UN')
- _emoji_sequences[UN_seq] = 'Emoji_Flag_Sequence'
-
-
def flag_sequence(territory_code):
return tuple(0x1F1E6 + ord(ch) - ord('A') for ch in territory_code)
@@ -444,7 +430,8 @@
flag_sequence('GF'), flag_sequence('GP'), flag_sequence('GS'),
flag_sequence('MF'), flag_sequence('MQ'), flag_sequence('NC'),
flag_sequence('PM'), flag_sequence('RE'), flag_sequence('TF'),
- flag_sequence('WF'), flag_sequence('XK'), flag_sequence('YT'),
+ flag_sequence('UN'), flag_sequence('WF'), flag_sequence('XK'),
+ flag_sequence('YT'),
})
EQUIVALENT_FLAGS = {
@@ -492,7 +479,17 @@
def is_fitzpatrick_modifier(cp):
- return 0x1f3fb <= cp <= 0x1f3ff
+ return 0x1F3FB <= cp <= 0x1F3FF
+
+
+def reverse_emoji(seq):
+ rev = list(reversed(seq))
+ # if there are fitzpatrick modifiers in the sequence, keep them after
+ # the emoji they modify
+ for i in xrange(1, len(rev)):
+ if is_fitzpatrick_modifier(rev[i-1]):
+ rev[i], rev[i-1] = rev[i-1], rev[i]
+ return tuple(rev)
def compute_expected_emoji():
@@ -512,15 +509,7 @@
sequence_pieces.update(sequence)
# Add reverse of all emoji ZWJ sequences, which are added to the fonts
# as a workaround to get the sequences work in RTL text.
- reversed_seq = list(reversed(sequence))
- # if there are fitzpatrick modifiers in the sequence, keep them after
- # the emoji they modify
- for i in xrange(1, len(reversed_seq)):
- if is_fitzpatrick_modifier(reversed_seq[i - 1]):
- tmp = reversed_seq[i]
- reversed_seq[i] = reversed_seq[i-1]
- reversed_seq[i-1] = tmp
- reversed_seq = tuple(reversed_seq)
+ reversed_seq = reverse_emoji(sequence)
all_sequences.add(reversed_seq)
equivalent_emoji[reversed_seq] = sequence