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