diff options
| author | Vincent Prouillet | 2018-03-20 19:01:23 +0100 |
|---|---|---|
| committer | GitHub | 2018-03-20 19:01:23 +0100 |
| commit | f5b8e9910b9714a5990d173b3a1cc856641ee454 (patch) | |
| tree | e31551babd75ccc41696347370f11c62d4b649c1 /validator_derive/tests/complex.rs | |
| parent | f07c87b0e90f1d2ef8fe806160863ce179d133b7 (diff) | |
| parent | 2911d169468a232e90be81b6a00e21ce18be74b0 (diff) | |
| download | validator-f5b8e9910b9714a5990d173b3a1cc856641ee454.tar.bz2 | |
Merge pull request #44 from csharad/double-option
Support for validating Option<Option<T>>. Fixes #41
Diffstat (limited to 'validator_derive/tests/complex.rs')
| -rw-r--r-- | validator_derive/tests/complex.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/validator_derive/tests/complex.rs b/validator_derive/tests/complex.rs index 0bd74fa..bbbc2e6 100644 --- a/validator_derive/tests/complex.rs +++ b/validator_derive/tests/complex.rs @@ -81,6 +81,10 @@ fn test_can_validate_option_fields_with_lifetime() { struct PutStruct<'a> { #[validate(length(min = "1", max = "10"))] name: Option<&'a str>, + #[validate(length(min = "1", max = "10"))] + address: Option<Option<&'a str>>, + #[validate(range(min = "1", max = "100"))] + age: Option<Option<usize>>, #[validate(range(min = "1", max = "10"))] range: Option<usize>, #[validate(email)] @@ -101,6 +105,8 @@ fn test_can_validate_option_fields_with_lifetime() { let s = PutStruct { name: Some("al"), + address: Some(Some("gol")), + age: Some(Some(20)), range: Some(2), email: Some("hi@gmail.com"), url: Some("http://google.com"), @@ -122,7 +128,13 @@ fn test_can_validate_option_fields_without_lifetime() { #[validate(length(min = "1", max = "10"))] name: Option<String>, #[validate(length(min = "1", max = "10"))] + address: Option<Option<String>>, + #[validate(length(min = "1", max = "10"))] ids: Option<Vec<usize>>, + #[validate(length(min = "1", max = "10"))] + opt_ids: Option<Option<Vec<usize>>>, + #[validate(range(min = "1", max = "100"))] + age: Option<Option<usize>>, #[validate(range(min = "1", max = "10"))] range: Option<usize>, #[validate(email)] @@ -143,7 +155,10 @@ fn test_can_validate_option_fields_without_lifetime() { let s = PutStruct { name: Some("al".to_string()), + address: Some(Some("gol".to_string())), ids: Some(vec![1, 2, 3]), + opt_ids: Some(Some(vec![1, 2, 3])), + age: Some(Some(20)), range: Some(2), email: Some("hi@gmail.com".to_string()), url: Some("http://google.com".to_string()), @@ -170,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 |
