52 lines
2.9 KiB
Python
52 lines
2.9 KiB
Python
"""Parent raw-byte check of independently authored fixture/index expectations."""
|
|
from pathlib import Path
|
|
import json
|
|
import re
|
|
|
|
def ident(n):
|
|
return f'00000000-0000-0000-0000-{n:012}'
|
|
|
|
body = (f'node n id "{ident(4)}" {{ diagram @d; element @v; }}\n'
|
|
f'oa_property v "Value" id "{ident(3)}" {{ subject @w; type Number; base 1; }}\n'
|
|
f'oa_activity w "Work" id "{ident(2)}" {{}}\n'
|
|
f'diagram d "Diagram" id "{ident(5)}" {{ }}\n')
|
|
main = f'arcadia 8;\nproject p "Project" id "{ident(1)}" {{\n{body}\n}}\n'
|
|
main = main.replace('base 1;', 'base @f(y: 2, x: @g(x: 3, y: 4)) + @f(x: 5, y: 6);')
|
|
main = main.replace('node n', 'include "b.arcadia"; include "a.arcadia";\nnode n')
|
|
files = []
|
|
for alias, name, n, op in [('f', 'F', 10, '+'), ('g', 'G', 11, '-')]:
|
|
files.append((f'calculation {alias} "{name}" id "{ident(n)}" {{\n'
|
|
f'input x id "{ident(1)}" : Number;\n'
|
|
f'input y id "{ident(12)}" : Number;\n'
|
|
f'result Number; body $x {op} $y;\n}}\n').encode())
|
|
files.append(main.encode())
|
|
assert list(map(len, files)) == [213, 213, 474]
|
|
oracle = Path(__file__).with_name('ORACLE.md').read_text(encoding='utf-8')
|
|
rows = [line.split('|')[1:-1] for line in oracle.splitlines() if re.match(r'\| (E|H|O)\d+ \|', line)]
|
|
expressions = [r for r in rows if r[0].strip().startswith('E')]
|
|
occurrences = [r for r in rows if not r[0].strip().startswith('E')]
|
|
expected_expressions = ['$x + $y', '$x', '$y', '$x - $y', '$x', '$y',
|
|
'@f(y: 2, x: @g(x: 3, y: 4)) + @f(x: 5, y: 6)',
|
|
'@f(y: 2, x: @g(x: 3, y: 4))', '2', '@g(x: 3, y: 4)', '3', '4',
|
|
'@f(x: 5, y: 6)', '5', '6']
|
|
expected_occurrences = ['f', 'g', 'v', 'x', 'y', 'x', 'y', 'x', 'y', 'x', 'y',
|
|
'w', 'f', 'y', 'x', 'g', 'x', 'y', 'f', 'x', 'y']
|
|
assert len(expressions) == 15 and len(occurrences) == 21
|
|
checks = []
|
|
for group, expected, span_column in [(expressions, expected_expressions, 5),
|
|
(occurrences, expected_occurrences, 7)]:
|
|
for row, value in zip(group, expected, strict=True):
|
|
name, file = row[0].strip(), int(row[1])
|
|
start, end = map(int, row[span_column].strip().split('..'))
|
|
assert files[file][start:end] == value.encode(), (name, files[file][start:end], value)
|
|
transformed = b'// \xe9\x9b\xa8\r\n' + files[file].replace(b'\n', b'\r\n')
|
|
shifted_start = 8 + start + files[file][:start].count(b'\n')
|
|
shifted_end = 8 + end + files[file][:end].count(b'\n')
|
|
assert transformed[shifted_start:shifted_end] == value.encode()
|
|
checks.append(name)
|
|
assert 11 + 21 + 15 + 12 == 59
|
|
print(json.dumps({'result': 'PASS', 'file_bytes': list(map(len, files)),
|
|
'original_span_checks': len(checks), 'unicode_crlf_span_checks': len(checks),
|
|
'retained_entries': 59, 'retained_name_bytes': 11,
|
|
'scope': 'Independent raw fixture/byte arithmetic, no parser, lowerer, index or compiler execution.'}))
|