chore(parser): add tests

This commit is contained in:
Guillem L. Jara
2026-05-16 17:40:12 +02:00
parent d276095dc0
commit ee9785435a
2 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -267,7 +267,7 @@ impl Debug for Place<'_> {
match self {
Self::Record(expr) => write!(f, "(Record {expr:?})"),
Self::Variable(var) => <_ as Debug>::fmt(var, f),
Self::ArrayElement(var, index) => write!(f, "(index {var:?} {index:?})"),
Self::ArrayElement(var, index) => write!(f, "(ArrayAccess {var:?} {index:?})"),
}
}
}
+24
View File
@@ -214,3 +214,27 @@ fn test_parser_relaxed_assignments() {
}
);
}
#[test]
fn test_parser_inc_dec() {
let source = r#"
{ ++a $0-- }
{ --a[2] ++$(1 + 1) }
{ a++ a["x"]-- }
{ --a $"a"++ }
"#;
test_parser!(source => {
rules: [
(None, Some("(body (Concat (IncrementL awk::a) (DecrementR (Record 0))))")),
(
None,
Some("(body (Concat (DecrementL (ArrayAccess awk::a 2)) (IncrementL (Record (Add 1 1)))))")
),
(None, Some("(body (Concat (IncrementR awk::a) (DecrementR (ArrayAccess awk::a \"x\"))))")),
(None, Some("(body (Concat (DecrementL awk::a) (IncrementR (Record \"a\"))))")),
],
});
// these should parse as (Cat (--L (++R $0)) a), or otherwise error out.
// FIXME: not treated as errors yet.
// test_parser!(is_err!("{ $0++ --a }", "{ ++$0 ++a }"));
}