diff --git a/yazi-shared/src/condition.rs b/yazi-shared/src/condition.rs index e348045e..3a803d4a 100644 --- a/yazi-shared/src/condition.rs +++ b/yazi-shared/src/condition.rs @@ -72,7 +72,10 @@ impl Condition { let op = ConditionOp::new(token); match op { ConditionOp::Or | ConditionOp::And | ConditionOp::Not => { - while matches!(stack.last(), Some(last) if last.prec() >= op.prec()) { + while matches!( + stack.last(), + Some(last) if last.prec() > op.prec() || (op != ConditionOp::Not && last.prec() == op.prec()) + ) { output.push(stack.pop().unwrap()); } stack.push(op); @@ -129,3 +132,21 @@ impl Condition { if stack.len() == 1 { Some(stack[0]) } else { None } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_condition_not() -> anyhow::Result<()> { + let cond: Condition = "!!dir".parse()?; + assert!(cond.eval(|s| s == "dir").unwrap()); + assert!(!cond.eval(|_| false).unwrap()); + + let cond: Condition = "!!!dir".parse()?; + assert!(!cond.eval(|s| s == "dir").unwrap()); + assert!(cond.eval(|_| false).unwrap()); + + Ok(()) + } +}