Nesting works

This commit is contained in:
William Brown 2019-01-21 15:42:34 +13:00
parent 0b75e0d537
commit cc14125640
2 changed files with 29 additions and 17 deletions

View file

@ -319,20 +319,43 @@ mod tests {
fn test_nested_entry_filter() { fn test_nested_entry_filter() {
let e1: Entry = serde_json::from_str(r#"{ let e1: Entry = serde_json::from_str(r#"{
"attrs": { "attrs": {
"userid": ["william"], "class": ["person"],
"uidNumber": ["1000"]
}
}"#).unwrap();
let e2: Entry = serde_json::from_str(r#"{
"attrs": {
"class": ["person"],
"uidNumber": ["1001"]
}
}"#).unwrap();
let e3: Entry = serde_json::from_str(r#"{
"attrs": {
"class": ["person"],
"uidNumber": ["1002"]
}
}"#).unwrap();
let e4: Entry = serde_json::from_str(r#"{
"attrs": {
"class": ["group"],
"uidNumber": ["1000"] "uidNumber": ["1000"]
} }
}"#).unwrap(); }"#).unwrap();
let f_t1a = Filter::And(vec![ let f_t1a = Filter::And(vec![
Filter::Eq(String::from("class"), String::from("person")), Filter::Eq(String::from("class"), String::from("person")),
Filter::And(vec![ Filter::Or(vec![
Filter::Eq(String::from("uidNumber"), String::from("1001")), Filter::Eq(String::from("uidNumber"), String::from("1001")),
Filter::Eq(String::from("uidNumber"), String::from("1000")), Filter::Eq(String::from("uidNumber"), String::from("1000")),
]), ]),
]); ]);
println!("{:?}", f_t1a); assert!(f_t1a.entry_match_no_index(&e1));
assert!(false); assert!(f_t1a.entry_match_no_index(&e2));
assert!(!f_t1a.entry_match_no_index(&e3));
assert!(!f_t1a.entry_match_no_index(&e4));
} }
} }

View file

@ -1021,19 +1021,8 @@ impl SchemaInner {
} }
}) })
} }
Filter::Not(filters) => { Filter::Not(filter) => {
// This should never happen because self.validate_filter(filter)
// optimising should remove them as invalid parts?
if filters.len() == 0 {
return Err(SchemaError::EmptyFilter);
};
filters.iter().fold(Ok(()), |acc, filt| {
if acc.is_ok() {
self.validate_filter(filt)
} else {
acc
}
})
} }
} }
} }