From a23dd9bb428fc958e98a0a086e1895cd5ec32f69 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 24 Nov 2018 08:30:23 +0100 Subject: [PATCH] add test for VerifyFn --- src/api/schema.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/api/schema.rs b/src/api/schema.rs index 270d0983..7e2ebc3c 100644 --- a/src/api/schema.rs +++ b/src/api/schema.rs @@ -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()); +}