diff options
author | Matan Kushner <hello@matchai.me> | 2019-04-04 14:32:22 -0400 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-04-04 14:32:22 -0400 |
commit | 7136059dcd4d3b3fe6857dcf0542bd850a50d813 (patch) | |
tree | 9c909f0a42632b03fbb85b9ad8c25c7d3397e61f /src | |
parent | 7683f33bc870cd928e7d572fcdde65a1fd5eda0c (diff) |
Add tests to dir home truncation
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/dir.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/modules/dir.rs b/src/modules/dir.rs index 5f17d709b..098d0f14e 100644 --- a/src/modules/dir.rs +++ b/src/modules/dir.rs @@ -5,7 +5,7 @@ use ansi_term::{Color, Style}; use clap::ArgMatches; /// Creates a segment with the current directory -pub fn segment(args: &ArgMatches) -> Segment { +pub fn segment(_: &ArgMatches) -> Segment { const COLOR_DIR: Color = Color::Cyan; const HOME_SYMBOL: char = '~'; @@ -28,14 +28,12 @@ pub fn segment(args: &ArgMatches) -> Segment { } } -// fn truncate_dir(directory: PathBuf, truncate_to: u8) { - -// } - #[cfg(test)] mod tests { + // TODO: Look into stubbing `env` so that tests can be run in parallel use super::*; use clap::{App, Arg}; + use std::path::Path; #[test] fn truncate_home_dir() { @@ -43,8 +41,23 @@ mod tests { .arg(Arg::with_name("status_code")) .get_matches_from(vec!["starship", "0"]); - env::set_current_dir("~/dev/"); + let home_dir = dirs::home_dir().unwrap(); + env::set_current_dir(&home_dir).unwrap(); + + let segment = segment(&args); + assert_eq!(segment.value, "~"); + } + + #[test] + fn dont_truncate_non_home_dir() { + let args = App::new("starship") + .arg(Arg::with_name("status_code")) + .get_matches_from(vec!["starship", "0"]); + + let root_dir = Path::new("/"); + env::set_current_dir(&root_dir).unwrap(); + let segment = segment(&args); - assert_eq!(segment.style, Style::from(Color::Green)); + assert_eq!(segment.value, "/"); } } |