From 36f6535f6d0c1b680eb396159c27c6c44e63bc79 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 1 May 2019 21:36:09 +0200 Subject: attr_literals is stable \o/ --- validator_derive/tests/complex.rs | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'validator_derive/tests/complex.rs') diff --git a/validator_derive/tests/complex.rs b/validator_derive/tests/complex.rs index 7826a49..974fdad 100644 --- a/validator_derive/tests/complex.rs +++ b/validator_derive/tests/complex.rs @@ -29,16 +29,16 @@ fn validate_signup(data: &SignupData) -> Result<(), ValidationError> { } #[derive(Debug, Validate, Deserialize)] -#[validate(schema(function = "validate_signup", skip_on_field_errors = "false"))] +#[validate(schema(function = "validate_signup", skip_on_field_errors = false))] struct SignupData { #[validate(email)] mail: String, #[validate(url)] site: String, - #[validate(length(min = "1"), custom = "validate_unique_username")] + #[validate(length(min = 1), custom = "validate_unique_username")] #[serde(rename = "firstName")] first_name: String, - #[validate(range(min = "18", max = "20"))] + #[validate(range(min = 18, max = 20))] age: u32, #[validate] phone: Phone, @@ -58,13 +58,13 @@ struct Phone { struct Card { #[validate(credit_card)] number: String, - #[validate(range(min = "100", max = "9999"))] + #[validate(range(min = 100, max = 9999))] cvv: u32, } #[derive(Debug, Validate, Deserialize)] struct Preference { - #[validate(length(min = "4"))] + #[validate(length(min = 4))] name: String, value: bool, } @@ -98,8 +98,8 @@ fn failed_validation_points_to_original_field_name() { let res = signup.validate(); // println!("{}", serde_json::to_string(&res).unwrap()); assert!(res.is_err()); - let errs = res.unwrap_err().errors(); - assert!(errs.contains_key("firstName")); + let err = res.unwrap_err(); +let errs = err.errors();assert!(errs.contains_key("firstName")); if let ValidationErrorsKind::Field(ref err) = errs["firstName"] { assert_eq!(err.len(), 1); assert_eq!(err[0].code, "length"); @@ -167,13 +167,13 @@ fn test_can_validate_option_fields_with_lifetime() { #[derive(Debug, Validate)] struct PutStruct<'a> { - #[validate(length(min = "1", max = "10"))] + #[validate(length(min = 1, max = 10))] name: Option<&'a str>, - #[validate(length(min = "1", max = "10"))] + #[validate(length(min = 1, max = 10))] address: Option>, - #[validate(range(min = "1", max = "100"))] + #[validate(range(min = 1, max = 100))] age: Option>, - #[validate(range(min = "1", max = "10"))] + #[validate(range(min = 1, max = 10))] range: Option, #[validate(email)] email: Option<&'a str>, @@ -213,17 +213,17 @@ fn test_can_validate_option_fields_without_lifetime() { #[derive(Debug, Validate)] struct PutStruct { - #[validate(length(min = "1", max = "10"))] + #[validate(length(min = 1, max = 10))] name: Option, - #[validate(length(min = "1", max = "10"))] + #[validate(length(min = 1, max = 10))] address: Option>, - #[validate(length(min = "1", max = "10"))] + #[validate(length(min = 1, max = 10))] ids: Option>, - #[validate(length(min = "1", max = "10"))] + #[validate(length(min = 1, max = 10))] opt_ids: Option>>, - #[validate(range(min = "1", max = "100"))] + #[validate(range(min = 1, max = 100))] age: Option>, - #[validate(range(min = "1", max = "10"))] + #[validate(range(min = 1, max = 10))] range: Option, #[validate(email)] email: Option, @@ -281,13 +281,13 @@ fn test_works_with_question_mark_operator() { fn test_works_with_none_values() { #[derive(Debug, Validate)] struct PutStruct { - #[validate(length(min = "1", max = "10"))] + #[validate(length(min = 1, max = 10))] name: Option, - #[validate(length(min = "1", max = "10"))] + #[validate(length(min = 1, max = 10))] address: Option>, - #[validate(range(min = "1", max = "100"))] + #[validate(range(min = 1, max = 100))] age: Option>, - #[validate(range(min = "1", max = "10"))] + #[validate(range(min = 1, max = 10))] range: Option, } @@ -304,5 +304,5 @@ where F: FnOnce(HashMap<&'static str, ValidationErrorsKind>), { let errors = *errors.clone(); - f(errors.errors()); + f(errors.errors().clone()); } -- cgit v1.2.3 From 467298db852205329758f89d7c2f2639b61ad66a Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 1 May 2019 22:03:17 +0200 Subject: Cargo fmt + edition 2018 for validator --- validator_derive/tests/complex.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'validator_derive/tests/complex.rs') diff --git a/validator_derive/tests/complex.rs b/validator_derive/tests/complex.rs index 974fdad..305b0ce 100644 --- a/validator_derive/tests/complex.rs +++ b/validator_derive/tests/complex.rs @@ -99,7 +99,8 @@ fn failed_validation_points_to_original_field_name() { // println!("{}", serde_json::to_string(&res).unwrap()); assert!(res.is_err()); let err = res.unwrap_err(); -let errs = err.errors();assert!(errs.contains_key("firstName")); + let errs = err.errors(); + assert!(errs.contains_key("firstName")); if let ValidationErrorsKind::Field(ref err) = errs["firstName"] { assert_eq!(err.len(), 1); assert_eq!(err[0].code, "length"); -- cgit v1.2.3