isolate_tests.py: Parse Sphinx block parameters correctly

This commit is contained in:
Kamil Śliwak
2021-06-21 20:54:12 +02:00
parent a96114b3c5
commit 0311b955c2
4 changed files with 152 additions and 5 deletions
+20 -5
View File
@@ -38,19 +38,34 @@ def extract_test_cases(path):
# Look for `pragma solidity`, `contract`, `library` or `interface`
# and abort a line not indented properly.
def extract_docs_cases(path):
inside = False
insideBlock = False
insideBlockParameters = False
pastBlockParameters = False
extractedLines = []
tests = []
# Collect all snippets of indented blocks
for l in open(path, mode='r', errors='ignore', encoding='utf8', newline='').read().splitlines():
if l != '':
if not inside and l.startswith(' '):
if not insideBlock and l.startswith(' '):
# start new test
extractedLines += ['']
inside = l.startswith(' ')
if inside:
extractedLines[-1] += l + '\n'
insideBlockParameters = False
pastBlockParameters = False
insideBlock = l.startswith(' ')
if insideBlock:
if not pastBlockParameters:
# NOTE: For simplicity this allows blank lines between block parameters even
# though Sphinx does not. This does not matter since the first non-empty line in
# a Solidity file cannot start with a colon anyway.
if not l.strip().startswith(':') and (l != '' or not insideBlockParameters):
insideBlockParameters = False
pastBlockParameters = True
else:
insideBlockParameters = True
if not insideBlockParameters:
extractedLines[-1] += l + '\n'
codeStart = "(// SPDX-License-Identifier:|pragma solidity|contract.*{|library.*{|interface.*{)"