feat: impl `Display` for `OptionalMinMaxSequence`

pull/24376/head
Marco Neumann 2021-08-06 09:16:40 +02:00
parent 4ffdb3d95d
commit a5e9bbc507
1 changed files with 26 additions and 0 deletions

View File

@ -67,6 +67,16 @@ impl OptionalMinMaxSequence {
}
}
impl std::fmt::Display for OptionalMinMaxSequence {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(min) = self.min {
write!(f, "[{}, {}]", min, self.max)
} else {
write!(f, "({}, {}]", self.max, self.max)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
@ -110,4 +120,20 @@ mod tests {
fn test_opt_min_max_checks_values() {
OptionalMinMaxSequence::new(Some(11), 10);
}
#[test]
fn test_opt_min_max_display() {
assert_eq!(
OptionalMinMaxSequence::new(Some(10), 20).to_string(),
"[10, 20]".to_string()
);
assert_eq!(
OptionalMinMaxSequence::new(Some(20), 20).to_string(),
"[20, 20]".to_string()
);
assert_eq!(
OptionalMinMaxSequence::new(None, 20).to_string(),
"(20, 20]".to_string()
);
}
}