mirror of
https://github.com/uutils/awk.git
synced 2026-06-10 16:15:04 -07:00
chore(parser): add tests
This commit is contained in:
+1
-1
@@ -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:?})"),
|
||||
}
|
||||
|
||||
@@ -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))))"),
|
||||
),
|
||||
],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user