✨ any + all
This commit is contained in:
parent
b1ad069731
commit
89517943f2
3 changed files with 118 additions and 1 deletions
74
src/test.rs
74
src/test.rs
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue