Skip to content

Commit

Permalink
[BUILD] Preprocess: support blank before --#if/pico8 and closing equi…
Browse files Browse the repository at this point in the history
…valents
  • Loading branch information
hsandt committed May 13, 2019
1 parent e35be0f commit 83d96af
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
10 changes: 5 additions & 5 deletions prebuild/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ class ParsingMode(Enum):

# tag to enter a pico8-only block (it's a comment block so that busted never runs it but preprocess reactivates it)
# unlike normal comment blocks, we expect to match from the line start
pico8_start_pattern = re.compile(r"--\[=*\[#pico8")
pico8_start_pattern = re.compile(r"\s*--\[=*\[#pico8")
# closing tag for pico8-only block. Unlike normal comment blocks, we expect to match from the line start and we ignore anything after the block end!
pico8_end_pattern = re.compile(r"--#pico8]=*]")
pico8_end_pattern = re.compile(r"\s*--#pico8]=*]")

if_pattern = re.compile(r"--#if (\w+)") # ! ignore anything after 1st symbol
ifn_pattern = re.compile(r"--#ifn (\w+)") # ! ignore anything after 1st symbol
endif_pattern = re.compile(r"--#endif")
if_pattern = re.compile(r"\s*--#if (\w+)") # ! ignore anything after 1st symbol
ifn_pattern = re.compile(r"\s*--#ifn (\w+)") # ! ignore anything after 1st symbol
endif_pattern = re.compile(r"\s*--#endif")
stripped_function_call_patterns_table = {}
for config, stripped_functions in stripped_functions_table.items():
# if there is nothing to strip, avoid creating a regex with just "(?:)\(\)" that would match a line starting with brackets
Expand Down
58 changes: 58 additions & 0 deletions prebuild/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,30 @@ def test_preprocess_lines_missing_endif_ignored(self):
# this will also trigger a warning, but we don't test it
self.assertEqual(preprocess.preprocess_lines(test_lines, 'release'), expected_processed_lines)

def test_preprocess_lines_if_after_blank_acknowledged(self):
test_lines = [
' --#if log\n',
' print("debug")\n',
' --#endif\n',
]
expected_processed_lines = [
' print("debug")\n',
]
self.assertEqual(preprocess.preprocess_lines(test_lines, 'debug'), expected_processed_lines)

def test_preprocess_lines_if_after_non_blank_preserved(self):
test_lines = [
'text before --#if log\n',
'print("debug")\n',
'text before --#endif\n',
]
expected_processed_lines = [
'text before --#if log\n',
'print("debug")\n',
'text before --#endif\n',
]
self.assertEqual(preprocess.preprocess_lines(test_lines, 'release'), expected_processed_lines)

def test_preprocess_lines_pico8_block(self):
test_lines = [
'print("start")\n',
Expand Down Expand Up @@ -407,6 +431,40 @@ def test_preprocess_lines_missing_end_pico8_ignored(self):
# this will also trigger a warning, but we don't test it
self.assertEqual(preprocess.preprocess_lines(test_lines, 'release'), expected_processed_lines)

def test_preprocess_lines_pico8_after_blank_acknowledged(self):
test_lines = [
'print("start")\n',
' --[[#pico8 pico8 start\n',
'real pico8 code\n',
' --#pico8]] exceptionally ignored\n',
'print("end")\n',
]
expected_processed_lines = [
'print("start")\n',
'real pico8 code\n',
'print("end")\n',
]
# this will also trigger a warning, but we don't test it
self.assertEqual(preprocess.preprocess_lines(test_lines, 'release'), expected_processed_lines)

def test_preprocess_lines_pico8_after_non_blank_preserved(self):
test_lines = [
'print("start")\n',
'text --[[#pico8 pico8 start\n',
'real pico8 code\n',
'text --#pico8]] exceptionally ignored\n',
'print("end")\n',
]
expected_processed_lines = [
'print("start")\n',
'text --[[#pico8 pico8 start\n',
'real pico8 code\n',
'text --#pico8]] exceptionally ignored\n',
'print("end")\n',
]
# this will also trigger a warning, but we don't test it
self.assertEqual(preprocess.preprocess_lines(test_lines, 'release'), expected_processed_lines)

def test_preprocess_lines_with_unknown_config(self):
test_lines = []
self.assertRaises(ValueError, preprocess.preprocess_lines, test_lines, 'unknown')
Expand Down

0 comments on commit 83d96af

Please sign in to comment.