cli: preserve keyword spacing in unpack and grouped ranges

This commit is contained in:
dev committed 2026-10-07 20:36:27 +03:00
1 parent 9001e56325
commit b1629a59fd
2 files changed
+28 -2

No files matched your search

+15
View File
@@ -112,6 +112,21 @@ with tempfile.TemporaryDirectory(prefix="aji-format-") as directory:
assert b"// lit \t\n b: 2u64" in text
assert b"not (true and false)" in text
# Grouped range bounds and unpack bindings have keyword spacing,
# while calls and the range operator stay compact. AIR stays identical.
sample = root / "keyword-spaces.aji"
sample.write_bytes(b"module spaces fn main()->u64 effects [] {let p=[1u64,2u64];"
b"let(a,b)=array.unpack(p);var n:u64=0;"
b"for i in(0usize)..(2usize){n=n+a+b;}n}")
original_air = cli("lower", sample)
text = cli("fmt", sample)
assert b"let (a, b) = array.unpack(p);" in text
assert b"for i in (0usize)..(2usize)" in text
sample.write_bytes(text)
assert cli("fmt", sample) == text
assert cli("lower", sample) == original_air
assert json.loads(cli("run", "--fuel", "10000", sample))["value"] == 6
# Q-040: statement boundaries are lexical, not dependent on the original
# line breaks. Formatting exposes them without inserting separators.
for construct in ("{*p=2u64;}", "if true {*p=2u64;} else {}",