[feaLib] Round-trip useExtension keyword

This commit is contained in:
Khaled Hosny 2019-01-27 00:13:18 +02:00
parent 18ac453781
commit f48f4cc6b4
2 changed files with 12 additions and 2 deletions

View File

@ -293,7 +293,10 @@ class FeatureBlock(Block):
builder.end_feature()
def asFea(self, indent=""):
res = indent + "feature %s {\n" % self.name.strip()
res = indent + "feature %s " % self.name.strip()
if self.use_extension:
res += "useExtension "
res += "{\n"
res += Block.asFea(self, indent=indent)
res += indent + "} %s;\n" % self.name.strip()
return res
@ -329,7 +332,10 @@ class LookupBlock(Block):
builder.end_lookup_block()
def asFea(self, indent=""):
res = "lookup {} {{\n".format(self.name)
res = "lookup {} ".format(self.name)
if self.use_extension:
res += "useExtension "
res += "{\n"
res += Block.asFea(self, indent=indent)
res += "{}}} {};\n".format(indent, self.name)
return res

View File

@ -215,6 +215,8 @@ class ParserTest(unittest.TestCase):
[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
@ -608,6 +610,8 @@ class ParserTest(unittest.TestCase):
[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(