-
Notifications
You must be signed in to change notification settings - Fork 448
/
parser_test.py
1948 lines (1729 loc) · 84.6 KB
/
parser_test.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
from fontTools.misc.loggingTools import CapturingLogHandler
from fontTools.feaLib.error import FeatureLibError
from fontTools.feaLib.parser import Parser, SymbolTable
from io import StringIO
import warnings
import fontTools.feaLib.ast as ast
import os
import unittest
def glyphstr(glyphs):
def f(x):
if len(x) == 1:
return list(x)[0]
else:
return '[%s]' % ' '.join(sorted(list(x)))
return ' '.join(f(g.glyphSet()) for g in glyphs)
def mapping(s):
b = []
for a in s.glyphs:
b.extend(a.glyphSet())
c = []
for a in s.replacements:
c.extend(a.glyphSet())
if len(c) == 1:
c = c * len(b)
return dict(zip(b, c))
GLYPHNAMES = ("""
.notdef space A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
A.sc B.sc C.sc D.sc E.sc F.sc G.sc H.sc I.sc J.sc K.sc L.sc M.sc
N.sc O.sc P.sc Q.sc R.sc S.sc T.sc U.sc V.sc W.sc X.sc Y.sc Z.sc
A.swash B.swash X.swash Y.swash Z.swash
a b c d e f g h i j k l m n o p q r s t u v w x y z
a.sc b.sc c.sc d.sc e.sc f.sc g.sc h.sc i.sc j.sc k.sc l.sc m.sc
n.sc o.sc p.sc q.sc r.sc s.sc t.sc u.sc v.sc w.sc x.sc y.sc z.sc
a.swash b.swash x.swash y.swash z.swash
foobar foo.09 foo.1234 foo.9876
one two five six acute grave dieresis umlaut cedilla ogonek macron
a_f_f_i o_f_f_i f_i f_f_i one.fitted one.oldstyle a.1 a.2 a.3 c_t
PRE SUF FIX BACK TRACK LOOK AHEAD ampersand ampersand.1 ampersand.2
cid00001 cid00002 cid00003 cid00004 cid00005 cid00006 cid00007
cid12345 cid78987 cid00999 cid01000 cid01001 cid00998 cid00995
cid00111 cid00222
comma endash emdash figuredash damma hamza
c_d d.alt n.end s.end f_f
""").split() + ["foo.%d" % i for i in range(1, 200)]
class ParserTest(unittest.TestCase):
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)
# Python 3 renamed assertRaisesRegexp to assertRaisesRegex,
# and fires deprecation warnings if a program uses the old name.
if not hasattr(self, "assertRaisesRegex"):
self.assertRaisesRegex = self.assertRaisesRegexp
def test_glyphMap_deprecated(self):
glyphMap = {'a': 0, 'b': 1, 'c': 2}
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
parser = Parser(StringIO(), glyphMap=glyphMap)
self.assertEqual(len(w), 1)
self.assertEqual(w[-1].category, UserWarning)
self.assertIn("deprecated", str(w[-1].message))
self.assertEqual(parser.glyphNames_, {'a', 'b', 'c'})
self.assertRaisesRegex(
TypeError, "mutually exclusive",
Parser, StringIO(), ("a",), glyphMap={"a": 0})
self.assertRaisesRegex(
TypeError, "unsupported keyword argument",
Parser, StringIO(), foo="bar")
def test_comments(self):
doc = self.parse(
""" # Initial
feature test {
sub A by B; # simple
} test;""")
c1 = doc.statements[0]
c2 = doc.statements[1].statements[1]
self.assertEqual(type(c1), ast.Comment)
self.assertEqual(c1.text, "# Initial")
self.assertEqual(str(c1), "# Initial")
self.assertEqual(type(c2), ast.Comment)
self.assertEqual(c2.text, "# simple")
self.assertEqual(doc.statements[1].name, "test")
def test_only_comments(self):
doc = self.parse("""\
# Initial
""")
c1 = doc.statements[0]
self.assertEqual(type(c1), ast.Comment)
self.assertEqual(c1.text, "# Initial")
self.assertEqual(str(c1), "# Initial")
def test_anchor_format_a(self):
doc = self.parse(
"feature test {"
" pos cursive A <anchor 120 -20> <anchor NULL>;"
"} test;")
anchor = doc.statements[0].statements[0].entryAnchor
self.assertEqual(type(anchor), ast.Anchor)
self.assertEqual(anchor.x, 120)
self.assertEqual(anchor.y, -20)
self.assertIsNone(anchor.contourpoint)
self.assertIsNone(anchor.xDeviceTable)
self.assertIsNone(anchor.yDeviceTable)
def test_anchor_format_b(self):
doc = self.parse(
"feature test {"
" pos cursive A <anchor 120 -20 contourpoint 5> <anchor NULL>;"
"} test;")
anchor = doc.statements[0].statements[0].entryAnchor
self.assertEqual(type(anchor), ast.Anchor)
self.assertEqual(anchor.x, 120)
self.assertEqual(anchor.y, -20)
self.assertEqual(anchor.contourpoint, 5)
self.assertIsNone(anchor.xDeviceTable)
self.assertIsNone(anchor.yDeviceTable)
def test_anchor_format_c(self):
doc = self.parse(
"feature test {"
" pos cursive A "
" <anchor 120 -20 <device 11 111, 12 112> <device NULL>>"
" <anchor NULL>;"
"} test;")
anchor = doc.statements[0].statements[0].entryAnchor
self.assertEqual(type(anchor), ast.Anchor)
self.assertEqual(anchor.x, 120)
self.assertEqual(anchor.y, -20)
self.assertIsNone(anchor.contourpoint)
self.assertEqual(anchor.xDeviceTable, ((11, 111), (12, 112)))
self.assertIsNone(anchor.yDeviceTable)
def test_anchor_format_d(self):
doc = self.parse(
"feature test {"
" pos cursive A <anchor 120 -20> <anchor NULL>;"
"} test;")
anchor = doc.statements[0].statements[0].exitAnchor
self.assertIsNone(anchor)
def test_anchor_format_e(self):
doc = self.parse(
"feature test {"
" anchorDef 120 -20 contourpoint 7 Foo;"
" pos cursive A <anchor Foo> <anchor NULL>;"
"} test;")
anchor = doc.statements[0].statements[1].entryAnchor
self.assertEqual(type(anchor), ast.Anchor)
self.assertEqual(anchor.x, 120)
self.assertEqual(anchor.y, -20)
self.assertEqual(anchor.contourpoint, 7)
self.assertIsNone(anchor.xDeviceTable)
self.assertIsNone(anchor.yDeviceTable)
def test_anchor_format_e_undefined(self):
self.assertRaisesRegex(
FeatureLibError, 'Unknown anchor "UnknownName"', self.parse,
"feature test {"
" position cursive A <anchor UnknownName> <anchor NULL>;"
"} test;")
def test_anchor_variable_scalar(self):
doc = self.parse(
"feature test {"
" pos cursive A <anchor (wght=200:-100 wght=900:-150 wght=900,wdth=150:-120) -20> <anchor NULL>;"
"} test;")
anchor = doc.statements[0].statements[0].entryAnchor
self.assertEqual(anchor.asFea(), "<anchor (wght=200:-100 wght=900:-150 wght=900,wdth=150:-120) -20>")
def test_anchordef(self):
[foo] = self.parse("anchorDef 123 456 foo;").statements
self.assertEqual(type(foo), ast.AnchorDefinition)
self.assertEqual(foo.name, "foo")
self.assertEqual(foo.x, 123)
self.assertEqual(foo.y, 456)
self.assertEqual(foo.contourpoint, None)
def test_anchordef_contourpoint(self):
[foo] = self.parse("anchorDef 123 456 contourpoint 5 foo;").statements
self.assertEqual(type(foo), ast.AnchorDefinition)
self.assertEqual(foo.name, "foo")
self.assertEqual(foo.x, 123)
self.assertEqual(foo.y, 456)
self.assertEqual(foo.contourpoint, 5)
def test_anon(self):
anon = self.parse("anon TEST { # a\nfoo\n } TEST; # qux").statements[0]
self.assertIsInstance(anon, ast.AnonymousBlock)
self.assertEqual(anon.tag, "TEST")
self.assertEqual(anon.content, "foo\n ")
def test_anonymous(self):
anon = self.parse("anonymous TEST {\nbar\n} TEST;").statements[0]
self.assertIsInstance(anon, ast.AnonymousBlock)
self.assertEqual(anon.tag, "TEST")
# feature file spec requires passing the final end-of-line
self.assertEqual(anon.content, "bar\n")
def test_anon_missingBrace(self):
self.assertRaisesRegex(
FeatureLibError, "Expected '} TEST;' to terminate anonymous block",
self.parse, "anon TEST { \n no end in sight")
def test_attach(self):
doc = self.parse("table GDEF {Attach [a e] 2;} GDEF;")
s = doc.statements[0].statements[0]
self.assertIsInstance(s, ast.AttachStatement)
self.assertEqual(glyphstr([s.glyphs]), "[a e]")
self.assertEqual(s.contourPoints, {2})
def test_feature_block(self):
[liga] = self.parse("feature liga {} liga;").statements
self.assertEqual(liga.name, "liga")
self.assertFalse(liga.use_extension)
def test_feature_block_useExtension(self):
[liga] = self.parse("feature liga useExtension {} liga;").statements
self.assertEqual(liga.name, "liga")
self.assertTrue(liga.use_extension)
self.assertEqual(liga.asFea(),
"feature liga useExtension {\n \n} liga;\n")
def test_feature_comment(self):
[liga] = self.parse("feature liga { # Comment\n } liga;").statements
[comment] = liga.statements
self.assertIsInstance(comment, ast.Comment)
self.assertEqual(comment.text, "# Comment")
def test_feature_reference(self):
doc = self.parse("feature aalt { feature salt; } aalt;")
ref = doc.statements[0].statements[0]
self.assertIsInstance(ref, ast.FeatureReferenceStatement)
self.assertEqual(ref.featureName, "salt")
def test_FeatureNames_bad(self):
self.assertRaisesRegex(
FeatureLibError, 'Expected "name"',
self.parse, "feature ss01 { featureNames { feature test; } ss01;")
def test_FeatureNames_comment(self):
[feature] = self.parse(
"feature ss01 { featureNames { # Comment\n }; } ss01;").statements
[featureNames] = feature.statements
self.assertIsInstance(featureNames, ast.NestedBlock)
[comment] = featureNames.statements
self.assertIsInstance(comment, ast.Comment)
self.assertEqual(comment.text, "# Comment")
def test_FeatureNames_emptyStatements(self):
[feature] = self.parse(
"feature ss01 { featureNames { ;;; }; } ss01;").statements
[featureNames] = feature.statements
self.assertIsInstance(featureNames, ast.NestedBlock)
self.assertEqual(featureNames.statements, [])
def test_FontRevision(self):
doc = self.parse("table head {FontRevision 2.5;} head;")
s = doc.statements[0].statements[0]
self.assertIsInstance(s, ast.FontRevisionStatement)
self.assertEqual(s.revision, 2.5)
def test_FontRevision_negative(self):
self.assertRaisesRegex(
FeatureLibError, "Font revision numbers must be positive",
self.parse, "table head {FontRevision -17.2;} head;")
def test_strict_glyph_name_check(self):
self.parse("@bad = [a b ccc];", glyphNames=("a", "b", "ccc"))
with self.assertRaisesRegex(FeatureLibError, "missing from the glyph set: ccc"):
self.parse("@bad = [a b ccc];", glyphNames=("a", "b"))
def test_glyphclass(self):
[gc] = self.parse("@dash = [endash emdash figuredash];").statements
self.assertEqual(gc.name, "dash")
self.assertEqual(gc.glyphSet(), ("endash", "emdash", "figuredash"))
def test_glyphclass_glyphNameTooLong(self):
self.assertRaisesRegex(
FeatureLibError, "must not be longer than 63 characters",
self.parse, "@GlyphClass = [%s];" % ("G" * 64))
def test_glyphclass_bad(self):
self.assertRaisesRegex(
FeatureLibError,
"Expected glyph name, glyph range, or glyph class reference",
self.parse, "@bad = [a 123];")
def test_glyphclass_duplicate(self):
# makeotf accepts this, so we should too
ab, xy = self.parse("@dup = [a b]; @dup = [x y];").statements
self.assertEqual(glyphstr([ab]), "[a b]")
self.assertEqual(glyphstr([xy]), "[x y]")
def test_glyphclass_empty(self):
[gc] = self.parse("@empty_set = [];").statements
self.assertEqual(gc.name, "empty_set")
self.assertEqual(gc.glyphSet(), tuple())
def test_glyphclass_equality(self):
[foo, bar] = self.parse("@foo = [a b]; @bar = @foo;").statements
self.assertEqual(foo.glyphSet(), ("a", "b"))
self.assertEqual(bar.glyphSet(), ("a", "b"))
def test_glyphclass_from_markClass(self):
doc = self.parse(
"markClass [acute grave] <anchor 500 800> @TOP_MARKS;"
"markClass cedilla <anchor 500 -100> @BOTTOM_MARKS;"
"@MARKS = [@TOP_MARKS @BOTTOM_MARKS ogonek];"
"@ALL = @MARKS;")
self.assertEqual(doc.statements[-1].glyphSet(),
("acute", "grave", "cedilla", "ogonek"))
def test_glyphclass_range_cid(self):
[gc] = self.parse(r"@GlyphClass = [\999-\1001];").statements
self.assertEqual(gc.name, "GlyphClass")
self.assertEqual(gc.glyphSet(), ("cid00999", "cid01000", "cid01001"))
def test_glyphclass_range_cid_bad(self):
self.assertRaisesRegex(
FeatureLibError,
"Bad range: start should be less than limit",
self.parse, r"@bad = [\998-\995];")
def test_glyphclass_range_uppercase(self):
[gc] = self.parse("@swashes = [X.swash-Z.swash];").statements
self.assertEqual(gc.name, "swashes")
self.assertEqual(gc.glyphSet(), ("X.swash", "Y.swash", "Z.swash"))
def test_glyphclass_range_lowercase(self):
[gc] = self.parse("@defg.sc = [d.sc-g.sc];").statements
self.assertEqual(gc.name, "defg.sc")
self.assertEqual(gc.glyphSet(), ("d.sc", "e.sc", "f.sc", "g.sc"))
def test_glyphclass_range_dash(self):
glyphNames = "A-foo.sc B-foo.sc C-foo.sc".split()
[gc] = self.parse("@range = [A-foo.sc-C-foo.sc];", glyphNames).statements
self.assertEqual(gc.glyphSet(), ("A-foo.sc", "B-foo.sc", "C-foo.sc"))
def test_glyphclass_range_dash_with_space(self):
gn = "A-foo.sc B-foo.sc C-foo.sc".split()
[gc] = self.parse("@range = [A-foo.sc - C-foo.sc];", gn).statements
self.assertEqual(gc.glyphSet(), ("A-foo.sc", "B-foo.sc", "C-foo.sc"))
def test_glyphclass_ambiguous_dash_no_glyph_names(self):
# If Parser is initialized without a glyphNames parameter (or with empty one)
# it cannot distinguish between a glyph name containing an hyphen, or a
# range of glyph names; thus it will interpret them as literal glyph names
# while also outputting a logging warning to alert user about the ambiguity.
# https://github.com/fonttools/fonttools/issues/1768
glyphNames = ()
with CapturingLogHandler("fontTools.feaLib.parser", level="WARNING") as caplog:
[gc] = self.parse("@class = [A-foo.sc B-foo.sc C D];", glyphNames).statements
self.assertEqual(gc.glyphSet(), ("A-foo.sc", "B-foo.sc", "C", "D"))
self.assertEqual(len(caplog.records), 2)
caplog.assertRegex("Ambiguous glyph name that looks like a range:")
def test_glyphclass_glyph_name_should_win_over_range(self):
# The OpenType Feature File Specification v1.20 makes it clear
# that if a dashed name could be interpreted either as a glyph name
# or as a range, then the semantics should be the single dashed name.
glyphNames = (
"A-foo.sc-C-foo.sc A-foo.sc B-foo.sc C-foo.sc".split())
[gc] = self.parse("@range = [A-foo.sc-C-foo.sc];", glyphNames).statements
self.assertEqual(gc.glyphSet(), ("A-foo.sc-C-foo.sc",))
def test_glyphclass_range_dash_ambiguous(self):
glyphNames = "A B C A-B B-C".split()
self.assertRaisesRegex(
FeatureLibError,
'Ambiguous glyph range "A-B-C"; '
'please use "A - B-C" or "A-B - C" to clarify what you mean',
self.parse, r"@bad = [A-B-C];", glyphNames)
def test_glyphclass_range_digit1(self):
[gc] = self.parse("@range = [foo.2-foo.5];").statements
self.assertEqual(gc.glyphSet(), ("foo.2", "foo.3", "foo.4", "foo.5"))
def test_glyphclass_range_digit2(self):
[gc] = self.parse("@range = [foo.09-foo.11];").statements
self.assertEqual(gc.glyphSet(), ("foo.09", "foo.10", "foo.11"))
def test_glyphclass_range_digit3(self):
[gc] = self.parse("@range = [foo.123-foo.125];").statements
self.assertEqual(gc.glyphSet(), ("foo.123", "foo.124", "foo.125"))
def test_glyphclass_range_bad(self):
self.assertRaisesRegex(
FeatureLibError,
"Bad range: \"a\" and \"foobar\" should have the same length",
self.parse, "@bad = [a-foobar];")
self.assertRaisesRegex(
FeatureLibError, "Bad range: \"A.swash-z.swash\"",
self.parse, "@bad = [A.swash-z.swash];")
self.assertRaisesRegex(
FeatureLibError, "Start of range must be smaller than its end",
self.parse, "@bad = [B.swash-A.swash];")
self.assertRaisesRegex(
FeatureLibError, "Bad range: \"foo.1234-foo.9876\"",
self.parse, "@bad = [foo.1234-foo.9876];")
def test_glyphclass_range_mixed(self):
[gc] = self.parse("@range = [a foo.09-foo.11 X.sc-Z.sc];").statements
self.assertEqual(gc.glyphSet(), (
"a", "foo.09", "foo.10", "foo.11", "X.sc", "Y.sc", "Z.sc"
))
def test_glyphclass_reference(self):
[vowels_lc, vowels_uc, vowels] = self.parse(
"@Vowels.lc = [a e i o u]; @Vowels.uc = [A E I O U];"
"@Vowels = [@Vowels.lc @Vowels.uc y Y];").statements
self.assertEqual(vowels_lc.glyphSet(), tuple("aeiou"))
self.assertEqual(vowels_uc.glyphSet(), tuple("AEIOU"))
self.assertEqual(vowels.glyphSet(), tuple("aeiouAEIOUyY"))
self.assertEqual(vowels.asFea(),
"@Vowels = [@Vowels.lc @Vowels.uc y Y];")
self.assertRaisesRegex(
FeatureLibError, "Unknown glyph class @unknown",
self.parse, "@bad = [@unknown];")
def test_glyphclass_scoping(self):
[foo, liga, smcp] = self.parse(
"@foo = [a b];"
"feature liga { @bar = [@foo l]; } liga;"
"feature smcp { @bar = [@foo s]; } smcp;"
).statements
self.assertEqual(foo.glyphSet(), ("a", "b"))
self.assertEqual(liga.statements[0].glyphSet(), ("a", "b", "l"))
self.assertEqual(smcp.statements[0].glyphSet(), ("a", "b", "s"))
def test_glyphclass_scoping_bug496(self):
# https://github.com/fonttools/fonttools/issues/496
f1, f2 = self.parse(
"feature F1 { lookup L { @GLYPHCLASS = [A B C];} L; } F1;"
"feature F2 { sub @GLYPHCLASS by D; } F2;"
).statements
self.assertEqual(list(f2.statements[0].glyphs[0].glyphSet()),
["A", "B", "C"])
def test_GlyphClassDef(self):
doc = self.parse("table GDEF {GlyphClassDef [b],[l],[m],[C c];} GDEF;")
s = doc.statements[0].statements[0]
self.assertIsInstance(s, ast.GlyphClassDefStatement)
self.assertEqual(glyphstr([s.baseGlyphs]), "b")
self.assertEqual(glyphstr([s.ligatureGlyphs]), "l")
self.assertEqual(glyphstr([s.markGlyphs]), "m")
self.assertEqual(glyphstr([s.componentGlyphs]), "[C c]")
def test_GlyphClassDef_noCLassesSpecified(self):
doc = self.parse("table GDEF {GlyphClassDef ,,,;} GDEF;")
s = doc.statements[0].statements[0]
self.assertIsNone(s.baseGlyphs)
self.assertIsNone(s.ligatureGlyphs)
self.assertIsNone(s.markGlyphs)
self.assertIsNone(s.componentGlyphs)
def test_ignore_pos(self):
doc = self.parse("feature test {ignore pos e t' c, q u' u' x;} test;")
sub = doc.statements[0].statements[0]
self.assertIsInstance(sub, ast.IgnorePosStatement)
[(pref1, glyphs1, suff1), (pref2, glyphs2, suff2)] = sub.chainContexts
self.assertEqual(glyphstr(pref1), "e")
self.assertEqual(glyphstr(glyphs1), "t")
self.assertEqual(glyphstr(suff1), "c")
self.assertEqual(glyphstr(pref2), "q")
self.assertEqual(glyphstr(glyphs2), "u u")
self.assertEqual(glyphstr(suff2), "x")
def test_ignore_position(self):
doc = self.parse(
"feature test {"
" ignore position f [a e] d' [a u]' [e y];"
"} test;")
sub = doc.statements[0].statements[0]
self.assertIsInstance(sub, ast.IgnorePosStatement)
[(prefix, glyphs, suffix)] = sub.chainContexts
self.assertEqual(glyphstr(prefix), "f [a e]")
self.assertEqual(glyphstr(glyphs), "d [a u]")
self.assertEqual(glyphstr(suffix), "[e y]")
def test_ignore_position_with_lookup(self):
self.assertRaisesRegex(
FeatureLibError,
'No lookups can be specified for "ignore pos"',
self.parse,
"lookup L { pos [A A.sc] -100; } L;"
"feature test { ignore pos f' i', A' lookup L; } test;")
def test_ignore_sub(self):
doc = self.parse("feature test {ignore sub e t' c, q u' u' x;} test;")
sub = doc.statements[0].statements[0]
self.assertIsInstance(sub, ast.IgnoreSubstStatement)
[(pref1, glyphs1, suff1), (pref2, glyphs2, suff2)] = sub.chainContexts
self.assertEqual(glyphstr(pref1), "e")
self.assertEqual(glyphstr(glyphs1), "t")
self.assertEqual(glyphstr(suff1), "c")
self.assertEqual(glyphstr(pref2), "q")
self.assertEqual(glyphstr(glyphs2), "u u")
self.assertEqual(glyphstr(suff2), "x")
def test_ignore_substitute(self):
doc = self.parse(
"feature test {"
" ignore substitute f [a e] d' [a u]' [e y];"
"} test;")
sub = doc.statements[0].statements[0]
self.assertIsInstance(sub, ast.IgnoreSubstStatement)
[(prefix, glyphs, suffix)] = sub.chainContexts
self.assertEqual(glyphstr(prefix), "f [a e]")
self.assertEqual(glyphstr(glyphs), "d [a u]")
self.assertEqual(glyphstr(suffix), "[e y]")
def test_ignore_substitute_with_lookup(self):
self.assertRaisesRegex(
FeatureLibError,
'No lookups can be specified for "ignore sub"',
self.parse,
"lookup L { sub [A A.sc] by a; } L;"
"feature test { ignore sub f' i', A' lookup L; } test;")
def test_include_statement(self):
doc = self.parse("""\
include(../family.fea);
include # Comment
(foo)
;
""", followIncludes=False)
s1, s2, s3 = doc.statements
self.assertEqual(type(s1), ast.IncludeStatement)
self.assertEqual(s1.filename, "../family.fea")
self.assertEqual(s1.asFea(), "include(../family.fea);")
self.assertEqual(type(s2), ast.IncludeStatement)
self.assertEqual(s2.filename, "foo")
self.assertEqual(s2.asFea(), "include(foo);")
self.assertEqual(type(s3), ast.Comment)
self.assertEqual(s3.text, "# Comment")
def test_include_statement_no_semicolon(self):
doc = self.parse("""\
include(../family.fea)
""", followIncludes=False)
s1 = doc.statements[0]
self.assertEqual(type(s1), ast.IncludeStatement)
self.assertEqual(s1.filename, "../family.fea")
self.assertEqual(s1.asFea(), "include(../family.fea);")
def test_language(self):
doc = self.parse("feature test {language DEU;} test;")
s = doc.statements[0].statements[0]
self.assertEqual(type(s), ast.LanguageStatement)
self.assertEqual(s.language, "DEU ")
self.assertTrue(s.include_default)
self.assertFalse(s.required)
def test_language_exclude_dflt(self):
doc = self.parse("feature test {language DEU exclude_dflt;} test;")
s = doc.statements[0].statements[0]
self.assertEqual(type(s), ast.LanguageStatement)
self.assertEqual(s.language, "DEU ")
self.assertFalse(s.include_default)
self.assertFalse(s.required)
def test_language_exclude_dflt_required(self):
doc = self.parse("feature test {"
" language DEU exclude_dflt required;"
"} test;")
s = doc.statements[0].statements[0]
self.assertEqual(type(s), ast.LanguageStatement)
self.assertEqual(s.language, "DEU ")
self.assertFalse(s.include_default)
self.assertTrue(s.required)
def test_language_include_dflt(self):
doc = self.parse("feature test {language DEU include_dflt;} test;")
s = doc.statements[0].statements[0]
self.assertEqual(type(s), ast.LanguageStatement)
self.assertEqual(s.language, "DEU ")
self.assertTrue(s.include_default)
self.assertFalse(s.required)
def test_language_include_dflt_required(self):
doc = self.parse("feature test {"
" language DEU include_dflt required;"
"} test;")
s = doc.statements[0].statements[0]
self.assertEqual(type(s), ast.LanguageStatement)
self.assertEqual(s.language, "DEU ")
self.assertTrue(s.include_default)
self.assertTrue(s.required)
def test_language_DFLT(self):
self.assertRaisesRegex(
FeatureLibError,
'"DFLT" is not a valid language tag; use "dflt" instead',
self.parse, "feature test { language DFLT; } test;")
def test_ligatureCaretByIndex_glyphClass(self):
doc = self.parse("table GDEF{LigatureCaretByIndex [c_t f_i] 2;}GDEF;")
s = doc.statements[0].statements[0]
self.assertIsInstance(s, ast.LigatureCaretByIndexStatement)
self.assertEqual(glyphstr([s.glyphs]), "[c_t f_i]")
self.assertEqual(s.carets, [2])
def test_ligatureCaretByIndex_singleGlyph(self):
doc = self.parse("table GDEF{LigatureCaretByIndex f_f_i 3 7;}GDEF;")
s = doc.statements[0].statements[0]
self.assertIsInstance(s, ast.LigatureCaretByIndexStatement)
self.assertEqual(glyphstr([s.glyphs]), "f_f_i")
self.assertEqual(s.carets, [3, 7])
def test_ligatureCaretByPos_glyphClass(self):
doc = self.parse("table GDEF {LigatureCaretByPos [c_t f_i] 7;} GDEF;")
s = doc.statements[0].statements[0]
self.assertIsInstance(s, ast.LigatureCaretByPosStatement)
self.assertEqual(glyphstr([s.glyphs]), "[c_t f_i]")
self.assertEqual(s.carets, [7])
def test_ligatureCaretByPos_singleGlyph(self):
doc = self.parse("table GDEF {LigatureCaretByPos f_i 400 380;} GDEF;")
s = doc.statements[0].statements[0]
self.assertIsInstance(s, ast.LigatureCaretByPosStatement)
self.assertEqual(glyphstr([s.glyphs]), "f_i")
self.assertEqual(s.carets, [400, 380])
def test_lookup_block(self):
[lookup] = self.parse("lookup Ligatures {} Ligatures;").statements
self.assertEqual(lookup.name, "Ligatures")
self.assertFalse(lookup.use_extension)
def test_lookup_block_useExtension(self):
[lookup] = self.parse("lookup Foo useExtension {} Foo;").statements
self.assertEqual(lookup.name, "Foo")
self.assertTrue(lookup.use_extension)
self.assertEqual(lookup.asFea(),
"lookup Foo useExtension {\n \n} Foo;\n")
def test_lookup_block_name_mismatch(self):
self.assertRaisesRegex(
FeatureLibError, 'Expected "Foo"',
self.parse, "lookup Foo {} Bar;")
def test_lookup_block_with_horizontal_valueRecordDef(self):
doc = self.parse("feature liga {"
" lookup look {"
" valueRecordDef 123 foo;"
" } look;"
"} liga;")
[liga] = doc.statements
[look] = liga.statements
[foo] = look.statements
self.assertEqual(foo.value.xAdvance, 123)
self.assertIsNone(foo.value.yAdvance)
def test_lookup_block_with_vertical_valueRecordDef(self):
doc = self.parse("feature vkrn {"
" lookup look {"
" valueRecordDef 123 foo;"
" } look;"
"} vkrn;")
[vkrn] = doc.statements
[look] = vkrn.statements
[foo] = look.statements
self.assertIsNone(foo.value.xAdvance)
self.assertEqual(foo.value.yAdvance, 123)
def test_lookup_comment(self):
[lookup] = self.parse("lookup L { # Comment\n } L;").statements
[comment] = lookup.statements
self.assertIsInstance(comment, ast.Comment)
self.assertEqual(comment.text, "# Comment")
def test_lookup_reference(self):
[foo, bar] = self.parse("lookup Foo {} Foo;"
"feature Bar {lookup Foo;} Bar;").statements
[ref] = bar.statements
self.assertEqual(type(ref), ast.LookupReferenceStatement)
self.assertEqual(ref.lookup, foo)
def test_lookup_reference_to_lookup_inside_feature(self):
[qux, bar] = self.parse("feature Qux {lookup Foo {} Foo;} Qux;"
"feature Bar {lookup Foo;} Bar;").statements
[foo] = qux.statements
[ref] = bar.statements
self.assertIsInstance(ref, ast.LookupReferenceStatement)
self.assertEqual(ref.lookup, foo)
def test_lookup_reference_unknown(self):
self.assertRaisesRegex(
FeatureLibError, 'Unknown lookup "Huh"',
self.parse, "feature liga {lookup Huh;} liga;")
def parse_lookupflag_(self, s):
return self.parse("lookup L {%s} L;" % s).statements[0].statements[-1]
def test_lookupflag_format_A(self):
flag = self.parse_lookupflag_("lookupflag RightToLeft IgnoreMarks;")
self.assertIsInstance(flag, ast.LookupFlagStatement)
self.assertEqual(flag.value, 9)
self.assertIsNone(flag.markAttachment)
self.assertIsNone(flag.markFilteringSet)
self.assertEqual(flag.asFea(), "lookupflag RightToLeft IgnoreMarks;")
def test_lookupflag_format_A_MarkAttachmentType(self):
flag = self.parse_lookupflag_(
"@TOP_MARKS = [acute grave macron];"
"lookupflag RightToLeft MarkAttachmentType @TOP_MARKS;")
self.assertIsInstance(flag, ast.LookupFlagStatement)
self.assertEqual(flag.value, 1)
self.assertIsInstance(flag.markAttachment, ast.GlyphClassName)
self.assertEqual(flag.markAttachment.glyphSet(),
("acute", "grave", "macron"))
self.assertIsNone(flag.markFilteringSet)
self.assertEqual(flag.asFea(),
"lookupflag RightToLeft MarkAttachmentType @TOP_MARKS;")
def test_lookupflag_format_A_MarkAttachmentType_glyphClass(self):
flag = self.parse_lookupflag_(
"lookupflag RightToLeft MarkAttachmentType [acute grave macron];")
self.assertIsInstance(flag, ast.LookupFlagStatement)
self.assertEqual(flag.value, 1)
self.assertIsInstance(flag.markAttachment, ast.GlyphClass)
self.assertEqual(flag.markAttachment.glyphSet(),
("acute", "grave", "macron"))
self.assertIsNone(flag.markFilteringSet)
self.assertEqual(flag.asFea(),
"lookupflag RightToLeft MarkAttachmentType [acute grave macron];")
def test_lookupflag_format_A_UseMarkFilteringSet(self):
flag = self.parse_lookupflag_(
"@BOTTOM_MARKS = [cedilla ogonek];"
"lookupflag UseMarkFilteringSet @BOTTOM_MARKS IgnoreLigatures;")
self.assertIsInstance(flag, ast.LookupFlagStatement)
self.assertEqual(flag.value, 4)
self.assertIsNone(flag.markAttachment)
self.assertIsInstance(flag.markFilteringSet, ast.GlyphClassName)
self.assertEqual(flag.markFilteringSet.glyphSet(),
("cedilla", "ogonek"))
self.assertEqual(flag.asFea(),
"lookupflag IgnoreLigatures UseMarkFilteringSet @BOTTOM_MARKS;")
def test_lookupflag_format_A_UseMarkFilteringSet_glyphClass(self):
flag = self.parse_lookupflag_(
"lookupflag UseMarkFilteringSet [cedilla ogonek] IgnoreLigatures;")
self.assertIsInstance(flag, ast.LookupFlagStatement)
self.assertEqual(flag.value, 4)
self.assertIsNone(flag.markAttachment)
self.assertIsInstance(flag.markFilteringSet, ast.GlyphClass)
self.assertEqual(flag.markFilteringSet.glyphSet(),
("cedilla", "ogonek"))
self.assertEqual(flag.asFea(),
"lookupflag IgnoreLigatures UseMarkFilteringSet [cedilla ogonek];")
def test_lookupflag_format_B(self):
flag = self.parse_lookupflag_("lookupflag 7;")
self.assertIsInstance(flag, ast.LookupFlagStatement)
self.assertEqual(flag.value, 7)
self.assertIsNone(flag.markAttachment)
self.assertIsNone(flag.markFilteringSet)
self.assertEqual(flag.asFea(),
"lookupflag RightToLeft IgnoreBaseGlyphs IgnoreLigatures;")
def test_lookupflag_format_B_zero(self):
flag = self.parse_lookupflag_("lookupflag 0;")
self.assertIsInstance(flag, ast.LookupFlagStatement)
self.assertEqual(flag.value, 0)
self.assertIsNone(flag.markAttachment)
self.assertIsNone(flag.markFilteringSet)
self.assertEqual(flag.asFea(), "lookupflag 0;")
def test_lookupflag_no_value(self):
self.assertRaisesRegex(
FeatureLibError,
'lookupflag must have a value',
self.parse,
"feature test {lookupflag;} test;")
def test_lookupflag_repeated(self):
self.assertRaisesRegex(
FeatureLibError,
'RightToLeft can be specified only once',
self.parse,
"feature test {lookupflag RightToLeft RightToLeft;} test;")
def test_lookupflag_unrecognized(self):
self.assertRaisesRegex(
FeatureLibError,
'"IgnoreCookies" is not a recognized lookupflag',
self.parse, "feature test {lookupflag IgnoreCookies;} test;")
def test_gpos_type_1_glyph(self):
doc = self.parse("feature kern {pos one <1 2 3 4>;} kern;")
pos = doc.statements[0].statements[0]
self.assertIsInstance(pos, ast.SinglePosStatement)
[(glyphs, value)] = pos.pos
self.assertEqual(glyphstr([glyphs]), "one")
self.assertEqual(value.asFea(), "<1 2 3 4>")
def test_gpos_type_1_glyphclass_horizontal(self):
doc = self.parse("feature kern {pos [one two] -300;} kern;")
pos = doc.statements[0].statements[0]
self.assertIsInstance(pos, ast.SinglePosStatement)
[(glyphs, value)] = pos.pos
self.assertEqual(glyphstr([glyphs]), "[one two]")
self.assertEqual(value.asFea(), "-300")
def test_gpos_type_1_glyphclass_vertical(self):
doc = self.parse("feature vkrn {pos [one two] -300;} vkrn;")
pos = doc.statements[0].statements[0]
self.assertIsInstance(pos, ast.SinglePosStatement)
[(glyphs, value)] = pos.pos
self.assertEqual(glyphstr([glyphs]), "[one two]")
self.assertEqual(value.asFea(), "-300")
def test_gpos_type_1_multiple(self):
doc = self.parse("feature f {pos one'1 two'2 [five six]'56;} f;")
pos = doc.statements[0].statements[0]
self.assertIsInstance(pos, ast.SinglePosStatement)
[(glyphs1, val1), (glyphs2, val2), (glyphs3, val3)] = pos.pos
self.assertEqual(glyphstr([glyphs1]), "one")
self.assertEqual(val1.asFea(), "1")
self.assertEqual(glyphstr([glyphs2]), "two")
self.assertEqual(val2.asFea(), "2")
self.assertEqual(glyphstr([glyphs3]), "[five six]")
self.assertEqual(val3.asFea(), "56")
self.assertEqual(pos.prefix, [])
self.assertEqual(pos.suffix, [])
def test_gpos_type_1_enumerated(self):
self.assertRaisesRegex(
FeatureLibError,
'"enumerate" is only allowed with pair positionings',
self.parse, "feature test {enum pos T 100;} test;")
self.assertRaisesRegex(
FeatureLibError,
'"enumerate" is only allowed with pair positionings',
self.parse, "feature test {enumerate pos T 100;} test;")
def test_gpos_type_1_chained(self):
doc = self.parse("feature kern {pos [A B] [T Y]' 20 comma;} kern;")
pos = doc.statements[0].statements[0]
self.assertIsInstance(pos, ast.SinglePosStatement)
[(glyphs, value)] = pos.pos
self.assertEqual(glyphstr([glyphs]), "[T Y]")
self.assertEqual(value.asFea(), "20")
self.assertEqual(glyphstr(pos.prefix), "[A B]")
self.assertEqual(glyphstr(pos.suffix), "comma")
def test_gpos_type_1_chained_special_kern_format_valuerecord_format_a(self):
doc = self.parse("feature kern {pos [A B] [T Y]' comma 20;} kern;")
pos = doc.statements[0].statements[0]
self.assertIsInstance(pos, ast.SinglePosStatement)
[(glyphs, value)] = pos.pos
self.assertEqual(glyphstr([glyphs]), "[T Y]")
self.assertEqual(value.asFea(), "20")
self.assertEqual(glyphstr(pos.prefix), "[A B]")
self.assertEqual(glyphstr(pos.suffix), "comma")
def test_gpos_type_1_chained_special_kern_format_valuerecord_format_b(self):
doc = self.parse("feature kern {pos [A B] [T Y]' comma <0 0 0 0>;} kern;")
pos = doc.statements[0].statements[0]
self.assertIsInstance(pos, ast.SinglePosStatement)
[(glyphs, value)] = pos.pos
self.assertEqual(glyphstr([glyphs]), "[T Y]")
self.assertEqual(value.asFea(), "<0 0 0 0>")
self.assertEqual(glyphstr(pos.prefix), "[A B]")
self.assertEqual(glyphstr(pos.suffix), "comma")
def test_gpos_type_1_chained_special_kern_format_valuerecord_format_b_bug2293(self):
# https://github.com/fonttools/fonttools/issues/2293
doc = self.parse("feature kern {pos [A B] [T Y]' comma a <0 0 0 0>;} kern;")
pos = doc.statements[0].statements[0]
self.assertIsInstance(pos, ast.SinglePosStatement)
[(glyphs, value)] = pos.pos
self.assertEqual(glyphstr([glyphs]), "[T Y]")
self.assertEqual(value.asFea(), "<0 0 0 0>")
self.assertEqual(glyphstr(pos.prefix), "[A B]")
self.assertEqual(glyphstr(pos.suffix), "comma a")
def test_gpos_type_1_chained_exception1(self):
with self.assertRaisesRegex(FeatureLibError, "Positioning values are allowed"):
doc = self.parse("feature kern {"
" pos [A B]' [T Y]' comma a <0 0 0 0>;"
"} kern;")
def test_gpos_type_1_chained_exception2(self):
with self.assertRaisesRegex(FeatureLibError, "Positioning values are allowed"):
doc = self.parse("feature kern {"
" pos [A B]' <0 0 0 0> [T Y]' comma a <0 0 0 0>;"
"} kern;")
def test_gpos_type_1_chained_exception3(self):
with self.assertRaisesRegex(FeatureLibError, "Positioning cannot be applied"):
doc = self.parse("feature kern {"
" pos [A B] <0 0 0 0> [T Y]' comma a <0 0 0 0>;"
"} kern;")
def test_gpos_type_1_chained_exception4(self):
with self.assertRaisesRegex(FeatureLibError, "Positioning values are allowed"):
doc = self.parse("feature kern {"
" pos a' b c 123 d;"
"} kern;")
def test_gpos_type_2_format_a(self):
doc = self.parse("feature kern {"
" pos [T V] -60 [a b c] <1 2 3 4>;"
"} kern;")
pos = doc.statements[0].statements[0]
self.assertEqual(type(pos), ast.PairPosStatement)
self.assertFalse(pos.enumerated)
self.assertEqual(glyphstr([pos.glyphs1]), "[T V]")
self.assertEqual(pos.valuerecord1.asFea(), "-60")
self.assertEqual(glyphstr([pos.glyphs2]), "[a b c]")
self.assertEqual(pos.valuerecord2.asFea(), "<1 2 3 4>")
def test_gpos_type_2_format_a_enumerated(self):
doc = self.parse("feature kern {"
" enum pos [T V] -60 [a b c] <1 2 3 4>;"
"} kern;")
pos = doc.statements[0].statements[0]
self.assertEqual(type(pos), ast.PairPosStatement)
self.assertTrue(pos.enumerated)
self.assertEqual(glyphstr([pos.glyphs1]), "[T V]")
self.assertEqual(pos.valuerecord1.asFea(), "-60")
self.assertEqual(glyphstr([pos.glyphs2]), "[a b c]")
self.assertEqual(pos.valuerecord2.asFea(), "<1 2 3 4>")
def test_gpos_type_2_format_a_with_null_first(self):
doc = self.parse("feature kern {"
" pos [T V] <NULL> [a b c] <1 2 3 4>;"
"} kern;")
pos = doc.statements[0].statements[0]
self.assertEqual(type(pos), ast.PairPosStatement)
self.assertFalse(pos.enumerated)
self.assertEqual(glyphstr([pos.glyphs1]), "[T V]")
self.assertFalse(pos.valuerecord1)
self.assertEqual(pos.valuerecord1.asFea(), "<NULL>")
self.assertEqual(glyphstr([pos.glyphs2]), "[a b c]")
self.assertEqual(pos.valuerecord2.asFea(), "<1 2 3 4>")
self.assertEqual(pos.asFea(), "pos [T V] <NULL> [a b c] <1 2 3 4>;")
def test_gpos_type_2_format_a_with_null_second(self):
doc = self.parse("feature kern {"
" pos [T V] <1 2 3 4> [a b c] <NULL>;"
"} kern;")
pos = doc.statements[0].statements[0]
self.assertEqual(type(pos), ast.PairPosStatement)
self.assertFalse(pos.enumerated)
self.assertEqual(glyphstr([pos.glyphs1]), "[T V]")
self.assertEqual(pos.valuerecord1.asFea(), "<1 2 3 4>")
self.assertEqual(glyphstr([pos.glyphs2]), "[a b c]")
self.assertFalse(pos.valuerecord2)
self.assertEqual(pos.asFea(), "pos [T V] [a b c] <1 2 3 4>;")
def test_gpos_type_2_format_b(self):
doc = self.parse("feature kern {"
" pos [T V] [a b c] <1 2 3 4>;"
"} kern;")
pos = doc.statements[0].statements[0]
self.assertEqual(type(pos), ast.PairPosStatement)
self.assertFalse(pos.enumerated)
self.assertEqual(glyphstr([pos.glyphs1]), "[T V]")
self.assertEqual(pos.valuerecord1.asFea(), "<1 2 3 4>")
self.assertEqual(glyphstr([pos.glyphs2]), "[a b c]")
self.assertIsNone(pos.valuerecord2)
def test_gpos_type_2_format_b_enumerated(self):
doc = self.parse("feature kern {"
" enumerate position [T V] [a b c] <1 2 3 4>;"
"} kern;")
pos = doc.statements[0].statements[0]
self.assertEqual(type(pos), ast.PairPosStatement)
self.assertTrue(pos.enumerated)
self.assertEqual(glyphstr([pos.glyphs1]), "[T V]")
self.assertEqual(pos.valuerecord1.asFea(), "<1 2 3 4>")
self.assertEqual(glyphstr([pos.glyphs2]), "[a b c]")
self.assertIsNone(pos.valuerecord2)
def test_gpos_type_3(self):
doc = self.parse("feature kern {"
" position cursive A <anchor 12 -2> <anchor 2 3>;"
"} kern;")
pos = doc.statements[0].statements[0]
self.assertEqual(type(pos), ast.CursivePosStatement)
self.assertEqual(pos.glyphclass.glyphSet(), ("A",))
self.assertEqual((pos.entryAnchor.x, pos.entryAnchor.y), (12, -2))
self.assertEqual((pos.exitAnchor.x, pos.exitAnchor.y), (2, 3))