• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from __future__ import print_function, division, absolute_import
2from fontTools.cffLib.specializer import (programToString, stringToProgram,
3                                          generalizeProgram, specializeProgram)
4import unittest
5
6# TODO
7# https://github.com/fonttools/fonttools/pull/959#commitcomment-22059841
8# Maybe we should make these data driven. Each entry will have an input string,
9# and a generalized and specialized. For the latter two, if they are None, they
10# are considered equal to the input. Then we can do roundtripping tests as well...
11# There are a few other places (aosp tests for example) where we generate tests
12# from data.
13
14
15def get_generalized_charstr(charstr, **kwargs):
16    return programToString(generalizeProgram(stringToProgram(charstr), **kwargs))
17
18
19def get_specialized_charstr(charstr, **kwargs):
20    return programToString(specializeProgram(stringToProgram(charstr), **kwargs))
21
22
23class CFFGeneralizeProgramTest(unittest.TestCase):
24
25    def __init__(self, methodName):
26        unittest.TestCase.__init__(self, methodName)
27        # Python 3 renamed assertRaisesRegexp to assertRaisesRegex,
28        # and fires deprecation warnings if a program uses the old name.
29        if not hasattr(self, "assertRaisesRegex"):
30            self.assertRaisesRegex = self.assertRaisesRegexp
31
32# no arguments/operands
33    def test_rmoveto_none(self):
34        test_charstr = 'rmoveto'
35        with self.assertRaisesRegex(ValueError, r'\[\]'):
36            get_generalized_charstr(test_charstr)
37
38    def test_hmoveto_none(self):
39        test_charstr = 'hmoveto'
40        with self.assertRaisesRegex(ValueError, r'\[\]'):
41            get_generalized_charstr(test_charstr)
42
43    def test_vmoveto_none(self):
44        test_charstr = 'vmoveto'
45        with self.assertRaisesRegex(ValueError, r'\[\]'):
46            get_generalized_charstr(test_charstr)
47
48    def test_rlineto_none(self):
49        test_charstr = 'rlineto'
50        with self.assertRaisesRegex(ValueError, r'\[\]'):
51            get_generalized_charstr(test_charstr)
52
53    def test_hlineto_none(self):
54        test_charstr = 'hlineto'
55        with self.assertRaisesRegex(ValueError, r'\[\]'):
56            get_generalized_charstr(test_charstr)
57
58    def test_vlineto_none(self):
59        test_charstr = 'vlineto'
60        with self.assertRaisesRegex(ValueError, r'\[\]'):
61            get_generalized_charstr(test_charstr)
62
63    def test_rrcurveto_none(self):
64        test_charstr = 'rrcurveto'
65        with self.assertRaisesRegex(ValueError, r'\[\]'):
66            get_generalized_charstr(test_charstr)
67
68    def test_hhcurveto_none(self):
69        test_charstr = 'hhcurveto'
70        with self.assertRaisesRegex(ValueError, r'\[\]'):
71            get_generalized_charstr(test_charstr)
72
73    def test_vvcurveto_none(self):
74        test_charstr = 'vvcurveto'
75        with self.assertRaisesRegex(ValueError, r'\[\]'):
76            get_generalized_charstr(test_charstr)
77
78    def test_hvcurveto_none(self):
79        test_charstr = 'hvcurveto'
80        with self.assertRaisesRegex(ValueError, r'\[\]'):
81            get_generalized_charstr(test_charstr)
82
83    def test_vhcurveto_none(self):
84        test_charstr = 'vhcurveto'
85        with self.assertRaisesRegex(ValueError, r'\[\]'):
86            get_generalized_charstr(test_charstr)
87
88    def test_rcurveline_none(self):
89        test_charstr = 'rcurveline'
90        with self.assertRaisesRegex(ValueError, r'\[\]'):
91            get_generalized_charstr(test_charstr)
92
93    def test_rlinecurve_none(self):
94        test_charstr = 'rlinecurve'
95        with self.assertRaisesRegex(ValueError, r'\[\]'):
96            get_generalized_charstr(test_charstr)
97
98# rmoveto
99    def test_rmoveto_zero(self):
100        test_charstr = '0 0 rmoveto'
101        xpct_charstr = test_charstr
102        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
103
104    def test_rmoveto_zero_width(self):
105        test_charstr = '100 0 0 rmoveto'
106        xpct_charstr = test_charstr
107        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
108
109    def test_rmoveto(self):
110        test_charstr = '.55 -.8 rmoveto'
111        xpct_charstr = '0.55 -0.8 rmoveto'
112        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
113
114    def test_rmoveto_width(self):
115        test_charstr = '100.5 50 -5.8 rmoveto'
116        xpct_charstr = test_charstr
117        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
118
119# hmoveto
120    def test_hmoveto_zero(self):
121        test_charstr = '0 hmoveto'
122        xpct_charstr = '0 0 rmoveto'
123        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
124
125    def test_hmoveto_zero_width(self):
126        test_charstr = '100 0 hmoveto'
127        xpct_charstr = '100 0 0 rmoveto'
128        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
129
130    def test_hmoveto(self):
131        test_charstr = '.67 hmoveto'
132        xpct_charstr = '0.67 0 rmoveto'
133        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
134
135    def test_hmoveto_width(self):
136        test_charstr = '100 -70 hmoveto'
137        xpct_charstr = '100 -70 0 rmoveto'
138        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
139
140# vmoveto
141    def test_vmoveto_zero(self):
142        test_charstr = '0 vmoveto'
143        xpct_charstr = '0 0 rmoveto'
144        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
145
146    def test_vmoveto_zero_width(self):
147        test_charstr = '100 0 vmoveto'
148        xpct_charstr = '100 0 0 rmoveto'
149        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
150
151    def test_vmoveto(self):
152        test_charstr = '-.24 vmoveto'
153        xpct_charstr = '0 -0.24 rmoveto'
154        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
155
156    def test_vmoveto_width(self):
157        test_charstr = '100 44 vmoveto'
158        xpct_charstr = '100 0 44 rmoveto'
159        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
160
161# rlineto
162    def test_rlineto_zero(self):
163        test_charstr = '0 0 rlineto'
164        xpct_charstr = test_charstr
165        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
166
167    def test_rlineto_zero_mult(self):
168        test_charstr = '0 0 0 0 0 0 rlineto'
169        xpct_charstr = ('0 0 rlineto '*3).rstrip()
170        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
171
172    def test_rlineto(self):
173        test_charstr = '.55 -.8 rlineto'
174        xpct_charstr = '0.55 -0.8 rlineto'
175        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
176
177    def test_rlineto_mult(self):
178        test_charstr = '.55 -.8 .55 -.8 .55 -.8 rlineto'
179        xpct_charstr = ('0.55 -0.8 rlineto '*3).rstrip()
180        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
181
182# hlineto
183    def test_hlineto_zero(self):
184        test_charstr = '0 hlineto'
185        xpct_charstr = '0 0 rlineto'
186        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
187
188    def test_hlineto_zero_mult(self):
189        test_charstr = '0 0 0 0 hlineto'
190        xpct_charstr = ('0 0 rlineto '*4).rstrip()
191        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
192
193    def test_hlineto(self):
194        test_charstr = '.67 hlineto'
195        xpct_charstr = '0.67 0 rlineto'
196        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
197
198    def test_hlineto_mult(self):
199        test_charstr = '.67 -6.0 .67 hlineto'
200        xpct_charstr = '0.67 0 rlineto 0 -6.0 rlineto 0.67 0 rlineto'
201        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
202
203# vlineto
204    def test_vlineto_zero(self):
205        test_charstr = '0 vlineto'
206        xpct_charstr = '0 0 rlineto'
207        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
208
209    def test_vlineto_zero_mult(self):
210        test_charstr = '0 0 0 vlineto'
211        xpct_charstr = ('0 0 rlineto '*3).rstrip()
212        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
213
214    def test_vlineto(self):
215        test_charstr = '-.24 vlineto'
216        xpct_charstr = '0 -0.24 rlineto'
217        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
218
219    def test_vlineto_mult(self):
220        test_charstr = '-.24 +50 30 -4 vlineto'
221        xpct_charstr = '0 -0.24 rlineto 50 0 rlineto 0 30 rlineto -4 0 rlineto'
222        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
223
224# rrcurveto
225    def test_rrcurveto(self):
226        test_charstr = '-1 56 -2 57 -1 57 rrcurveto'
227        xpct_charstr = test_charstr
228        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
229
230    def test_rrcurveto_mult(self):
231        test_charstr = '-30 8 -36 15 -37 22 44 54 31 61 22 68 rrcurveto'
232        xpct_charstr = '-30 8 -36 15 -37 22 rrcurveto 44 54 31 61 22 68 rrcurveto'
233        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
234
235    def test_rrcurveto_d3947b8(self):
236        test_charstr = '1 2 3 4 5 0 rrcurveto'
237        xpct_charstr = test_charstr
238        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
239
240    def test_rrcurveto_v0_0h_h0(self):
241        test_charstr = '0 10 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto'
242        xpct_charstr = '0 10 1 2 0 0 rrcurveto 0 0 1 2 0 1 rrcurveto 0 1 3 4 0 0 rrcurveto'
243        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
244
245    def test_rrcurveto_h0_0h_h0(self):
246        test_charstr = '10 0 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto'
247        xpct_charstr = '10 0 1 2 0 0 rrcurveto 0 0 1 2 0 1 rrcurveto 0 1 3 4 0 0 rrcurveto'
248        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
249
250    def test_rrcurveto_00_0h_h0(self):
251        test_charstr = '0 0 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto'
252        xpct_charstr = '0 0 1 2 0 0 rrcurveto 0 0 1 2 0 1 rrcurveto 0 1 3 4 0 0 rrcurveto'
253        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
254
255    def test_rrcurveto_r0_0h_h0(self):
256        test_charstr = '10 10 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto'
257        xpct_charstr = '10 10 1 2 0 0 rrcurveto 0 0 1 2 0 1 rrcurveto 0 1 3 4 0 0 rrcurveto'
258        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
259
260    def test_rrcurveto_v0_0v_v0(self):
261        test_charstr = '0 10 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto'
262        xpct_charstr = '0 10 1 2 0 0 rrcurveto 0 0 1 2 1 0 rrcurveto 1 0 3 4 0 0 rrcurveto'
263        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
264
265    def test_rrcurveto_h0_0v_v0(self):
266        test_charstr = '10 0 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto'
267        xpct_charstr = '10 0 1 2 0 0 rrcurveto 0 0 1 2 1 0 rrcurveto 1 0 3 4 0 0 rrcurveto'
268        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
269
270    def test_rrcurveto_00_0v_v0(self):
271        test_charstr = '0 0 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto'
272        xpct_charstr = '0 0 1 2 0 0 rrcurveto 0 0 1 2 1 0 rrcurveto 1 0 3 4 0 0 rrcurveto'
273        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
274
275    def test_rrcurveto_r0_0v_v0(self):
276        test_charstr = '10 10 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto'
277        xpct_charstr = '10 10 1 2 0 0 rrcurveto 0 0 1 2 1 0 rrcurveto 1 0 3 4 0 0 rrcurveto'
278        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
279
280# hhcurveto
281    def test_hhcurveto_4(self):
282        test_charstr = '10 30 0 10 hhcurveto'
283        xpct_charstr = '10 0 30 0 10 0 rrcurveto'
284        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
285
286    def test_hhcurveto_5(self):
287        test_charstr = '40 -38 -60 41 -91 hhcurveto'
288        xpct_charstr = '-38 40 -60 41 -91 0 rrcurveto'
289        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
290
291    def test_hhcurveto_mult_4_4(self):
292        test_charstr = '43 23 25 18 29 56 42 -84 hhcurveto'
293        xpct_charstr = '43 0 23 25 18 0 rrcurveto 29 0 56 42 -84 0 rrcurveto'
294        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
295
296    def test_hhcurveto_mult_5_4(self):
297        test_charstr = '43 23 25 18 29 56 42 -84 79 hhcurveto'
298        xpct_charstr = '23 43 25 18 29 0 rrcurveto 56 0 42 -84 79 0 rrcurveto'
299        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
300
301    def test_hhcurveto_mult_4_4_4(self):
302        test_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 hhcurveto'
303        xpct_charstr = '1 0 2 3 4 0 rrcurveto 5 0 6 7 8 0 rrcurveto 9 0 10 11 12 0 rrcurveto'
304        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
305
306    def test_hhcurveto_mult_5_4_4(self):
307        test_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 13 hhcurveto'
308        xpct_charstr = '2 1 3 4 5 0 rrcurveto 6 0 7 8 9 0 rrcurveto 10 0 11 12 13 0 rrcurveto'
309        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
310
311# vvcurveto
312    def test_vvcurveto_4(self):
313        test_charstr = '61 6 52 68 vvcurveto'
314        xpct_charstr = '0 61 6 52 0 68 rrcurveto'
315        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
316
317    def test_vvcurveto_5(self):
318        test_charstr = '61 38 35 56 72 vvcurveto'
319        xpct_charstr = '61 38 35 56 0 72 rrcurveto'
320        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
321
322    def test_vvcurveto_mult_4_4(self):
323        test_charstr = '-84 -88 -30 -90 -13 19 23 -11 vvcurveto'
324        xpct_charstr = '0 -84 -88 -30 0 -90 rrcurveto 0 -13 19 23 0 -11 rrcurveto'
325        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
326
327    def test_vvcurveto_mult_5_4(self):
328        test_charstr = '43 12 17 32 65 68 -6 52 61 vvcurveto'
329        xpct_charstr = '43 12 17 32 0 65 rrcurveto 0 68 -6 52 0 61 rrcurveto'
330        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
331
332    def test_vvcurveto_mult_4_4_4(self):
333        test_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 vvcurveto'
334        xpct_charstr = '0 1 2 3 0 4 rrcurveto 0 5 6 7 0 8 rrcurveto 0 9 10 11 0 12 rrcurveto'
335        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
336
337    def test_vvcurveto_mult_5_4_4(self):
338        test_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 13 vvcurveto'
339        xpct_charstr = '1 2 3 4 0 5 rrcurveto 0 6 7 8 0 9 rrcurveto 0 10 11 12 0 13 rrcurveto'
340        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
341
342# hvcurveto
343    def test_hvcurveto_4(self):
344        test_charstr = '1 2 3 4 hvcurveto'
345        xpct_charstr = '1 0 2 3 0 4 rrcurveto'
346        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
347
348    def test_hvcurveto_5(self):
349        test_charstr = '57 44 22 40 34 hvcurveto'
350        xpct_charstr = '57 0 44 22 34 40 rrcurveto'
351        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
352
353    def test_hvcurveto_4_4(self):
354        test_charstr = '65 33 -19 -45 -45 -29 -25 -71 hvcurveto'
355        xpct_charstr = '65 0 33 -19 0 -45 rrcurveto 0 -45 -29 -25 -71 0 rrcurveto'
356        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
357
358    def test_hvcurveto_4_5(self):
359        test_charstr = '97 69 41 86 58 -36 34 -64 11 hvcurveto'
360        xpct_charstr = '97 0 69 41 0 86 rrcurveto 0 58 -36 34 -64 11 rrcurveto'
361        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
362
363    def test_hvcurveto_4_4_4(self):
364        test_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 hvcurveto'
365        xpct_charstr = '1 0 2 3 0 4 rrcurveto 0 5 6 7 8 0 rrcurveto 9 0 10 11 0 12 rrcurveto'
366        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
367
368    def test_hvcurveto_4_4_5(self):
369        test_charstr = '-124 -79 104 165 163 82 102 124 56 43 -25 -37 35 hvcurveto'
370        xpct_charstr = '-124 0 -79 104 0 165 rrcurveto 0 163 82 102 124 0 rrcurveto 56 0 43 -25 35 -37 rrcurveto'
371        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
372
373    def test_hvcurveto_4_4_4_4(self):
374        test_charstr = '32 25 22 32 31 -25 22 -32 -32 -25 -22 -31 -32 25 -22 32 hvcurveto'
375        xpct_charstr = '32 0 25 22 0 32 rrcurveto 0 31 -25 22 -32 0 rrcurveto -32 0 -25 -22 0 -31 rrcurveto 0 -32 25 -22 32 0 rrcurveto'
376        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
377
378    def test_hvcurveto_4_4_4_4_5(self):
379        test_charstr = '-170 -128 111 195 234 172 151 178 182 95 -118 -161 -130 -71 -77 -63 -55 -19 38 79 20 hvcurveto'
380        xpct_charstr = '-170 0 -128 111 0 195 rrcurveto 0 234 172 151 178 0 rrcurveto 182 0 95 -118 0 -161 rrcurveto 0 -130 -71 -77 -63 0 rrcurveto -55 0 -19 38 20 79 rrcurveto'
381        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
382
383# vhcurveto
384    def test_vhcurveto_4(self):
385        test_charstr = '-57 43 -30 53 vhcurveto'
386        xpct_charstr = '0 -57 43 -30 53 0 rrcurveto'
387        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
388
389    def test_vhcurveto_5(self):
390        test_charstr = '41 -27 19 -46 11 vhcurveto'
391        xpct_charstr = '0 41 -27 19 -46 11 rrcurveto'
392        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
393
394    def test_vhcurveto_4_4(self):
395        test_charstr = '1 2 3 4 5 6 7 8 vhcurveto'
396        xpct_charstr = '0 1 2 3 4 0 rrcurveto 5 0 6 7 0 8 rrcurveto'
397        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
398
399    def test_vhcurveto_4_5(self):
400        test_charstr = '-64 -23 -25 -45 -30 -24 14 33 -19 vhcurveto'
401        xpct_charstr = '0 -64 -23 -25 -45 0 rrcurveto -30 0 -24 14 -19 33 rrcurveto'
402        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
403
404    def test_vhcurveto_4_4_4(self):
405        test_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 vhcurveto'
406        xpct_charstr = '0 1 2 3 4 0 rrcurveto 5 0 6 7 0 8 rrcurveto 0 9 10 11 12 0 rrcurveto'
407        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
408
409    def test_vhcurveto_4_4_5(self):
410        test_charstr = '108 59 81 98 99 59 -81 -108 -100 -46 -66 -63 -47 vhcurveto'
411        xpct_charstr = '0 108 59 81 98 0 rrcurveto 99 0 59 -81 0 -108 rrcurveto 0 -100 -46 -66 -63 -47 rrcurveto'
412        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
413
414    def test_vhcurveto_4_4_4_5(self):
415        test_charstr = '60 -26 37 -43 -33 -28 -22 -36 -37 27 -20 32 3 4 0 1 3 vhcurveto'
416        xpct_charstr = '0 60 -26 37 -43 0 rrcurveto -33 0 -28 -22 0 -36 rrcurveto 0 -37 27 -20 32 0 rrcurveto 3 0 4 0 3 1 rrcurveto'
417        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
418
419# rcurveline
420    def test_rcurveline_6_2(self):
421        test_charstr = '21 -76 21 -72 24 -73 31 -100 rcurveline'
422        xpct_charstr = '21 -76 21 -72 24 -73 rrcurveto 31 -100 rlineto'
423        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
424
425    def test_rcurveline_6_6_2(self):
426        test_charstr = '-73 80 -80 121 -49 96 60 65 55 41 54 17 -8 78 rcurveline'
427        xpct_charstr = '-73 80 -80 121 -49 96 rrcurveto 60 65 55 41 54 17 rrcurveto -8 78 rlineto'
428        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
429
430    def test_rcurveline_6_6_6_2(self):
431        test_charstr = '1 64 10 51 29 39 15 21 15 20 15 18 47 -89 63 -98 52 -59 91 8 rcurveline'
432        xpct_charstr = '1 64 10 51 29 39 rrcurveto 15 21 15 20 15 18 rrcurveto 47 -89 63 -98 52 -59 rrcurveto 91 8 rlineto'
433        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
434
435    def test_rcurveline_6_6_6_6_2(self):
436        test_charstr = '1 64 10 51 29 39 15 21 15 20 15 18 46 -88 63 -97 52 -59 -38 -57 -49 -62 -52 -54 96 -8 rcurveline'
437        xpct_charstr = '1 64 10 51 29 39 rrcurveto 15 21 15 20 15 18 rrcurveto 46 -88 63 -97 52 -59 rrcurveto -38 -57 -49 -62 -52 -54 rrcurveto 96 -8 rlineto'
438        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
439
440# rlinecurve
441    def test_rlinecurve_2_6(self):
442        test_charstr = '21 -76 21 -72 24 -73 31 -100 rlinecurve'
443        xpct_charstr = '21 -76 rlineto 21 -72 24 -73 31 -100 rrcurveto'
444        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
445
446    def test_rlinecurve_2_2_6(self):
447        test_charstr = '-73 80 -80 121 -49 96 60 65 55 41 rlinecurve'
448        xpct_charstr = '-73 80 rlineto -80 121 rlineto -49 96 60 65 55 41 rrcurveto'
449        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
450
451    def test_rlinecurve_2_2_2_6(self):
452        test_charstr = '1 64 10 51 29 39 15 21 15 20 15 18 rlinecurve'
453        xpct_charstr = '1 64 rlineto 10 51 rlineto 29 39 rlineto 15 21 15 20 15 18 rrcurveto'
454        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
455
456    def test_rlinecurve_2_2_2_2_6(self):
457        test_charstr = '1 64 10 51 29 39 15 21 15 20 15 18 46 -88 rlinecurve'
458        xpct_charstr = '1 64 rlineto 10 51 rlineto 29 39 rlineto 15 21 rlineto 15 20 15 18 46 -88 rrcurveto'
459        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
460
461# hstem/vstem
462    def test_hstem_vstem(self):
463        test_charstr = '95 0 58 542 60 hstem 89 65 344 67 vstem 89 45 rmoveto'
464        xpct_charstr = test_charstr
465        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
466
467# hstemhm/vstemhm
468    def test_hstemhm_vstemhm(self):
469        test_charstr = '-16 577 60 24 60 hstemhm 98 55 236 55 vstemhm 343 577 rmoveto'
470        xpct_charstr = test_charstr
471        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
472
473# hintmask/cntrmask
474    def test_hintmask_cntrmask(self):
475        test_charstr = '52 80 153 61 4 83 -71.5 71.5 hintmask 11011100 94 119 216 119 216 119 cntrmask 1110000 154 -12 rmoveto'
476        xpct_charstr = test_charstr
477        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
478
479# endchar
480    def test_endchar(self):
481        test_charstr = '-255 319 rmoveto 266 57 rlineto endchar'
482        xpct_charstr = test_charstr
483        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
484
485# xtra
486    def test_xtra(self):
487        test_charstr = '-255 319 rmoveto 266 57 rlineto xtra 90 34'
488        xpct_charstr = test_charstr
489        self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr)
490
491
492class CFFSpecializeProgramTest(unittest.TestCase):
493
494    def __init__(self, methodName):
495        unittest.TestCase.__init__(self, methodName)
496        # Python 3 renamed assertRaisesRegexp to assertRaisesRegex,
497        # and fires deprecation warnings if a program uses the old name.
498        if not hasattr(self, "assertRaisesRegex"):
499            self.assertRaisesRegex = self.assertRaisesRegexp
500
501# no arguments/operands
502    def test_rmoveto_none(self):
503        test_charstr = 'rmoveto'
504        with self.assertRaisesRegex(ValueError, r'\[\]'):
505            get_specialized_charstr(test_charstr)
506
507    def test_hmoveto_none(self):
508        test_charstr = 'hmoveto'
509        with self.assertRaisesRegex(ValueError, r'\[\]'):
510            get_specialized_charstr(test_charstr)
511
512    def test_vmoveto_none(self):
513        test_charstr = 'vmoveto'
514        with self.assertRaisesRegex(ValueError, r'\[\]'):
515            get_specialized_charstr(test_charstr)
516
517    def test_rlineto_none(self):
518        test_charstr = 'rlineto'
519        with self.assertRaisesRegex(ValueError, r'\[\]'):
520            get_specialized_charstr(test_charstr)
521
522    def test_hlineto_none(self):
523        test_charstr = 'hlineto'
524        with self.assertRaisesRegex(ValueError, r'\[\]'):
525            get_specialized_charstr(test_charstr)
526
527    def test_vlineto_none(self):
528        test_charstr = 'vlineto'
529        with self.assertRaisesRegex(ValueError, r'\[\]'):
530            get_specialized_charstr(test_charstr)
531
532    def test_rrcurveto_none(self):
533        test_charstr = 'rrcurveto'
534        with self.assertRaisesRegex(ValueError, r'\[\]'):
535            get_specialized_charstr(test_charstr)
536
537    def test_hhcurveto_none(self):
538        test_charstr = 'hhcurveto'
539        with self.assertRaisesRegex(ValueError, r'\[\]'):
540            get_specialized_charstr(test_charstr)
541
542    def test_vvcurveto_none(self):
543        test_charstr = 'vvcurveto'
544        with self.assertRaisesRegex(ValueError, r'\[\]'):
545            get_specialized_charstr(test_charstr)
546
547    def test_hvcurveto_none(self):
548        test_charstr = 'hvcurveto'
549        with self.assertRaisesRegex(ValueError, r'\[\]'):
550            get_specialized_charstr(test_charstr)
551
552    def test_vhcurveto_none(self):
553        test_charstr = 'vhcurveto'
554        with self.assertRaisesRegex(ValueError, r'\[\]'):
555            get_specialized_charstr(test_charstr)
556
557    def test_rcurveline_none(self):
558        test_charstr = 'rcurveline'
559        with self.assertRaisesRegex(ValueError, r'\[\]'):
560            get_specialized_charstr(test_charstr)
561
562    def test_rlinecurve_none(self):
563        test_charstr = 'rlinecurve'
564        with self.assertRaisesRegex(ValueError, r'\[\]'):
565            get_specialized_charstr(test_charstr)
566
567# rmoveto
568    def test_rmoveto_zero(self):
569        test_charstr = '0 0 rmoveto'
570        xpct_charstr = '0 hmoveto'
571        self.assertEqual(get_specialized_charstr(test_charstr,
572                                        generalizeFirst=False), xpct_charstr)
573
574    def test_rmoveto_zero_mult(self):
575        test_charstr = '0 0 rmoveto '*3
576        xpct_charstr = '0 hmoveto'
577        self.assertEqual(get_specialized_charstr(test_charstr,
578                                        generalizeFirst=False), xpct_charstr)
579
580    def test_rmoveto_zero_width(self):
581        test_charstr = '100 0 0 rmoveto'
582        xpct_charstr = '100 0 hmoveto'
583        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
584
585    def test_rmoveto(self):
586        test_charstr = '.55 -.8 rmoveto'
587        xpct_charstr = '0.55 -0.8 rmoveto'
588        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
589
590    def test_rmoveto_mult(self):
591        test_charstr = '55 -8 rmoveto '*3
592        xpct_charstr = '165 -24 rmoveto'
593        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
594
595    def test_rmoveto_width(self):
596        test_charstr = '100.5 50 -5.8 rmoveto'
597        xpct_charstr = test_charstr
598        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
599
600# rlineto
601    def test_rlineto_zero(self):
602        test_charstr = '0 0 rlineto'
603        xpct_charstr = ''
604        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
605
606    def test_rlineto_zero_mult(self):
607        test_charstr = '0 0 rlineto '*3
608        xpct_charstr = ''
609        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
610
611    def test_rlineto(self):
612        test_charstr = '.55 -.8 rlineto'
613        xpct_charstr = '0.55 -0.8 rlineto'
614        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
615
616    def test_rlineto_mult(self):
617        test_charstr = '.55 -.8 rlineto '*3
618        xpct_charstr = '0.55 -0.8 0.55 -0.8 0.55 -0.8 rlineto'
619        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
620
621    def test_hlineto(self):
622        test_charstr = '.67 0 rlineto'
623        xpct_charstr = '0.67 hlineto'
624        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
625
626    def test_hlineto_zero_mult(self):
627        test_charstr = '62 0 rlineto '*3
628        xpct_charstr = '186 hlineto'
629        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
630
631    def test_hlineto_mult(self):
632        test_charstr = '.67 0 rlineto 0 -6.0 rlineto .67 0 rlineto'
633        xpct_charstr = '0.67 -6.0 0.67 hlineto'
634        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
635
636    def test_vlineto(self):
637        test_charstr = '0 -.24 rlineto'
638        xpct_charstr = '-0.24 vlineto'
639        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
640
641    def test_vlineto_zero_mult(self):
642        test_charstr = '0 -24 rlineto '*3
643        xpct_charstr = '-72 vlineto'
644        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
645
646    def test_vlineto_mult(self):
647        test_charstr = '0 -.24 rlineto +50 0 rlineto 0 30 rlineto -4 0 rlineto'
648        xpct_charstr = '-0.24 50 30 -4 vlineto'
649        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
650
651    def test_0lineto_peephole(self):
652        test_charstr = '1 2 0 0 3 4 rlineto'
653        xpct_charstr = '1 2 3 4 rlineto'
654        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
655
656    def test_hlineto_peephole(self):
657        test_charstr = '1 2 5 0 3 4 rlineto'
658        xpct_charstr = test_charstr
659        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
660
661    def test_vlineto_peephole(self):
662        test_charstr = '1 2 0 5 3 4 rlineto'
663        xpct_charstr = test_charstr
664        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
665
666# rrcurveto
667    def test_rrcurveto(self):
668        test_charstr = '-1 56 -2 57 -1 57 rrcurveto'
669        xpct_charstr = test_charstr
670        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
671
672    def test_rrcurveto_mult(self):
673        test_charstr = '-30 8 -36 15 -37 22 rrcurveto 44 54 31 61 22 68 rrcurveto'
674        xpct_charstr = '-30 8 -36 15 -37 22 44 54 31 61 22 68 rrcurveto'
675        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
676
677    def test_rrcurveto_d3947b8(self):
678        test_charstr = '1 2 3 4 5 0 rrcurveto'
679        xpct_charstr = '2 1 3 4 5 hhcurveto'
680        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
681
682    def test_hhcurveto_4(self):
683        test_charstr = '10 0 30 0 10 0 rrcurveto'
684        xpct_charstr = '10 30 0 10 hhcurveto'
685        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
686
687    def test_hhcurveto_5(self):
688        test_charstr = '-38 40 -60 41 -91 0 rrcurveto'
689        xpct_charstr = '40 -38 -60 41 -91 hhcurveto'
690        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
691
692    def test_hhcurveto_mult_4_4(self):
693        test_charstr = '43 0 23 25 18 0 rrcurveto 29 0 56 42 -84 0 rrcurveto'
694        xpct_charstr = '43 23 25 18 29 56 42 -84 hhcurveto'
695        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
696
697    def test_hhcurveto_mult_5_4(self):
698        test_charstr = '23 43 25 18 29 0 rrcurveto 56 0 42 -84 79 0 rrcurveto'
699        xpct_charstr = '43 23 25 18 29 56 42 -84 79 hhcurveto'
700        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
701
702    def test_hhcurveto_mult_4_4_4(self):
703        test_charstr = '1 0 2 3 4 0 rrcurveto 5 0 6 7 8 0 rrcurveto 9 0 10 11 12 0 rrcurveto'
704        xpct_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 hhcurveto'
705        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
706
707    def test_hhcurveto_mult_5_4_4(self):
708        test_charstr = '2 1 3 4 5 0 rrcurveto 6 0 7 8 9 0 rrcurveto 10 0 11 12 13 0 rrcurveto'
709        xpct_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 13 hhcurveto'
710        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
711
712    def test_vvcurveto_4(self):
713        test_charstr = '0 61 6 52 0 68 rrcurveto'
714        xpct_charstr = '61 6 52 68 vvcurveto'
715        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
716
717    def test_vvcurveto_5(self):
718        test_charstr = '61 38 35 56 0 72 rrcurveto'
719        xpct_charstr = '61 38 35 56 72 vvcurveto'
720        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
721
722    def test_vvcurveto_mult_4_4(self):
723        test_charstr = '0 -84 -88 -30 0 -90 rrcurveto 0 -13 19 23 0 -11 rrcurveto'
724        xpct_charstr = '-84 -88 -30 -90 -13 19 23 -11 vvcurveto'
725        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
726
727    def test_vvcurveto_mult_5_4(self):
728        test_charstr = '43 12 17 32 0 65 rrcurveto 0 68 -6 52 0 61 rrcurveto'
729        xpct_charstr = '43 12 17 32 65 68 -6 52 61 vvcurveto'
730        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
731
732    def test_vvcurveto_mult_4_4_4(self):
733        test_charstr = '0 1 2 3 0 4 rrcurveto 0 5 6 7 0 8 rrcurveto 0 9 10 11 0 12 rrcurveto'
734        xpct_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 vvcurveto'
735        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
736
737    def test_vvcurveto_mult_5_4_4(self):
738        test_charstr = '1 2 3 4 0 5 rrcurveto 0 6 7 8 0 9 rrcurveto 0 10 11 12 0 13 rrcurveto'
739        xpct_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 13 vvcurveto'
740        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
741
742    def test_hvcurveto_4(self):
743        test_charstr = '1 0 2 3 0 4 rrcurveto'
744        xpct_charstr = '1 2 3 4 hvcurveto'
745        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
746
747    def test_hvcurveto_5(self):
748        test_charstr = '57 0 44 22 34 40 rrcurveto'
749        xpct_charstr = '57 44 22 40 34 hvcurveto'
750        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
751
752    def test_hvcurveto_4_4(self):
753        test_charstr = '65 0 33 -19 0 -45 rrcurveto 0 -45 -29 -25 -71 0 rrcurveto'
754        xpct_charstr = '65 33 -19 -45 -45 -29 -25 -71 hvcurveto'
755        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
756
757    def test_hvcurveto_4_5(self):
758        test_charstr = '97 0 69 41 0 86 rrcurveto 0 58 -36 34 -64 11 rrcurveto'
759        xpct_charstr = '97 69 41 86 58 -36 34 -64 11 hvcurveto'
760        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
761
762    def test_hvcurveto_4_4_4(self):
763        test_charstr = '1 0 2 3 0 4 rrcurveto 0 5 6 7 8 0 rrcurveto 9 0 10 11 0 12 rrcurveto'
764        xpct_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 hvcurveto'
765        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
766
767    def test_hvcurveto_4_4_5(self):
768        test_charstr = '-124 0 -79 104 0 165 rrcurveto 0 163 82 102 124 0 rrcurveto 56 0 43 -25 35 -37 rrcurveto'
769        xpct_charstr = '-124 -79 104 165 163 82 102 124 56 43 -25 -37 35 hvcurveto'
770        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
771
772    def test_hvcurveto_4_4_4_4(self):
773        test_charstr = '32 0 25 22 0 32 rrcurveto 0 31 -25 22 -32 0 rrcurveto -32 0 -25 -22 0 -31 rrcurveto 0 -32 25 -22 32 0 rrcurveto'
774        xpct_charstr = '32 25 22 32 31 -25 22 -32 -32 -25 -22 -31 -32 25 -22 32 hvcurveto'
775        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
776
777    def test_hvcurveto_4_4_4_4_5(self):
778        test_charstr = '-170 0 -128 111 0 195 rrcurveto 0 234 172 151 178 0 rrcurveto 182 0 95 -118 0 -161 rrcurveto 0 -130 -71 -77 -63 0 rrcurveto -55 0 -19 38 20 79 rrcurveto'
779        xpct_charstr = '-170 -128 111 195 234 172 151 178 182 95 -118 -161 -130 -71 -77 -63 -55 -19 38 79 20 hvcurveto'
780        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
781
782    def test_vhcurveto_4(self):
783        test_charstr = '0 -57 43 -30 53 0 rrcurveto'
784        xpct_charstr = '-57 43 -30 53 vhcurveto'
785        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
786
787    def test_vhcurveto_5(self):
788        test_charstr = '0 41 -27 19 -46 11 rrcurveto'
789        xpct_charstr = '41 -27 19 -46 11 vhcurveto'
790        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
791
792    def test_vhcurveto_4_4(self):
793        test_charstr = '0 1 2 3 4 0 rrcurveto 5 0 6 7 0 8 rrcurveto'
794        xpct_charstr = '1 2 3 4 5 6 7 8 vhcurveto'
795        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
796
797    def test_vhcurveto_4_5(self):
798        test_charstr = '0 -64 -23 -25 -45 0 rrcurveto -30 0 -24 14 -19 33 rrcurveto'
799        xpct_charstr = '-64 -23 -25 -45 -30 -24 14 33 -19 vhcurveto'
800        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
801
802    def test_vhcurveto_4_4_4(self):
803        test_charstr = '0 1 2 3 4 0 rrcurveto 5 0 6 7 0 8 rrcurveto 0 9 10 11 12 0 rrcurveto'
804        xpct_charstr = '1 2 3 4 5 6 7 8 9 10 11 12 vhcurveto'
805        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
806
807    def test_vhcurveto_4_4_5(self):
808        test_charstr = '0 108 59 81 98 0 rrcurveto 99 0 59 -81 0 -108 rrcurveto 0 -100 -46 -66 -63 -47 rrcurveto'
809        xpct_charstr = '108 59 81 98 99 59 -81 -108 -100 -46 -66 -63 -47 vhcurveto'
810        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
811
812    def test_vhcurveto_4_4_4_5(self):
813        test_charstr = '0 60 -26 37 -43 0 rrcurveto -33 0 -28 -22 0 -36 rrcurveto 0 -37 27 -20 32 0 rrcurveto 3 0 4 0 3 1 rrcurveto'
814        xpct_charstr = '60 -26 37 -43 -33 -28 -22 -36 -37 27 -20 32 3 4 0 1 3 vhcurveto'
815        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
816
817    def test_rrcurveto_v0_0h_h0(self):
818        test_charstr = '0 10 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto'
819        xpct_charstr = '10 1 2 0 0 1 2 1 1 3 4 0 vhcurveto'
820        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
821
822    def test_rrcurveto_h0_0h_h0(self):
823        test_charstr = '10 0 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto'
824        xpct_charstr = '10 1 2 0 hhcurveto 0 1 2 1 1 3 4 0 hvcurveto'
825        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
826
827    def test_rrcurveto_00_0h_h0(self):
828        test_charstr = '0 0 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto'
829        xpct_charstr = '1 2 rlineto 0 1 2 1 1 3 4 0 hvcurveto'
830        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
831
832    def test_rrcurveto_r0_0h_h0(self):
833        test_charstr = '10 10 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto'
834        xpct_charstr = '10 10 1 2 0 0 1 2 1 1 3 4 0 vvcurveto'
835        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
836
837    def test_rrcurveto_v0_0v_v0(self):
838        test_charstr = '0 10 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto'
839        xpct_charstr = '10 1 2 0 vhcurveto 0 1 2 1 1 3 4 0 hhcurveto'
840        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
841
842    def test_rrcurveto_h0_0v_v0(self):
843        test_charstr = '10 0 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto'
844        xpct_charstr = '10 1 2 0 0 1 2 1 1 3 4 0 hhcurveto'
845        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
846
847    def test_rrcurveto_00_0v_v0(self):
848        test_charstr = '0 0 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto'
849        xpct_charstr = '1 2 rlineto 0 1 2 1 1 3 4 0 hhcurveto'
850        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
851
852    def test_rrcurveto_r0_0v_v0(self):
853        test_charstr = '10 10 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto'
854        xpct_charstr = '10 10 1 2 0 0 1 2 1 1 3 4 0 hhcurveto'
855        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
856
857    def test_hhcurveto_peephole(self):
858        test_charstr = '1 2 3 4 5 6 1 2 3 4 5 0 1 2 3 4 5 6 rrcurveto'
859        xpct_charstr = test_charstr
860        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
861
862    def test_vvcurveto_peephole(self):
863        test_charstr = '1 2 3 4 5 6 1 2 3 4 0 6 1 2 3 4 5 6 rrcurveto'
864        xpct_charstr = test_charstr
865        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
866
867    def test_hvcurveto_peephole(self):
868        test_charstr = '1 2 3 4 5 6 1 0 3 4 5 6 1 2 3 4 5 6 rrcurveto'
869        xpct_charstr = test_charstr
870        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
871
872    def test_vhcurveto_peephole(self):
873        test_charstr = '1 2 3 4 5 6 0 2 3 4 5 6 1 2 3 4 5 6 rrcurveto'
874        xpct_charstr = test_charstr
875        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
876
877    def test_rcurveline_6_2(self):
878        test_charstr = '21 -76 21 -72 24 -73 rrcurveto 31 -100 rlineto'
879        xpct_charstr = '21 -76 21 -72 24 -73 31 -100 rcurveline'
880        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
881
882    def test_rcurveline_6_6_2(self):
883        test_charstr = '-73 80 -80 121 -49 96 rrcurveto 60 65 55 41 54 17 rrcurveto -8 78 rlineto'
884        xpct_charstr = '-73 80 -80 121 -49 96 60 65 55 41 54 17 -8 78 rcurveline'
885        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
886
887    def test_rcurveline_6_6_6_2(self):
888        test_charstr = '1 64 10 51 29 39 rrcurveto 15 21 15 20 15 18 rrcurveto 47 -89 63 -98 52 -59 rrcurveto 91 8 rlineto'
889        xpct_charstr = '1 64 10 51 29 39 15 21 15 20 15 18 47 -89 63 -98 52 -59 91 8 rcurveline'
890        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
891
892    def test_rlinecurve_2_6(self):
893        test_charstr = '21 -76 rlineto 21 -72 24 -73 31 -100 rrcurveto'
894        xpct_charstr = '21 -76 21 -72 24 -73 31 -100 rlinecurve'
895        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
896
897    def test_rlinecurve_2_2_6(self):
898        test_charstr = '-73 80 rlineto -80 121 rlineto -49 96 60 65 55 41 rrcurveto'
899        xpct_charstr = '-73 80 -80 121 -49 96 60 65 55 41 rlinecurve'
900        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
901
902    def test_rlinecurve_2_2_2_6(self):
903        test_charstr = '1 64 rlineto 10 51 rlineto 29 39 rlineto 15 21 15 20 15 18 rrcurveto'
904        xpct_charstr = '1 64 10 51 29 39 15 21 15 20 15 18 rlinecurve'
905        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
906
907# maxstack CFF=48, specializer uses up to 47
908    def test_maxstack(self):
909        operands = '1 2 3 4 5 6 '
910        operator = 'rrcurveto '
911        test_charstr = (operands + operator)*9
912        xpct_charstr = (operands*2 + operator + operands*7 + operator).rstrip()
913        self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr)
914
915
916if __name__ == "__main__":
917    import sys
918    sys.exit(unittest.main())
919