diff --git a/doc/src/workflow/action/group.md b/doc/src/workflow/action/group.md index 82f2b24..0b6d388 100644 --- a/doc/src/workflow/action/group.md +++ b/doc/src/workflow/action/group.md @@ -30,7 +30,7 @@ Each selector is a **table** with only one of the following keys: * `condition`: An array of three elements: The *JSON pointer*, *the operator*, and the *operand*. The [JSON pointer](../../guide/concepts/json-pointers.md) references a specific portion of the directory's value. The operator may be `"<"`, `"<="`, - `"=="`, `">="`, or `">"`. Both operands **must** have the same data type. The element + `"=="`, `"!="`, `">="`, or `">"`. Both operands **must** have the same data type. The element referenced by each JSON pointer must be present in the value of **every** directory. * `all`: Array of conditions (see above). All conditions must be `true` for this selector to be `true`. `all` is evaluated with short-circuit logic. When an element in `all` diff --git a/src/expr.rs b/src/expr.rs index 9e40d16..b46c02e 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -64,6 +64,7 @@ pub(crate) fn evaluate_json_comparison( (Comparison::LessThan, Some(Ordering::Less)) => Some(true), (Comparison::LessThanOrEqualTo, Some(Ordering::Less | Ordering::Equal)) => Some(true), (Comparison::EqualTo, Some(Ordering::Equal)) => Some(true), + (Comparison::NotEqualTo, Some(Ordering::Less | Ordering::Greater)) => Some(true), (Comparison::GreaterThanOrEqualTo, Some(Ordering::Greater | Ordering::Equal)) => Some(true), (Comparison::GreaterThan, Some(Ordering::Greater)) => Some(true), (_, None) => None, @@ -165,6 +166,22 @@ mod tests { evaluate_json_comparison(&Comparison::EqualTo, &Value::from(5), &Value::from(5)), Some(true) ); + assert_eq!( + evaluate_json_comparison(&Comparison::NotEqualTo, &Value::from(5), &Value::from(10)), + Some(true) + ); + assert_eq!( + evaluate_json_comparison(&Comparison::NotEqualTo, &Value::from(5), &Value::from(5)), + Some(false) + ); + assert_eq!( + evaluate_json_comparison( + &Comparison::NotEqualTo, + &Value::from(5), + &Value::from("abcd") + ), + None + ); assert_eq!( evaluate_json_comparison( &Comparison::GreaterThanOrEqualTo, diff --git a/src/workflow.rs b/src/workflow.rs index 45368e8..3aade5b 100644 --- a/src/workflow.rs +++ b/src/workflow.rs @@ -186,6 +186,8 @@ pub enum Comparison { LessThanOrEqualTo, #[serde(rename(deserialize = "=="))] EqualTo, + #[serde(rename(deserialize = "!="))] + NotEqualTo, #[serde(rename(deserialize = ">="))] GreaterThanOrEqualTo, #[serde(rename(deserialize = ">"))]