Skip to content

Commit

Permalink
fix: tests for errors on in common.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
amydevs committed Apr 5, 2024
1 parent 1d3ac4a commit 8faa4ea
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<'de> Deserialize<'de> for HexColor {
return Ok(HexColor { value: color });
}
Err(de::Error::custom(format!(
"String does not match the #rrggbbaa format"
"string does not match the #rrggbbaa format"
)))
}
}
Expand Down Expand Up @@ -475,7 +475,6 @@ impl Meter {
#[cfg(test)]
mod tests {
use quick_xml::de::from_str;
use serde::de::Error;

use super::{HexColor, RGBAColor, ValueWrapper};
#[test]
Expand All @@ -487,6 +486,13 @@ mod tests {
)
.unwrap();
assert_eq!(rgba_value.value, 90);
let rgba_error: Result<ValueWrapper<u8>, quick_xml::DeError> = from_str(
r#"
<Alpha Value="90.0"/>
"#,
);
println!("{:?}", rgba_error);
assert!(matches!(rgba_error, Err(quick_xml::DeError::InvalidInt(_))));
}
#[test]
fn rgba() {
Expand Down Expand Up @@ -523,7 +529,7 @@ mod tests {
let rgba_error: Result<RGBAColor, quick_xml::DeError> = from_str(
r#"
<ControlForeground>
<R Value="invalid value"/>
<R Value="value"/>
</ControlForeground>
"#,
);
Expand All @@ -541,5 +547,8 @@ mod tests {
assert_eq!(hex2.value.g, 2);
assert_eq!(hex2.value.b, 3);
assert_eq!(hex2.value.a, 255);
let hex_error: Result<HexColor, quick_xml::DeError> =
from_str("<ControlForeground Value=\"value\"/>");
assert!(matches!(hex_error, Err(quick_xml::DeError::Custom(_))));
}
}

0 comments on commit 8faa4ea

Please # to comment.