tests/misc.py

changeset 78
1970afe52da4
parent 75
3ec747dfbfb9
child 86
b25fc6f7eb70
--- a/tests/misc.py	Sun Jun 23 12:09:20 2019 +0300
+++ b/tests/misc.py	Sun Jun 23 12:17:40 2019 +0300
@@ -184,6 +184,32 @@
                 bad_object = model.body[index],
             )
 
+@problem_type('unknown-metacommand',
+    severity = 'hold',
+    message = lambda command_text: str.format(
+        'unknown or deprecated metacommand: {command_text}',
+        command_text = command_text,
+    )
+)
+def metacommands_test(model):
+    allowed_metacommand_patterns = [
+        r'^BFC (CLIP|NOCLIP|INVERTNEXT)$',
+        r'^\!TEXMAP (START|NEXT) .+',
+        r'^\!: .+',
+        r'^\!TEXMAP (FALLBACK|END)$',
+    ]
+    import re
+    for element in model.body[model.header_size:]:
+        if isinstance(element, linetypes.MetaCommand):
+            if element.text and not any(
+                re.match(pattern, element.text)
+                for pattern in allowed_metacommand_patterns
+            ):
+                yield report_problem('unknown-metacommand',
+                    bad_object = element,
+                    command_text = element.text,
+                )
+
 manifest = {
     'tests': [
         colours_test,
@@ -197,5 +223,6 @@
         colour_24_test,
         moved_to_with_extension_test,
         bfc_invertnext_not_on_subfile_test,
+        metacommands_test,
     ],
 }

mercurial