cli: disambiguate block statement boundaries
This commit is contained in:
1 parent
462ddd2c5c
commit
911982dd1c
33 files changed
+465
-7
No files matched your search
@@ -112,6 +112,40 @@ 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
|
||||
|
||||
# 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 {}",
|
||||
"match 0u64 {0=>{*p=2u64;} _=>{}}"):
|
||||
for gap in (" ", "\n", " // boundary\n"):
|
||||
source = ("module boundary fn main()->u64 effects [] {"
|
||||
"var x:u64=1u64; mut p=x;" + construct + gap +
|
||||
"*p=*p+3u64;return *p;}").encode()
|
||||
sample = root / "boundary.aji"
|
||||
sample.write_bytes(source)
|
||||
original_air = cli("lower", sample)
|
||||
assert json.loads(cli("run", "--fuel", "10000", sample))["value"] == 5
|
||||
text = cli("fmt", sample)
|
||||
assert b"}\n *p = *p + 3u64;" in text or b"// boundary\n *p = *p + 3u64;" in text
|
||||
sample.write_bytes(text)
|
||||
assert cli("fmt", sample) == text
|
||||
assert cli("lower", sample) == original_air
|
||||
|
||||
# Former value-producing continuations must reject, rather than silently
|
||||
# discard their left operand. A formatter can still format rejected code.
|
||||
for body in ("{2u64} *3u64", "{2i64} -3i64",
|
||||
"if true {2u64} else {3u64} return 0u64;",
|
||||
"match 0u64 {0=>{2u64} _=>{3u64}} return 0u64;"):
|
||||
sample = root / "value-boundary.aji"
|
||||
source = ("module boundary fn main()->u64 effects [] {" + body + "}").encode()
|
||||
sample.write_bytes(source)
|
||||
error = json.loads(cli("lower", sample, code=1))
|
||||
assert error["code"] == "E7006" and "parentheses" in error["message"]
|
||||
assert error["line"] == 1 and error["col"] == source.index(body.encode()) + 1
|
||||
text = cli("fmt", sample)
|
||||
sample.write_bytes(text)
|
||||
assert cli("fmt", sample) == text
|
||||
assert json.loads(cli("lower", sample, code=1))["code"] == "E7006"
|
||||
|
||||
parsed = syntax_errors = lowered = 0
|
||||
files = sorted({p for directory in (REPO / "tests/conformance/source", REPO / "std", REPO / "examples")
|
||||
for p in directory.rglob("*.aji")})
|
||||
|
||||
Reference in new issue
Block a user