aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSharad Chand2018-03-18 09:25:40 +0545
committerSharad Chand2018-03-18 09:25:40 +0545
commit2911d169468a232e90be81b6a00e21ce18be74b0 (patch)
treeae6989b571fdea87d599af28b49aa2b9b03fd003
parentbcc9b005a4784d1c67a1622c93589377dae4d11c (diff)
downloadvalidator-2911d169468a232e90be81b6a00e21ce18be74b0.tar.bz2
Added test to validate None values
-rw-r--r--validator_derive/tests/complex.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/validator_derive/tests/complex.rs b/validator_derive/tests/complex.rs
index e7495b4..bbbc2e6 100644
--- a/validator_derive/tests/complex.rs
+++ b/validator_derive/tests/complex.rs
@@ -185,3 +185,35 @@ fn test_works_with_question_mark_operator() {
assert!(some_fn().is_err());
}
+
+#[test]
+fn test_works_with_none_values() {
+ #[derive(Debug, Validate)]
+ struct PutStruct {
+ #[validate(length(min = "1", max = "10"))]
+ name: Option<String>,
+ #[validate(length(min = "1", max = "10"))]
+ address: Option<Option<String>>,
+ #[validate(range(min = "1", max = "100"))]
+ age: Option<Option<usize>>,
+ #[validate(range(min = "1", max = "10"))]
+ range: Option<usize>,
+ }
+
+ let p = PutStruct {
+ name: None,
+ address: None,
+ age: None,
+ range: None,
+ };
+
+ let q = PutStruct {
+ name: None,
+ address: Some(None),
+ age: Some(None),
+ range: None,
+ };
+
+ assert!(p.validate().is_ok());
+ assert!(q.validate().is_ok());
+} \ No newline at end of file