diff options
Diffstat (limited to 'validator_derive/tests')
| -rw-r--r-- | validator_derive/tests/complex.rs | 64 | ||||
| -rw-r--r-- | validator_derive/tests/contains.rs | 16 | ||||
| -rw-r--r-- | validator_derive/tests/credit_card.rs | 16 | ||||
| -rw-r--r-- | validator_derive/tests/custom.rs | 12 | ||||
| -rw-r--r-- | validator_derive/tests/email.rs | 17 | ||||
| -rw-r--r-- | validator_derive/tests/length.rs | 16 | ||||
| -rw-r--r-- | validator_derive/tests/must_match.rs | 21 | ||||
| -rw-r--r-- | validator_derive/tests/nested.rs | 117 | ||||
| -rw-r--r-- | validator_derive/tests/phone.rs | 17 | ||||
| -rw-r--r-- | validator_derive/tests/range.rs | 16 | ||||
| -rw-r--r-- | validator_derive/tests/regex.rs | 18 | ||||
| -rw-r--r-- | validator_derive/tests/schema.rs | 22 | ||||
| -rw-r--r-- | validator_derive/tests/url.rs | 17 |
13 files changed, 109 insertions, 260 deletions
diff --git a/validator_derive/tests/complex.rs b/validator_derive/tests/complex.rs index 0df26c0..7826a49 100644 --- a/validator_derive/tests/complex.rs +++ b/validator_derive/tests/complex.rs @@ -3,15 +3,14 @@ extern crate validator_derive; extern crate validator; #[macro_use] extern crate serde_derive; -extern crate serde_json; extern crate regex; +extern crate serde_json; #[macro_use] extern crate lazy_static; use regex::Regex; -use validator::{Validate, ValidationError, ValidationErrors, ValidationErrorsKind}; use std::collections::HashMap; - +use validator::{Validate, ValidationError, ValidationErrors, ValidationErrorsKind}; fn validate_unique_username(username: &str) -> Result<(), ValidationError> { if username == "xXxShad0wxXx" { @@ -46,13 +45,13 @@ struct SignupData { #[validate] card: Option<Card>, #[validate] - preferences: Vec<Preference> + preferences: Vec<Preference>, } #[derive(Debug, Validate, Deserialize)] struct Phone { #[validate(phone)] - number: String + number: String, } #[derive(Debug, Validate, Deserialize)] @@ -77,19 +76,9 @@ fn is_fine_with_many_valid_validations() { site: "http://hello.com".to_string(), first_name: "Bob".to_string(), age: 18, - phone: Phone { - number: "+14152370800".to_string() - }, - card: Some(Card { - number: "5236313877109142".to_string(), - cvv: 123 - }), - preferences: vec![ - Preference { - name: "marketing".to_string(), - value: false - }, - ] + phone: Phone { number: "+14152370800".to_string() }, + card: Some(Card { number: "5236313877109142".to_string(), cvv: 123 }), + preferences: vec![Preference { name: "marketing".to_string(), value: false }], }; assert!(signup.validate().is_ok()); @@ -102,19 +91,9 @@ fn failed_validation_points_to_original_field_name() { site: "http://hello.com".to_string(), first_name: "".to_string(), age: 18, - phone: Phone { - number: "123 invalid".to_string(), - }, - card: Some(Card { - number: "1234567890123456".to_string(), - cvv: 1 - }), - preferences: vec![ - Preference { - name: "abc".to_string(), - value: true - }, - ] + phone: Phone { number: "123 invalid".to_string() }, + card: Some(Card { number: "1234567890123456".to_string(), cvv: 1 }), + preferences: vec![Preference { name: "abc".to_string(), value: true }], }; let res = signup.validate(); // println!("{}", serde_json::to_string(&res).unwrap()); @@ -286,9 +265,7 @@ fn test_works_with_question_mark_operator() { site: "http://hello.com".to_string(), first_name: "Bob".to_string(), age: 18, - phone: Phone { - number: "+14152370800".to_string() - }, + phone: Phone { number: "+14152370800".to_string() }, card: None, preferences: Vec::new(), }; @@ -314,27 +291,18 @@ fn test_works_with_none_values() { range: Option<usize>, } - let p = PutStruct { - name: None, - address: None, - age: None, - range: None, - }; + let p = PutStruct { name: None, address: None, age: None, range: None }; - let q = PutStruct { - name: None, - address: Some(None), - age: Some(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()); } fn unwrap_map<F>(errors: &Box<ValidationErrors>, f: F) - where F: FnOnce(HashMap<&'static str, ValidationErrorsKind>) +where + F: FnOnce(HashMap<&'static str, ValidationErrorsKind>), { let errors = *errors.clone(); f(errors.errors()); -}
\ No newline at end of file +} diff --git a/validator_derive/tests/contains.rs b/validator_derive/tests/contains.rs index 5e9060e..1fd568d 100644 --- a/validator_derive/tests/contains.rs +++ b/validator_derive/tests/contains.rs @@ -12,9 +12,7 @@ fn can_validate_contains_ok() { val: String, } - let s = TestStruct { - val: "hello".to_string(), - }; + let s = TestStruct { val: "hello".to_string() }; assert!(s.validate().is_ok()); } @@ -27,9 +25,7 @@ fn value_not_containing_needle_fails_validation() { val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -47,9 +43,7 @@ fn can_specify_code_for_contains() { #[validate(contains(pattern = "he", code = "oops"))] val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -65,9 +59,7 @@ fn can_specify_message_for_contains() { #[validate(contains(pattern = "he", message = "oops"))] val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/credit_card.rs b/validator_derive/tests/credit_card.rs index b1a9da3..d212c48 100644 --- a/validator_derive/tests/credit_card.rs +++ b/validator_derive/tests/credit_card.rs @@ -13,9 +13,7 @@ fn can_validate_valid_card_number() { val: String, } - let s = TestStruct { - val: "5236313877109142".to_string(), - }; + let s = TestStruct { val: "5236313877109142".to_string() }; assert!(s.validate().is_ok()); } @@ -29,9 +27,7 @@ fn bad_credit_card_fails_validation() { val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -49,9 +45,7 @@ fn can_specify_code_for_credit_card() { #[validate(credit_card(code = "oops"))] val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -68,9 +62,7 @@ fn can_specify_message_for_credit_card() { #[validate(credit_card(message = "oops"))] val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/custom.rs b/validator_derive/tests/custom.rs index cd1b354..c13853d 100644 --- a/validator_derive/tests/custom.rs +++ b/validator_derive/tests/custom.rs @@ -20,9 +20,7 @@ fn can_validate_custom_fn_ok() { val: String, } - let s = TestStruct { - val: "hello".to_string(), - }; + let s = TestStruct { val: "hello".to_string() }; assert!(s.validate().is_ok()); } @@ -35,9 +33,7 @@ fn can_fail_custom_fn_validation() { val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -54,9 +50,7 @@ fn can_specify_message_for_custom_fn() { #[validate(custom(function = "invalid_custom_fn", message = "oops"))] val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/email.rs b/validator_derive/tests/email.rs index 4fbc123..665f0da 100644 --- a/validator_derive/tests/email.rs +++ b/validator_derive/tests/email.rs @@ -4,7 +4,6 @@ extern crate validator; use validator::Validate; - #[test] fn can_validate_valid_email() { #[derive(Debug, Validate)] @@ -13,9 +12,7 @@ fn can_validate_valid_email() { val: String, } - let s = TestStruct { - val: "bob@bob.com".to_string(), - }; + let s = TestStruct { val: "bob@bob.com".to_string() }; assert!(s.validate().is_ok()); } @@ -28,9 +25,7 @@ fn bad_email_fails_validation() { val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -47,9 +42,7 @@ fn can_specify_code_for_email() { #[validate(email(code = "oops"))] val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -65,9 +58,7 @@ fn can_specify_message_for_email() { #[validate(email(message = "oops"))] val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/length.rs b/validator_derive/tests/length.rs index 12bffc6..6ad6272 100644 --- a/validator_derive/tests/length.rs +++ b/validator_derive/tests/length.rs @@ -12,9 +12,7 @@ fn can_validate_length_ok() { val: String, } - let s = TestStruct { - val: "hello".to_string(), - }; + let s = TestStruct { val: "hello".to_string() }; assert!(s.validate().is_ok()); } @@ -27,9 +25,7 @@ fn value_out_of_length_fails_validation() { val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -48,9 +44,7 @@ fn can_specify_code_for_length() { #[validate(length(min = "5", max = "10", code = "oops"))] val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -66,9 +60,7 @@ fn can_specify_message_for_length() { #[validate(length(min = "5", max = "10", message = "oops"))] val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/must_match.rs b/validator_derive/tests/must_match.rs index a8c95f9..32b3016 100644 --- a/validator_derive/tests/must_match.rs +++ b/validator_derive/tests/must_match.rs @@ -4,7 +4,6 @@ extern crate validator; use validator::Validate; - #[test] fn can_validate_valid_must_match() { #[derive(Debug, Validate)] @@ -14,10 +13,7 @@ fn can_validate_valid_must_match() { val2: String, } - let s = TestStruct { - val: "bob".to_string(), - val2: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string(), val2: "bob".to_string() }; assert!(s.validate().is_ok()); } @@ -31,10 +27,7 @@ fn not_matching_fails_validation() { val2: String, } - let s = TestStruct { - val: "bob".to_string(), - val2: "bobby".to_string(), - }; + let s = TestStruct { val: "bob".to_string(), val2: "bobby".to_string() }; let res = s.validate(); assert!(res.is_err()); @@ -54,10 +47,7 @@ fn can_specify_code_for_must_match() { val: String, val2: String, } - let s = TestStruct { - val: "bob".to_string(), - val2: "bobb".to_string(), - }; + let s = TestStruct { val: "bob".to_string(), val2: "bobb".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -74,10 +64,7 @@ fn can_specify_message_for_must_match() { val: String, val2: String, } - let s = TestStruct { - val: "bob".to_string(), - val2: "bobb".to_string(), - }; + let s = TestStruct { val: "bob".to_string(), val2: "bobb".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/nested.rs b/validator_derive/tests/nested.rs index 4f03714..a95b0ef 100644 --- a/validator_derive/tests/nested.rs +++ b/validator_derive/tests/nested.rs @@ -4,8 +4,10 @@ extern crate validator; #[macro_use] extern crate serde_derive; -use validator::{validate_length, Validate, ValidationError, ValidationErrors, ValidationErrorsKind, Validator}; use std::{borrow::Cow, collections::HashMap}; +use validator::{ + validate_length, Validate, ValidationError, ValidationErrors, ValidationErrorsKind, Validator, +}; #[derive(Debug, Validate)] struct Root<'a> { @@ -54,12 +56,7 @@ struct Child { fn is_fine_with_nested_validations() { let root = Root { value: "valid".to_string(), - a: &A { - value: "valid".to_string(), - b: B { - value: "valid".to_string(), - } - } + a: &A { value: "valid".to_string(), b: B { value: "valid".to_string() } }, }; assert!(root.validate().is_ok()); @@ -69,12 +66,7 @@ fn is_fine_with_nested_validations() { fn failed_validation_points_to_original_field_names() { let root = Root { value: String::new(), - a: &A { - value: String::new(), - b: B { - value: String::new(), - } - } + a: &A { value: String::new(), b: B { value: String::new() } }, }; let res = root.validate(); @@ -122,11 +114,7 @@ fn failed_validation_points_to_original_field_names() { #[test] fn test_can_validate_option_fields_without_lifetime() { - let instance = ParentWithOptionalChild { - child: Some(Child { - value: String::new(), - }) - }; + let instance = ParentWithOptionalChild { child: Some(Child { value: String::new() }) }; let res = instance.validate(); assert!(res.is_err()); @@ -157,13 +145,9 @@ fn test_can_validate_option_fields_with_lifetime() { child: Option<&'a Child>, } - let child = Child { - value: String::new(), - }; + let child = Child { value: String::new() }; - let instance = ParentWithLifetimeAndOptionalChild { - child: Some(&child) - }; + let instance = ParentWithLifetimeAndOptionalChild { child: Some(&child) }; let res = instance.validate(); assert!(res.is_err()); @@ -188,9 +172,7 @@ fn test_can_validate_option_fields_with_lifetime() { #[test] fn test_works_with_none_values() { - let instance = ParentWithOptionalChild { - child: None, - }; + let instance = ParentWithOptionalChild { child: None }; let res = instance.validate(); assert!(res.is_ok()); @@ -200,18 +182,10 @@ fn test_works_with_none_values() { fn test_can_validate_vector_fields() { let instance = ParentWithVectorOfChildren { child: vec![ - Child { - value: "valid".to_string(), - }, - Child { - value: String::new(), - }, - Child { - value: "valid".to_string(), - }, - Child { - value: String::new(), - } + Child { value: "valid".to_string() }, + Child { value: String::new() }, + Child { value: "valid".to_string() }, + Child { value: String::new() }, ], }; @@ -250,9 +224,7 @@ fn test_can_validate_vector_fields() { #[test] fn test_field_validations_take_priority_over_nested_validations() { - let instance = ParentWithVectorOfChildren { - child: Vec::new(), - }; + let instance = ParentWithVectorOfChildren { child: Vec::new() }; let res = instance.validate(); assert!(res.is_err()); @@ -271,7 +243,6 @@ fn test_field_validations_take_priority_over_nested_validations() { #[should_panic(expected = "Attempt to replace non-empty ValidationErrors entry")] #[allow(unused)] fn test_field_validation_errors_replaced_with_nested_validations_fails() { - #[derive(Debug)] struct ParentWithOverridingStructValidations { child: Vec<Child>, @@ -284,7 +255,10 @@ fn test_field_validation_errors_replaced_with_nested_validations_fails() { fn validate(&self) -> Result<(), ValidationErrors> { // First validate the length of the vector: let mut errors = ValidationErrors::new(); - if !validate_length(Validator::Length { min: Some(2u64), max: None, equal: None }, &self.child) { + if !validate_length( + Validator::Length { min: Some(2u64), max: None, equal: None }, + &self.child, + ) { let mut err = ValidationError::new("length"); err.add_param(Cow::from("min"), &2u64); err.add_param(Cow::from("value"), &&self.child); @@ -294,28 +268,29 @@ fn test_field_validation_errors_replaced_with_nested_validations_fails() { // Then validate the nested vector of structs without checking for existing field errors: let mut result = if errors.is_empty() { Ok(()) } else { Err(errors) }; { - let results: Vec<_> = self.child.iter().map(|child| { - let mut result = Ok(()); - result = ValidationErrors::merge(result, "child", child.validate()); - result - }).collect(); + let results: Vec<_> = self + .child + .iter() + .map(|child| { + let mut result = Ok(()); + result = ValidationErrors::merge(result, "child", child.validate()); + result + }).collect(); result = ValidationErrors::merge_all(result, "child", results); } result } } - let instance = ParentWithOverridingStructValidations { - child: vec![ - Child { - value: String::new() - }] - }; + let instance = + ParentWithOverridingStructValidations { child: vec![Child { value: String::new() }] }; instance.validate(); } #[test] -#[should_panic(expected = "Attempt to add field validation to a non-Field ValidationErrorsKind instance")] +#[should_panic( + expected = "Attempt to add field validation to a non-Field ValidationErrorsKind instance" +)] #[allow(unused)] fn test_field_validations_evaluated_after_nested_validations_fails() { #[derive(Debug)] @@ -331,16 +306,22 @@ fn test_field_validations_evaluated_after_nested_validations_fails() { // First validate the nested vector of structs: let mut result = Ok(()); if !ValidationErrors::has_error(&result, "child") { - let results: Vec<_> = self.child.iter().map(|child| { - let mut result = Ok(()); - result = ValidationErrors::merge(result, "child", child.validate()); - result - }).collect(); + let results: Vec<_> = self + .child + .iter() + .map(|child| { + let mut result = Ok(()); + result = ValidationErrors::merge(result, "child", child.validate()); + result + }).collect(); result = ValidationErrors::merge_all(result, "child", results); } // Then validate the length of the vector itself: - if !validate_length(Validator::Length { min: Some(2u64), max: None, equal: None }, &self.child) { + if !validate_length( + Validator::Length { min: Some(2u64), max: None, equal: None }, + &self.child, + ) { let mut err = ValidationError::new("length"); err.add_param(Cow::from("min"), &2u64); err.add_param(Cow::from("value"), &&self.child); @@ -353,18 +334,14 @@ fn test_field_validations_evaluated_after_nested_validations_fails() { } } - let instance = ParentWithStructValidationsFirst { - child: vec![ - Child { - value: String::new() - }] - }; + let instance = ParentWithStructValidationsFirst { child: vec![Child { value: String::new() }] }; let res = instance.validate(); } fn unwrap_map<F>(errors: &Box<ValidationErrors>, f: F) - where F: FnOnce(HashMap<&'static str, ValidationErrorsKind>) +where + F: FnOnce(HashMap<&'static str, ValidationErrorsKind>), { let errors = *errors.clone(); f(errors.errors()); -}
\ No newline at end of file +} diff --git a/validator_derive/tests/phone.rs b/validator_derive/tests/phone.rs index 3131bad..a87d037 100644 --- a/validator_derive/tests/phone.rs +++ b/validator_derive/tests/phone.rs @@ -4,7 +4,6 @@ extern crate validator; use validator::Validate; - #[cfg(feature = "phone")] #[test] fn can_validate_phone_ok() { @@ -14,9 +13,7 @@ fn can_validate_phone_ok() { val: String, } - let s = TestStruct { - val: "+14152370800".to_string(), - }; + let s = TestStruct { val: "+14152370800".to_string() }; assert!(s.validate().is_ok()); } @@ -30,9 +27,7 @@ fn bad_phone_fails_validation() { val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -49,9 +44,7 @@ fn can_specify_code_for_phone() { #[validate(phone(code = "oops"))] val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -69,9 +62,7 @@ fn can_specify_message_for_phone() { #[validate(phone(message = "oops"))] val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/range.rs b/validator_derive/tests/range.rs index 084e530..4f38f18 100644 --- a/validator_derive/tests/range.rs +++ b/validator_derive/tests/range.rs @@ -12,9 +12,7 @@ fn can_validate_range_ok() { val: usize, } - let s = TestStruct { - val: 6, - }; + let s = TestStruct { val: 6 }; assert!(s.validate().is_ok()); } @@ -27,9 +25,7 @@ fn value_out_of_range_fails_validation() { val: usize, } - let s = TestStruct { - val: 11, - }; + let s = TestStruct { val: 11 }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -45,9 +41,7 @@ fn can_specify_code_for_range() { #[validate(range(min = "5", max = "10", code = "oops"))] val: usize, } - let s = TestStruct { - val: 11, - }; + let s = TestStruct { val: 11 }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -66,9 +60,7 @@ fn can_specify_message_for_range() { #[validate(range(min = "5", max = "10", message = "oops"))] val: usize, } - let s = TestStruct { - val: 1, - }; + let s = TestStruct { val: 1 }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/regex.rs b/validator_derive/tests/regex.rs index b54df03..a6b9e68 100644 --- a/validator_derive/tests/regex.rs +++ b/validator_derive/tests/regex.rs @@ -5,8 +5,8 @@ extern crate lazy_static; extern crate validator_derive; extern crate validator; -use validator::Validate; use regex::Regex; +use validator::Validate; lazy_static! { static ref RE2: Regex = Regex::new(r"^[a-z]{2}$").unwrap(); @@ -20,9 +20,7 @@ fn can_validate_valid_regex() { val: String, } - let s = TestStruct { - val: "aa".to_string(), - }; + let s = TestStruct { val: "aa".to_string() }; assert!(s.validate().is_ok()); } @@ -35,9 +33,7 @@ fn bad_value_for_regex_fails_validation() { val: String, } - let s = TestStruct { - val: "2".to_string(), - }; + let s = TestStruct { val: "2".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -54,9 +50,7 @@ fn can_specify_code_for_regex() { #[validate(regex(path = "RE2", code = "oops"))] val: String, } - let s = TestStruct { - val: "2".to_string(), - }; + let s = TestStruct { val: "2".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -72,9 +66,7 @@ fn can_specify_message_for_regex() { #[validate(regex(path = "RE2", message = "oops"))] val: String, } - let s = TestStruct { - val: "2".to_string(), - }; + let s = TestStruct { val: "2".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); diff --git a/validator_derive/tests/schema.rs b/validator_derive/tests/schema.rs index 32684fa..b45f3a1 100644 --- a/validator_derive/tests/schema.rs +++ b/validator_derive/tests/schema.rs @@ -4,12 +4,11 @@ extern crate validator; use validator::{Validate, ValidationError}; - #[test] fn can_validate_schema_fn_ok() { fn valid_schema_fn(_: &TestStruct) -> Result<(), ValidationError> { - Ok(()) -} + Ok(()) + } #[derive(Debug, Validate)] #[validate(schema(function = "valid_schema_fn"))] @@ -17,9 +16,7 @@ fn can_validate_schema_fn_ok() { val: String, } - let s = TestStruct { - val: "hello".to_string(), - }; + let s = TestStruct { val: "hello".to_string() }; assert!(s.validate().is_ok()); } @@ -36,9 +33,7 @@ fn can_fail_schema_fn_validation() { val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -58,9 +53,7 @@ fn can_specify_message_for_schema_fn() { struct TestStruct { val: String, } - let s = TestStruct { - val: String::new(), - }; + let s = TestStruct { val: String::new() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -82,10 +75,7 @@ fn can_choose_to_run_schema_validation_even_after_field_errors() { num: usize, } - let s = TestStruct { - val: "hello".to_string(), - num: 0, - }; + let s = TestStruct { val: "hello".to_string(), num: 0 }; let res = s.validate(); assert!(res.is_err()); diff --git a/validator_derive/tests/url.rs b/validator_derive/tests/url.rs index 5a3b791..0ac3cb1 100644 --- a/validator_derive/tests/url.rs +++ b/validator_derive/tests/url.rs @@ -4,7 +4,6 @@ extern crate validator; use validator::Validate; - #[test] fn can_validate_url_ok() { #[derive(Debug, Validate)] @@ -13,9 +12,7 @@ fn can_validate_url_ok() { val: String, } - let s = TestStruct { - val: "https://google.com".to_string(), - }; + let s = TestStruct { val: "https://google.com".to_string() }; assert!(s.validate().is_ok()); } @@ -28,9 +25,7 @@ fn bad_url_fails_validation() { val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -46,9 +41,7 @@ fn can_specify_code_for_url() { #[validate(url(code = "oops"))] val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); @@ -65,9 +58,7 @@ fn can_specify_message_for_url() { #[validate(url(message = "oops"))] val: String, } - let s = TestStruct { - val: "bob".to_string(), - }; + let s = TestStruct { val: "bob".to_string() }; let res = s.validate(); assert!(res.is_err()); let errs = res.unwrap_err().field_errors(); |
