Fix a test that forget to match a Null value

This commit is contained in:
Clément Renault 2023-03-15 16:57:09 +01:00
parent 1a9c58a7ab
commit cf34d1c95f
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -212,13 +212,13 @@ fn execute_filter(filter: &str, document: &TestDocument) -> Option<String> {
} else if matches!(filter, "opt1.opt2 IS NULL") { } else if matches!(filter, "opt1.opt2 IS NULL") {
if document.opt1opt2.as_ref().map_or(false, |v| v.is_null()) { if document.opt1opt2.as_ref().map_or(false, |v| v.is_null()) {
id = Some(document.id.clone()); id = Some(document.id.clone());
} else if let Some(opt1) = &document.opt1 {
if !opt1.is_null() {
id = contains_null_rec(opt1, "opt2").then(|| document.id.clone());
}
} }
} else if matches!(filter, "opt1 IS EMPTY" | "NOT opt1 IS NOT EMPTY") { } else if matches!(filter, "opt1 IS EMPTY" | "NOT opt1 IS NOT EMPTY") {
id = document id = document.opt1.as_ref().map_or(false, is_empty_value).then(|| document.id.clone());
.opt1
.as_ref()
.map_or(false, |v| is_empty_value(v))
.then(|| document.id.clone());
} else if matches!(filter, "NOT opt1 IS EMPTY" | "opt1 IS NOT EMPTY") { } else if matches!(filter, "NOT opt1 IS EMPTY" | "opt1 IS NOT EMPTY") {
id = document id = document
.opt1 .opt1
@ -226,7 +226,7 @@ fn execute_filter(filter: &str, document: &TestDocument) -> Option<String> {
.map_or(true, |v| !is_empty_value(v)) .map_or(true, |v| !is_empty_value(v))
.then(|| document.id.clone()); .then(|| document.id.clone());
} else if matches!(filter, "opt1.opt2 IS EMPTY") { } else if matches!(filter, "opt1.opt2 IS EMPTY") {
if document.opt1opt2.as_ref().map_or(false, |v| is_empty_value(v)) { if document.opt1opt2.as_ref().map_or(false, is_empty_value) {
id = Some(document.id.clone()); id = Some(document.id.clone());
} }
} else if matches!( } else if matches!(
@ -273,6 +273,28 @@ pub fn contains_key_rec(v: &serde_json::Value, key: &str) -> bool {
} }
} }
pub fn contains_null_rec(v: &serde_json::Value, key: &str) -> bool {
match v {
serde_json::Value::Object(v) => {
for (k, v) in v.iter() {
if k == key && v.is_null() || contains_null_rec(v, key) {
return true;
}
}
false
}
serde_json::Value::Array(v) => {
for v in v.iter() {
if contains_null_rec(v, key) {
return true;
}
}
false
}
_ => false,
}
}
pub fn expected_filtered_ids(filters: Vec<Either<Vec<&str>, &str>>) -> HashSet<String> { pub fn expected_filtered_ids(filters: Vec<Either<Vec<&str>, &str>>) -> HashSet<String> {
let dataset: Vec<TestDocument> = let dataset: Vec<TestDocument> =
serde_json::Deserializer::from_str(CONTENT).into_iter().map(|r| r.unwrap()).collect(); serde_json::Deserializer::from_str(CONTENT).into_iter().map(|r| r.unwrap()).collect();