Skip to content

Commit

Permalink
fix error message
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoikey committed Oct 30, 2024
1 parent a06a803 commit 9479e6b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/rule/composer/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mod test {

#[test]
fn test_rule_binder_macro_err() {
type SampleRule = Or![EmailRule<String>, NonEmptyStringRule, EmailRule<String>];
assert!(SampleRule::validate("".to_string()).is_err());
type SampleRule = Or![EmailRule<String>, NonEmptyStringRule];
assert_eq!(SampleRule::validate("".to_string()).unwrap_err().to_string(), "[\"\" does not match the regex pattern ^[a-zA-Z0-9_.+-]+@([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]*\\.)+[a-zA-Z]{2,}$ || \"\" does not satisfy Not<refined_type::rule::empty::EmptyRule<alloc::string::String>>]");
}
}
4 changes: 2 additions & 2 deletions src/rule/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ mod ipv6;
mod regex;

pub use alpha_digit::*;
pub use alphabet::{Alphabet, AlphabetRule};
pub use alphabet::*;
pub use digit::*;
pub use email::{Email, EmailRule};
pub use email::*;
pub use ipv4::*;
pub use ipv6::*;
pub use regex::*;
8 changes: 8 additions & 0 deletions src/rule/string/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ use crate::{declare_regex_rule, Refined};
/// ```
pub type Email<STRING> = Refined<EmailRule<STRING>>;

pub type EmailString = Refined<EmailStringRule>;

pub type EmailStr = Refined<EmailStrRule>;

declare_regex_rule![
pub EmailRule,
r"^[a-zA-Z0-9_.+-]+@([a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]*\.)+[a-zA-Z]{2,}$"
];

pub type EmailStringRule = EmailRule<String>;

pub type EmailStrRule = EmailRule<&'static str>;

#[cfg(test)]
mod test {
use crate::rule::string::email::EmailRule;
Expand Down
2 changes: 1 addition & 1 deletion src/rule/string/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ macro_rules! declare_regex_rule {
if regex.is_match(target_as_ref) {
Ok(target)
} else {
let message = format!("{target_as_ref} does not match the regex pattern {regex}");
let message = format!("\"{target_as_ref}\" does not match the regex pattern {regex}");
Err($crate::result::Error::new(target, message))
}
}
Expand Down

0 comments on commit 9479e6b

Please sign in to comment.