add test for VerifyFn

This commit is contained in:
Dietmar Maurer 2018-11-24 08:30:23 +01:00
parent 715f22fb4a
commit a23dd9bb42
1 changed files with 17 additions and 0 deletions

View File

@ -644,3 +644,20 @@ fn test_query_boolean() {
assert!(res.is_ok());
}
#[test]
fn test_verify_function() {
let schema = ObjectSchema::new("Parameters.")
.required(
"p1", StringSchema::new("P1")
.format(ApiStringFormat::VerifyFn(|value| {
if value == "test" { return Ok(()) };
bail!("format error");
}).into())
);
let res = parse_query_string("p1=tes", &schema, true);
assert!(res.is_err());
let res = parse_query_string("p1=test", &schema, true);
assert!(res.is_ok());
}