Skip to content

Commit

Permalink
Merge pull request #61 from yassun7010/add_test_cases
Browse files Browse the repository at this point in the history
chore: add test case.
  • Loading branch information
yassun7010 authored May 7, 2024
2 parents c44369a + 8c41c98 commit 4d7dfb2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions serde_valid/tests/length_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

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)]
Expand Down
2 changes: 2 additions & 0 deletions serde_valid_derive/src/types/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub trait Field {

fn attrs(&self) -> &Vec<syn::Attribute>;

#[allow(dead_code)]
fn vis(&self) -> &syn::Visibility;

#[allow(dead_code)]
fn ty(&self) -> &syn::Type;
}

0 comments on commit 4d7dfb2

Please sign in to comment.