[feaLib] Raise for script/language in standalone lookup

They are not allowed per spec and makeotf, but currently we would fail
later with some cryptic error message.
This commit is contained in:
Khaled Hosny 2020-04-20 23:09:53 +02:00
parent dfd2ffe751
commit 6a24c8fed1
2 changed files with 20 additions and 0 deletions

View File

@ -706,6 +706,10 @@ class Builder(object):
raise FeatureLibError(
"Language statements are not allowed "
"within \"feature %s\"" % self.cur_feature_name_, location)
if self.cur_feature_name_ is None:
raise FeatureLibError(
"Language statements are not allowed "
"within standalone lookup blocks", location)
self.cur_lookup_ = None
key = (self.script_, language, self.cur_feature_name_)
@ -772,6 +776,10 @@ class Builder(object):
raise FeatureLibError(
"Script statements are not allowed "
"within \"feature %s\"" % self.cur_feature_name_, location)
if self.cur_feature_name_ is None:
raise FeatureLibError(
"Script statements are not allowed "
"within standalone lookup blocks", location)
self.cur_lookup_ = None
self.script_ = script
self.lookupflag_ = 0

View File

@ -337,6 +337,12 @@ class BuilderTest(unittest.TestCase):
"Script statements are not allowed within \"feature size\"",
self.build, "feature size { script latn; } size;")
def test_script_in_standalone_lookup(self):
self.assertRaisesRegex(
FeatureLibError,
"Script statements are not allowed within standalone lookup blocks",
self.build, "lookup test { script latn; } test;")
def test_language(self):
builder = Builder(makeTTFont(), (None, None))
builder.add_language_system(None, 'latn', 'FRA ')
@ -364,6 +370,12 @@ class BuilderTest(unittest.TestCase):
"Language statements are not allowed within \"feature size\"",
self.build, "feature size { language FRA; } size;")
def test_language_in_standalone_lookup(self):
self.assertRaisesRegex(
FeatureLibError,
"Language statements are not allowed within standalone lookup blocks",
self.build, "lookup test { language FRA; } test;")
def test_language_required_duplicate(self):
self.assertRaisesRegex(
FeatureLibError,