cli: capture complete source parser ranges
This commit is contained in:
1 parent
1a80c42289
commit
ba2cb1340a
3 files changed
+180
-16
No files matched your search
@@ -7,6 +7,7 @@ in place; --write tests use temporary files. Runs use fuel, without timeouts.
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
@@ -23,6 +24,20 @@ def cli(*args, code=0):
|
||||
return result.stdout
|
||||
|
||||
|
||||
def annotation_ranges(path, canonical):
|
||||
annotated = cli("lower", "--annotate", path)
|
||||
ordinary = []
|
||||
for line in annotated.splitlines(keepends=True):
|
||||
match = re.fullmatch(rb'\s*; (?:(.+):)?(\d+):(\d+)-(\d+):(\d+)\n', line)
|
||||
if match:
|
||||
start = tuple(map(int, match.group(2, 3)))
|
||||
end = tuple(map(int, match.group(4, 5)))
|
||||
assert min(*start, *end) >= 1 and start < end, (path, line)
|
||||
else:
|
||||
ordinary.append(line)
|
||||
assert b''.join(ordinary) == canonical, path
|
||||
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="aji-format-") as directory:
|
||||
root = Path(directory)
|
||||
fixture = REPO / "tests/format/layout.aji"
|
||||
@@ -182,6 +197,7 @@ with tempfile.TemporaryDirectory(prefix="aji-format-") as directory:
|
||||
checks += 1
|
||||
if lower.returncode == 0:
|
||||
assert cli("lower", formatted) == lower.stdout, path
|
||||
annotation_ranges(path, lower.stdout)
|
||||
lowered += 1
|
||||
else:
|
||||
assert lower.returncode in (1, 3), (path, lower.returncode, lower.stderr)
|
||||
|
||||
Reference in new issue
Block a user