added a test for unknown metacommands

Sun, 23 Jun 2019 12:17:40 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 23 Jun 2019 12:17:40 +0300
changeset 78
1970afe52da4
parent 77
d98502ae1f33
child 79
eb93feb6d3a3

added a test for unknown metacommands

tests/misc.py file | annotate | diff | comparison | revisions
--- 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