diff options
Diffstat (limited to 'validator_derive')
| -rw-r--r-- | validator_derive/src/lib.rs | 5 | ||||
| -rw-r--r-- | validator_derive/tests/compile-fail/length/wrong_arg_type.rs | 15 | ||||
| -rw-r--r-- | validator_derive/tests/compile-fail/range/wrong_arg_type.rs | 15 | ||||
| -rw-r--r-- | validator_derive/tests/test_derive.rs | 14 |
4 files changed, 11 insertions, 38 deletions
diff --git a/validator_derive/src/lib.rs b/validator_derive/src/lib.rs index 92f3ea5..fd02e3d 100644 --- a/validator_derive/src/lib.rs +++ b/validator_derive/src/lib.rs @@ -526,6 +526,8 @@ fn lit_to_string(lit: &syn::Lit) -> Option<String> { fn lit_to_int(lit: &syn::Lit) -> Option<u64> { match *lit { syn::Lit::Int(ref s, _) => Some(*s), + // TODO: remove when attr_literals is stable + syn::Lit::Str(ref s, _) => Some(s.parse::<u64>().unwrap()), _ => None, } } @@ -534,6 +536,8 @@ fn lit_to_float(lit: &syn::Lit) -> Option<f64> { match *lit { syn::Lit::Float(ref s, _) => Some(s.parse::<f64>().unwrap()), syn::Lit::Int(ref s, _) => Some(*s as f64), + // TODO: remove when attr_literals is stable + syn::Lit::Str(ref s, _) => Some(s.parse::<f64>().unwrap()), _ => None, } } @@ -541,6 +545,7 @@ fn lit_to_float(lit: &syn::Lit) -> Option<f64> { fn lit_to_bool(lit: &syn::Lit) -> Option<bool> { match *lit { syn::Lit::Bool(ref s) => Some(*s), + syn::Lit::Str(ref s, _) => if s == "true" { Some(true) } else { Some(false) }, _ => None, } } diff --git a/validator_derive/tests/compile-fail/length/wrong_arg_type.rs b/validator_derive/tests/compile-fail/length/wrong_arg_type.rs deleted file mode 100644 index 4d3f602..0000000 --- a/validator_derive/tests/compile-fail/length/wrong_arg_type.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(proc_macro, attr_literals)] - -#[macro_use] extern crate validator_derive; -extern crate validator; -use validator::Validate; - -#[derive(Validate)] -//~^ ERROR: custom derive attribute panicked -//~^^ HELP: Invalid attribute #[validate] on field `s`: invalid argument type for `min` of `length` validator: only integers are allowed -struct Test { - #[validate(length(min = "2"))] - s: String, -} - -fn main() {} diff --git a/validator_derive/tests/compile-fail/range/wrong_arg_type.rs b/validator_derive/tests/compile-fail/range/wrong_arg_type.rs deleted file mode 100644 index a62a5ff..0000000 --- a/validator_derive/tests/compile-fail/range/wrong_arg_type.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(proc_macro, attr_literals)] - -#[macro_use] extern crate validator_derive; -extern crate validator; -use validator::Validate; - -#[derive(Validate)] -//~^ ERROR: custom derive attribute panicked -//~^^ HELP: Invalid attribute #[validate] on field `s`: invalid argument type for `min` of `range` validator: only integers are allowed -struct Test { - #[validate(range(min = "2", max = 3))] - s: i32, -} - -fn main() {} diff --git a/validator_derive/tests/test_derive.rs b/validator_derive/tests/test_derive.rs index 6832762..9b9bad7 100644 --- a/validator_derive/tests/test_derive.rs +++ b/validator_derive/tests/test_derive.rs @@ -1,5 +1,3 @@ -#![feature(attr_literals)] - #[macro_use] extern crate validator_derive; extern crate validator; #[macro_use] extern crate serde_derive; @@ -9,16 +7,16 @@ use validator::Validate; #[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, } @@ -47,11 +45,11 @@ fn validate_signup(data: &SignupData) -> Option<(String, String)> { } #[derive(Debug, Validate, Deserialize)] -#[validate(schema(function = "validate_signup2", skip_on_field_errors = false))] +#[validate(schema(function = "validate_signup2", skip_on_field_errors = "false"))] struct SignupData2 { #[validate(email)] mail: String, - #[validate(range(min = 18, max = 20))] + #[validate(range(min = "18", max = "20"))] age: u32, } @@ -60,7 +58,7 @@ struct SignupData2 { struct SignupData3 { #[validate(email)] mail: String, - #[validate(range(min = 18, max = 20))] + #[validate(range(min = "18", max = "20"))] age: u32, } |
