1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 07:46:28 +00:00

Add tests to dir home truncation

This commit is contained in:
Matan Kushner 2019-04-04 14:32:22 -04:00
parent 7683f33bc8
commit 7136059dcd
No known key found for this signature in database
GPG Key ID: 4B98C3A8949CA8A4
2 changed files with 22 additions and 8 deletions

View File

@ -54,5 +54,6 @@ jobs:
condition: eq( variables['Agent.OS'], 'Windows_NT' )
- script: cargo build --all
displayName: Cargo build
- script: cargo test --all
# Until env stubbing is solved, make tests run on a single thread
- script: cargo test --all -- --test-threads=1
displayName: Cargo test

View File

@ -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.style, Style::from(Color::Green));
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.value, "/");
}
}