1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-26 11:37:32 +00:00

fix: Update Module::is_empty to check value of segments (#332)

Previously, a set of empty segments would cause the module to print. This changes the 
logic of Module::is_empty to check that all the segments are empty instead.
This commit is contained in:
Neil Kistner 2019-09-16 00:03:44 -05:00 committed by Kevin Song
parent 121c55bac5
commit aa26c5bca4
2 changed files with 42 additions and 2 deletions

View File

@ -74,9 +74,9 @@ impl<'a> Module<'a> {
self.segments.last_mut().unwrap()
}
/// Whether a module has any segments
/// Whether a module has non-empty segments
pub fn is_empty(&self) -> bool {
self.segments.is_empty()
self.segments.iter().all(|segment| segment.is_empty())
}
/// Get the module's prefix
@ -261,3 +261,38 @@ impl fmt::Display for Affix {
write!(f, "{}", self.ansi_string())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_module_is_empty_with_no_segments() {
let name = "unit_test";
let module = Module {
config: None,
_name: name.to_string(),
style: Style::default(),
prefix: Affix::default_prefix(name),
segments: Vec::new(),
suffix: Affix::default_suffix(name),
};
assert!(module.is_empty());
}
#[test]
fn test_module_is_empty_with_all_empty_segments() {
let name = "unit_test";
let module = Module {
config: None,
_name: name.to_string(),
style: Style::default(),
prefix: Affix::default_prefix(name),
segments: vec![Segment::new("test_segment")],
suffix: Affix::default_suffix(name),
};
assert!(module.is_empty());
}
}

View File

@ -52,6 +52,11 @@ impl Segment {
None => ANSIString::from(&self.value),
}
}
/// Determines if the segment contains a value.
pub fn is_empty(&self) -> bool {
self.value.trim().is_empty()
}
}
impl fmt::Display for Segment {