Format and add test

This commit is contained in:
Luca Matei Pintilie 2021-08-21 11:02:18 +02:00 committed by Abin Simon
parent 11124b9ff0
commit de190a4bfb

View file

@ -6,9 +6,9 @@ use super::Configurable;
use crate::config_file::Config;
use crate::print_error;
use std::env;
use clap::ArgMatches;
use serde::Deserialize;
use std::env;
/// A collection of flags on how to use colors.
#[derive(Clone, Debug, Copy, PartialEq, Eq, Default)]
@ -93,7 +93,7 @@ impl Configurable<Self> for ColorOption {
fn from_environment() -> Option<Self> {
if env::var("NO_COLOR").is_ok() {
return Some(Self::Never)
return Some(Self::Never);
} else {
None
}
@ -115,6 +115,8 @@ mod test_color_option {
use crate::config_file::{self, Config};
use crate::flags::Configurable;
use std::env::set_var;
#[test]
fn test_from_arg_matches_none() {
let argv = vec!["lsd"];
@ -152,6 +154,12 @@ mod test_color_option {
);
}
#[test]
fn test_from_env_no_color() {
set_var("NO_COLOR", "true");
assert_eq!(Some(ColorOption::Never), ColorOption::from_environment());
}
#[test]
fn test_from_arg_matches_classic_mode() {
let argv = vec!["lsd", "--color", "always", "--classic"];