any + all

This commit is contained in:
JMARyA 2025-05-07 09:03:34 +02:00
parent b1ad069731
commit 89517943f2
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 118 additions and 1 deletions

View file

@ -3,6 +3,80 @@ mod tests {
use crate::matches;
use serde_json::json;
#[test]
fn array_element_match() {
assert!(matches(
&json!(
{ "a": { "$contains": 3 }}
),
&json!({ "a": [1,2,3,4]})
));
}
#[test]
fn array_any_str() {
assert!(matches(
&json!(
{ "a": { "$any": { "$contains": "world"} }}
),
&json!({ "a": ["hello", "world"]})
));
}
#[test]
fn array_any_sub() {
assert!(matches(
&json!(
{ "a": { "$any": { "key": { "$contains": "world"} }}}
),
&json!({ "a": [{ "key": "hello" }, {"key": "world"}]})
));
}
#[test]
fn array_all_nested() {
assert!(!matches(
&json!(
{ "key": { "$all": { "$gt": 10} }}
),
&json!({ "key": [1,2,3,4,5]})
));
assert!(matches(
&json!(
{ "key": { "$all": { "$gt": 5} }}
),
&json!({ "key": [6,7,8,9]})
));
}
#[test]
fn array_all_direct() {
assert!(!matches(
&json!(
{ "$all": { "$gt": 10} }
),
&json!([1, 2, 3, 4, 5])
));
assert!(matches(
&json!(
{ "$all": { "$gt": 5} }
),
&json!([6, 7, 8, 9])
));
}
#[test]
fn array_any_direct() {
assert!(matches(
&json!(
{ "$any": { "$contains": "world"} }
),
&json!(["hello", "world"])
));
}
#[test]
fn simple_mask() {
assert!(matches(