From e35185be8120176da476260e0447981d1a4c40a3 Mon Sep 17 00:00:00 2001 From: "Guillem L. Jara" <4lon3ly0@tutanota.com> Date: Fri, 15 May 2026 15:47:45 +0200 Subject: [PATCH] chore(parser): add tests --- parser/src/sexpr.rs | 2 +- parser/src/tests.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/parser/src/sexpr.rs b/parser/src/sexpr.rs index 6810bb2..f221e2e 100644 --- a/parser/src/sexpr.rs +++ b/parser/src/sexpr.rs @@ -265,7 +265,7 @@ impl Debug for Atom<'_> { impl Debug for Place<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> Result { match self { - Self::Record(expr) => write!(f, "($ {expr:?})"), + Self::Record(expr) => write!(f, "(Record {expr:?})"), Self::Variable(var) => <_ as Debug>::fmt(var, f), Self::ArrayElement(var, index) => write!(f, "(index {var:?} {index:?})"), } diff --git a/parser/src/tests.rs b/parser/src/tests.rs index 0932f23..8c942f9 100644 --- a/parser/src/tests.rs +++ b/parser/src/tests.rs @@ -179,3 +179,38 @@ fn test_parser_valid_patterns() { fn test_parser_invalid_patterns() { test_parser!(is_err!("BEGIN", "END", "BEGINFILE", "ENDFILE", "print 1;")); } + +#[test] +fn test_parser_non_assoc() { + test_parser!(is_err!( + "a == b == c", + "a != b != c", + "a > b > c", + "a < b < c", + "a >= b >= c", + "a <= b <= c" + )); +} + +#[test] +fn test_parser_relaxed_assignments() { + let source = " + { 1 + 0 && x = 1 } + { y = @/a/ ? b : c } + { 1 + 0 || z = @/a/ ? b : c } + { 1 + 0 || z = /a/ && b || c } + "; + test_parser!( + source => { + rules: [ + (None, Some("(body (And (Add 1 0) (Assignment awk::x 1)))")), + (None, Some("(body (?: (Assignment awk::y @/a/) awk::b awk::c))")), + (None, Some("(body (?: (Or (Add 1 0) (Assignment awk::z @/a/)) awk::b awk::c))")), + ( + None, + Some("(body (Or (Add 1 0) (Assignment awk::z (Or (And /a/ awk::b) awk::c))))"), + ), + ], + } + ); +}