#[cfg(test)]
mod tests {
use jsonlogic::validation::{validate, RequireAndWrapper, ValidationConfig};
use serde_json::json;
#[test]
fn test_and_wrapper_validation() {
let config = ValidationConfig {
require_and_wrapper: Some(RequireAndWrapper { allow_empty: true }),
..Default::default()
};
let empty_logic = json!({});
assert!(validate(&empty_logic, &config).is_ok());
let valid_logic = json!({
"and": [
{"==": [{"var": "age"}, 18]},
{">=": [{"var": "score"}, 70]}
]
});
assert!(validate(&valid_logic, &config).is_ok());
let invalid_logic = json!({
"==": [{"var": "age"}, 18]
});
assert!(validate(&invalid_logic, &config).is_err());
let strict_config = ValidationConfig {
require_and_wrapper: Some(RequireAndWrapper { allow_empty: false }),
..Default::default()
};
assert!(validate(&invalid_logic, &config).is_err());
assert!(validate(&empty_logic, &strict_config).is_err());
assert!(validate(&valid_logic, &strict_config).is_ok());
}
}