Skip to content

Commit

Permalink
fix custom-error-message
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Nov 13, 2023
1 parent 3deab82 commit c73589d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ where

#[cfg(test)]
mod tests {
use core::str::FromStr;
use serde_derive::Deserialize;

#[derive(Debug, Deserialize, PartialEq)]
Expand Down Expand Up @@ -1083,7 +1084,10 @@ mod tests {
assert_eq!(
crate::from_str::<Xy>(r#"[10]"#),
Err(crate::de::Error::CustomErrorWithMessage(
"invalid length 1, expected tuple struct Xy with 2 elements".into()
heapless::String::from_str(
"invalid length 1, expected tuple struct Xy with 2 elements"
)
.unwrap()
))
);
assert_eq!(
Expand Down Expand Up @@ -1190,7 +1194,9 @@ mod tests {
use serde::de::Error;
assert_eq!(
crate::de::Error::custom("something bad happened"),
crate::de::Error::CustomErrorWithMessage("something bad happened".into())
crate::de::Error::CustomErrorWithMessage(
heapless::String::from_str("something bad happened").unwrap()
)
);
}

Expand All @@ -1200,8 +1206,8 @@ mod tests {
use serde::de::Error;
assert_eq!(
crate::de::Error::custom("0123456789012345678901234567890123456789012345678901234567890123 <- after here the message should be truncated"),
crate::de::Error::CustomErrorWithMessage(
"0123456789012345678901234567890123456789012345678901234567890123".into()
crate::de::Error::CustomErrorWithMessage(heapless::String::from_str(
"0123456789012345678901234567890123456789012345678901234567890123").unwrap()
)
);
}
Expand Down

0 comments on commit c73589d

Please sign in to comment.