]> git.ipfire.org Git - thirdparty/google/fonts.git/commitdiff
Add a check for wellformedness of multiline strings, fixes #197
authorSimon Cozens <simon@simon-cozens.org>
Fri, 25 Jul 2025 08:16:02 +0000 (09:16 +0100)
committerSimon Cozens <simon@simon-cozens.org>
Fri, 25 Jul 2025 08:16:02 +0000 (09:16 +0100)
tests/test_wellformed.py

index ac0eafd376ac316357983eefe2602bc6f25b46c5..852668410717dba1c2e78ad54a40e0ca1c7a3c77 100644 (file)
@@ -1,7 +1,15 @@
+import re
+import sys
+
 import pytest
 from axisregistry import AxisRegistry
 from axisregistry.axes_pb2 import AxisProto
 
+if sys.version_info < (3, 10):
+    from importlib_resources import files
+else:
+    from importlib.resources import files
+
 registry = AxisRegistry()
 
 OPTIONAL_FIELDS = ["illustration_url", "is_parametric"]
@@ -15,5 +23,25 @@ def test_proto_wellformed(axis_tag):
         field_name = field.name
         if field_name in OPTIONAL_FIELDS:
             continue
-        assert field_name in raw_fields, field_name
+        assert field_name in raw_fields, f"Non-optional field {field_name} is missing in {axis_tag}"
         assert raw_fields[field_name] is not None, field_name
+
+proto_files = [
+                file
+                for file in files("axisregistry.data").iterdir()
+                if file.name.endswith(".textproto")
+            ]
+@pytest.mark.parametrize("proto_file", proto_files)
+def test_proto_multiline_string(proto_file):
+    with open(proto_file, "r") as f:
+        content = f.read()
+    # Check for multiline strings which do not have a space either at the
+    # end of the line or at the beginning of the next line
+    pattern = re.compile(r'".*\S"\n\s*"\S+')
+    matches = pattern.findall(content)
+    if matches:
+        matches = [
+            re.sub(r'"\n\s+"', "", match) for match in matches
+        ]
+    # Assert that there are no such matches
+    assert not matches, f"Badly-spaced multiline strings found in {proto_file.name}: {', '.join(matches)}"
\ No newline at end of file