jsonlogic/operators/
equality.rs

1use serde_json::Value;
2
3use super::{logic, Data, Expression};
4
5pub fn compute(args: &[Expression], data: &Data) -> Value {
6    let a = args
7        .get(0)
8        .map(|arg| arg.compute(data))
9        .unwrap_or(Value::Null);
10    let b = args
11        .get(1)
12        .map(|arg| arg.compute(data))
13        .unwrap_or(Value::Null);
14
15    Value::Bool(logic::is_abstract_equal(&a, &b))
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21    use crate::compute_const;
22    use serde_json::json;
23
24    #[test]
25    fn default_null() {
26        assert_eq!(compute_const!(), Value::Bool(true));
27        assert_eq!(compute_const!(json!(null)), Value::Bool(true));
28    }
29
30    #[test]
31    fn test() {
32        assert_eq!(compute_const!(json!(null), json!(null)), Value::Bool(true));
33        assert_eq!(compute_const!(json!(1), json!(1)), Value::Bool(true));
34        assert_eq!(compute_const!(json!(1), json!(2)), Value::Bool(false));
35    }
36}