Debian Codegraph @

tests/test_routine_partition.py

raw
1 from fontFeatures import Substitution, FontFeatures, Routine, Chaining, RoutineReference
2
3 import pytest
4
5
6 def test_routine_partition():
7 f = FontFeatures()
8
9 s1 = Substitution([["A"]], [["A.grk"]], languages=["grek/*"])
10 s2 = Substitution([["A"]], [["A.esp"]], languages=["latn/ESP "])
11 r = Routine(rules=[s1, s2], flags=0x2)
12
13 f.routines.append(r)
14
15 dummy = Routine(rules=[Substitution([["G"]], [["G"]])])
16 f.routines.append(dummy)
17
18 c = Chaining(
19 [["A"], ["V"]],
20 lookups=[
21 [RoutineReference(routine=dummy), RoutineReference(routine=r)],
22 [RoutineReference(routine=r), RoutineReference(routine=dummy)],
23 ],
24 )
25 r2 = Routine(rules=[c])
26 f.routines.append(r2)
27
28 f.addFeature("locl", [r])
29
30 f.partitionRoutine(r, lambda rule: tuple(rule.languages or []))
31
32 assert len(f.routines) == 4
33 assert f.routines[0].flags == f.routines[1].flags
34 assert len(f.routines[0].rules) == 1
35 assert len(f.routines[1].rules) == 1
36 assert f.routines[0].rules[0].replacement[0][0] == "A.grk"
37 assert f.routines[1].rules[0].replacement[0][0] == "A.esp"
38
39 assert len(c.lookups[0]) == 3
40 assert len(f.features["locl"]) == 2
41
42
43 def test_routine_partition_not_needed():
44 f = FontFeatures()
45
46 s1 = Substitution([["A"]], [["A.grk"]], languages=["grek/*"])
47 s2 = Substitution([["A"]], [["A.esp"]], languages=["grek/*"])
48 r = Routine(rules=[s1, s2], flags=0x2)
49
50 f.routines.append(r)
51 f.partitionRoutine(r, lambda rule: tuple(rule.languages or []))
52
53 assert len(f.routines) == 1
54
55 r.rules = []
56 f.partitionRoutine(r, lambda rule: tuple(rule.languages or []))
57 assert len(f.routines) == 1