Skip to content

Commit

Permalink
chore: add test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
yassun7010 committed May 7, 2024
1 parent c44369a commit a96b341
Showing 1 changed file with 29 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

0 comments on commit a96b341

Please sign in to comment.