From a96b341f2bb1cb575db1c8d790e2db76200dabef Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Wed, 8 May 2024 01:01:47 +0900 Subject: [PATCH 1/2] chore: add test case. --- serde_valid/tests/length_test.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/serde_valid/tests/length_test.rs b/serde_valid/tests/length_test.rs index 68ffd307..57854dae 100644 --- a/serde_valid/tests/length_test.rs +++ b/serde_valid/tests/length_test.rs @@ -210,6 +210,35 @@ fn length_option_type_is_ok() { assert!(s.validate().is_ok()); } +#[test] +fn length_option_type_is_err() { + #[derive(Validate)] + struct TestStruct { + #[validate(min_length = 0)] + #[validate(max_length = 5)] + val: Option, + } + + let s = TestStruct { + val: Some(String::from("abcdefg")), + }; + + assert_eq!( + s.validate().unwrap_err().to_string(), + json!( + { + "errors":[], + "properties":{ + "val":{ + "errors": ["The length of the value must be `<= 5`."] + } + } + } + ) + .to_string() + ); +} + #[test] fn length_nested_option_type_is_ok() { #[derive(Validate)] From 8c41c98da22a42d7a88decfd1f6be555c635f2da Mon Sep 17 00:00:00 2001 From: yassun7010 Date: Wed, 8 May 2024 01:06:09 +0900 Subject: [PATCH 2/2] chore: fix clippy. --- serde_valid_derive/src/types/field.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serde_valid_derive/src/types/field.rs b/serde_valid_derive/src/types/field.rs index 3eb73d6d..2f8b5bfc 100644 --- a/serde_valid_derive/src/types/field.rs +++ b/serde_valid_derive/src/types/field.rs @@ -17,7 +17,9 @@ pub trait Field { fn attrs(&self) -> &Vec; + #[allow(dead_code)] fn vis(&self) -> &syn::Visibility; + #[allow(dead_code)] fn ty(&self) -> &syn::Type; }